Cycle

The Scriptorium

Smart Assembly code templates and tools for on-chain development in Eve Frontier.

Turret Targeting Modes
IntermediateChapter 3 of 415 min read

Attack All Mode

The Attack All mode is the aggressive counterpart to Aggression mode. Instead of waiting for someone to attack first, it targets every non-tribe pilot in range. Aggressors still get higher priority, but passive targets are fair game too.

Full Source

move
/// Mode: ATTACK ALL — shoot all non-tribe targets, protect tribe members.
module turret_monitor::attack_all;

use sui::bcs;
use turret_monitor::config;
use world::character::Character;
use world::turret::{Self, Turret, OnlineReceipt};

public struct AttackAllAuth has drop {}

public fun get_target_priority_list(
    turret: &Turret,
    owner_character: &Character,
    target_candidate_list: vector<u8>,
    receipt: OnlineReceipt,
): vector<u8> {
    assert!(receipt.turret_id() == object::id(turret), 0);

    let candidates = turret::unpack_candidate_list(target_candidate_list);
    let len = candidates.length();
    let owner_tribe = owner_character.tribe();
    let owner_char_id = owner_character.key().item_id();

    let mut return_list = vector::empty<turret::ReturnTargetPriorityList>();
    let mut num_aggressors: u64 = 0;
    let mut i: u64 = 0;

    while (i < len) {
        let candidate = candidates.borrow(i);
        let is_aggressor = candidate.is_aggressor();
        let is_same_tribe = candidate.character_tribe() == owner_tribe;
        let is_owner = (candidate.character_id() as u64) == owner_char_id;

        if (is_aggressor) { num_aggressors = num_aggressors + 1; };

        // Shoot everyone except owner and tribe members.
        // Aggressors get higher priority.
        let excluded = is_owner || is_same_tribe;

        if (!excluded) {
            let mut weight = candidate.priority_weight();
            if (is_aggressor) { weight = weight + 10000; };
            return_list.push_back(turret::new_return_target_priority_list(
                candidate.item_id(), weight,
            ));
        };
        i = i + 1;
    };

    config::emit_alert(
        object::id(turret), owner_char_id, owner_tribe,
        len, num_aggressors, b"attack_all",
    );

    let result = bcs::to_bytes(&return_list);
    turret::destroy_online_receipt(receipt, AttackAllAuth {});
    result
}

Key Differences from Aggression Mode

The structure is nearly identical to aggression.move. The differences are in two places:

1. The Exclusion Logic

Aggression mode:
move
let excluded = is_owner || is_same_tribe || !is_aggressor;
Attack All mode:
move
let excluded = is_owner || is_same_tribe;

The critical difference: Attack All removes the !is_aggressor check. This means non-aggressive targets are included in the targeting list. Every non-tribe, non-owner target gets shot.

2. The Priority Weight

Aggression mode:
move
// Flat boost for all targets (they are all aggressors by definition)
return_list.push_back(turret::new_return_target_priority_list(
    candidate.item_id(), candidate.priority_weight() + 10000,
));
Attack All mode:
move
// Conditional boost -- aggressors get higher priority than passive targets
let mut weight = candidate.priority_weight();
if (is_aggressor) { weight = weight + 10000; };
return_list.push_back(turret::new_return_target_priority_list(
    candidate.item_id(), weight,
));

In Attack All, the weight boost is conditional. Aggressors still get +10000 to be prioritized, but passive targets use their default weight. This creates a two-tier priority system:

``

Tier 1 (High Priority): Aggressors → base_weight + 10000

Tier 2 (Normal Priority): Non-aggressors → base_weight

`

Behavior Comparison

TargetAggression ModeAttack All Mode
OwnerExcludedExcluded
Tribe member (peaceful)ExcludedExcluded
Tribe member (aggressor)ExcludedExcluded
Non-tribe (peaceful)ExcludedTargeted (normal priority)
Non-tribe (aggressor)Targeted (high priority)Targeted (high priority)

The single behavioral difference: peaceful non-tribe targets. Aggression mode ignores them; Attack All mode shoots them.

When to Use Each Mode

Aggression mode is appropriate when:
  • You want a purely defensive posture
  • You are in a busy area with many neutral pilots
  • You only want to retaliate against active threats
Attack All mode is appropriate when:
  • You are defending a contested area
  • You want to establish a no-fly zone for non-tribe members
  • You want maximum territorial control

The Third Mode: No Protect

The turret_monitor package also includes a no_protect mode that we have not covered in detail. Its exclusion logic is:

move
let excluded = is_owner || !is_aggressor;

This is like aggression mode but without tribe protection. It shoots all aggressors, including tribe members who attack. This mode is useful when you suspect a tribe member has gone rogue or when tribe loyalty is uncertain.

ModeProtects Tribe?Shoots Peaceful Non-Tribe?
AggressionYesNo
Attack AllYesYes
No ProtectNoNo

Shared Infrastructure: config.move

All three modes share the same config.move module for event emission:

move
module turret_monitor::config;

use sui::event;

public struct TurretAlertEvent has copy, drop {
    turret_id: ID,
    owner_character_id: u64,
    owner_tribe_id: u32,
    num_targets: u64,
    num_aggressors: u64,
    mode: vector<u8>,
}

public fun emit_alert(
    turret_id: ID,
    owner_character_id: u64,
    owner_tribe_id: u32,
    num_targets: u64,
    num_aggressors: u64,
    mode: vector<u8>,
) {
    if (num_aggressors > 0) {
        event::emit(TurretAlertEvent {
            turret_id, owner_character_id, owner_tribe_id,
            num_targets, num_aggressors, mode,
        });
    };
}

The mode field (e.g., b"aggression_only", b"attack_all", b"no_tribe_protect") lets off-chain indexers distinguish which targeting module was active when the event fired.

Key Takeaways

  • Attack All mode removes the !is_aggressor check from the exclusion logic, targeting all non-tribe pilots.
  • Aggressors still get a +10000 priority weight boost, creating a two-tier targeting system.
  • Tribe members are always protected in Attack All mode (use No Protect to disable that).
  • All three turret modes share the same function signature and structural pattern -- they differ only in exclusion logic and priority weighting.
  • The config::emit_alert` function provides a unified event system across all modes.

Sign in to track your progress.