Modding Discussion Dead code in friendlyTargeting

Discussion in 'Starbound Modding' started by rl.starbound, Apr 22, 2024.

  1. rl.starbound

    rl.starbound Phantasmal Quasar

    I was looking to improve the behavior of friendly guards, so I was working my way through their behaviors trying to understand how they work.

    I see that the friendlyTargeting function (/scripts/actions/npc.lua) is concerned with identifying targets for friendly guards. It contains a comment that says, "Get a list of potential targets from querying, notifications, and taking damage". After that comment is a chunk of code that gets potential targets from a world query, and a chunk of code that gets potential targets from listening for attack notifications from other nearby allied NPCs.

    And then we get to "taking damage". In Starbound version 1.4.4, at line 363, there is this chunk:

    Code:
        if self.wasDamaged then
          local damageSource = board:getEntity("damageSource")
          if entity.damageTeam().type ~= "pvp" and world.isNpc(damageSource, entity.damageTeam().team) then
            npc.setDamageTeam(args.hostileDamageTeam)
          else
            table.insert(newTargets)
          end
        end
    As far as I can tell, nothing in the game code ever sets the self.wasDamaged instance variable, so this code should be dead. But even if this wasn't the case, the line table.insert(newTargets) throws an error when I try to run it in a Lua interpreter. Lua requires 2 parameters for the table.insert function. I assume, given that NPC guards don't regularly vanish in puffs of ill logic, that this branch can't be triggered, since it would immediately crash and cause the NPCs to die.

    Does anyone have any idea what the Chucklefish devs had intended this code chunk to do? I'd guess it's supposed to read a damage report from somewhere and change the NPC's allegiance based on that? But as is, the code seems dead and broken.

    Knowing that Frackin Universe heavily changes the base code, I checked their /scripts/actions/npc.lua file, but its implementation is identical to the base version, modulo whitespace. I'm not sure if anyone else has noticed this before.
     

Share This Page