Cycle

The Scriptorium

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

← Back to Example Code

Smart Turret — Faction Guard

Combat

A Smart Turret that fires on hostiles while protecting friendlies. Maintains a friend list — anyone not on the list is considered hostile. The turret returns targeting priorities to the World.

turretcombattargetingfaction
smart-turret-faction-guard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import { SmartTurretBase } from "@eveworld/smart-turret/SmartTurretBase.sol";

/**
 * @title FactionGuardTurret
 * @notice Turret that targets hostiles and protects friendlies.
 */
contract FactionGuardTurret is SmartTurretBase {
    address public owner;
    mapping(address => bool) public friends;

    event FriendAdded(address indexed pilot);
    event FriendRemoved(address indexed pilot);

    constructor() {
        owner = msg.sender;
        friends[msg.sender] = true;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Not turret owner");
        _;
    }

    function addFriend(address _pilot) external onlyOwner {
        friends[_pilot] = true;
        emit FriendAdded(_pilot);
    }

    function removeFriend(address _pilot) external onlyOwner {
        require(_pilot != owner, "Cannot remove owner");
        friends[_pilot] = false;
        emit FriendRemoved(_pilot);
    }

    /// @notice Called by the World to determine targeting priority
    /// @return priority 0 = ignore, higher = fire first
    function getTargetPriority(
        address target,
        uint256 /* shipId */
    ) external view override returns (uint256 priority) {
        if (friends[target]) {
            return 0; // Do not fire on friends
        }
        return 100; // Fire on everyone else
    }
}