Ranged Air Units

Do you want to help out with Freeciv development? Then check out this forum.
Post Reply
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Ranged Air Units

Post by Elefant »

Trying to make ranged air units with the bombard2/3 actions, I ran into two problems.
First, the units can bombard an unlimited number of times in a turn.
Second, my interception script won't run properly. The last thing it does is notify me "Checking for interceptor", although it might be going on past that up to the notify "Checking Player"

Code: Select all

function check_interceptor_aa(action, actor, target)
  notify.player(actor.owner, _("Checking for interceptor"))
  local actor_name = actor.utype:name_translation()
  local target_name = target.utype:name_translation()
  notify.player(actor.owner, target_name)
  local intercepted = false
  --iterate units owned by the target player
  for player in players_iterate() do
    notify.player(actor.owner, _("Checking Player"))
    if not player == actor.owner then
      for unit in player:units_iterate() do
        notify.player(actor.owner, _("Checking Unit"))
        if unit.tile:sq_distance(target) <= 36 and unit.utype:has_flag("Interceptor1") and random(1, 100) <= 30 then --and unit.owner == target.owner then
          local intercepted = true
          local interceptor_name  = unit.utype:name_translation() 
          notify.player(actor.owner, _("Intercepted!"))
        elseif unit.tile:sq_distance(target) <= 64 and unit.utype:has_flag("Interceptor2") and random(1, 100) <= 101 then -- and unit.owner == target.owner then
          local intercepted = true
          local interceptor_name  = unit.utype:name_translation()
          notify.player(actor.owner, _("Intercepted!"))
        elseif unit.tile == target and unit.utype:has_flag("AA1") and random(1, 100) <= 10 then -- and unit.owner == target.owner then
          local intercepted = true
          local interceptor_name  = unit.utype:name_translation()
          notify.player(actor.owner, _("Intercepted!"))
        elseif unit.tile == target and unit.utype:has_flag("AA2") and random(1, 100) <= 25 then --and unit.owner == target.owner then
          local intercepted = true
          local interceptor_name  = unit.utype:name_translation()
          notify.player(actor.owner, _("Intercepted!"))
        elseif unit.tile == target and unit.utype:has_flag("SAM") and random(1, 100) <= 40 then --and unit.owner == target.owner then
          local intercepted = true
          local interceptor_name  = unit.utype:name_translation()
          notify.player(actor.owner, _("Intercepted!"))
        end
      end
    end
  end
  if intercepted == true then
    notify.player(actor.owner, _("Intercepted!"))
    notify.event(actor.owner, target,
                 E.UNIT_ACTION_ACTOR_FAILURE,
                 -- /* TRANS: Your Bomber was intercepted doing
                 --  * airstrike Rifleman. */
                 _("Your %s was intercepted doing airstrike %s."),
                 actor_name,
                 target_name)

    notify.event(target.owner, target,
                 E.UNIT_ACTION_ACTOR_SUCCESS,
                 -- /* TRANS: Your Fighter intercepted a British Bomber doing
                 --  * airstrike to your Rifleman. */
                 _("Your %s intercepted a %s %s doing airstrike to your %s."),
                 interceptor_name,
                 actor.owner.nation:name_translation(),
                 actor_name,
                 target_name)
       actor.kill()
    elseif intercepted == false then
       notify.player(actor.owner, _("Success!"))
       notify.event(actor.owner, target,
                 E.UNIT_ACTION_ACTOR_SUCCESS,
                 -- /* TRANS: Your Bomber sucessfully did
                 --  * airstrike Rifleman. */
                 _("Your %s sucessfully did airstrike %s."),
                 actor_name,
                 target_name)

      notify.event(target.owner, target,
                 E.UNIT_ACTION_TARGET_HOSTILE,
                 -- /* TRANS: Your Fighter intercepted a British Bomber doing
                 --  * airstrike to your Rifleman. */
                 _("Your %s intercepted a %s %s doing airstrike to your %s."),
                 interceptor_name,
                 actor.owner.nation:name_translation(),
                 actor_name,
                 target_name)
  end
end

-- Handle tile targeted unit action start
function action_started_unit_unit_callback(action, actor, target)
  if action:rule_name() == "Bombard2" then
    check_interceptor_aa(action, actor, target)
  elseif action:rule_name() == "Bombard3" then
    check_interceptor_aa(action, actor, target)
  elseif action:rule_name() == "Bombard 2" then
    check_interceptor_aa(action, actor, target)
  elseif action:rule_name() == "Bombard 3" then
    check_interceptor_aa(action, actor, target)
  end
end

signal.connect("action_started_unit_units",
"action_started_unit_unit_callback")
If someone could tell me what I did wrong, that would be much appreciated.
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Post Reply