Unit Improvements

What would you like to see in Freeciv? Do you have a good idea what should be improved or how?
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Unit Improvements

Post by Elefant »

Here is a ruleset with lua script I wrote to try and make a ranged air combat system. It doesn't work, so if someone could take a look at it and tell me where the errors are, that would be great. As you can see, I used Bombard 2 and 3 to make an "airstrike" action. However, because the range for both actions is ruleset-wide and not different for each unit, I am limited to two different ranges, and I can't use Bombard 3 to make a bomb city/tile action that would destroy improvements.
Attachments
civ3.zip
(109.79 KiB) Downloaded 79 times
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
vego
Veteran
Posts: 75
Joined: Thu May 26, 2022 10:49 am

Re: Unit Improvements

Post by vego »

I dont understand how air units are ranged. Do you mean rocket attack or something like that? If you mean about classic air fight then hex to hex. And bombers over. If about bombarding improvements, id i would rather city.
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Unit Improvements

Post by Elefant »

I mean ranged like in civ 3 and civ 4, where they rebase from city/airbase/carrier to city/airbase/carrier and perform ranged missions like airstrike and airbomb, based on the range of the unit. Of all the air combat styles I have tried(freeciv, civ 3, civ 4), my favorite is the civ 4 running DCM one.
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Unit Improvements

Post by Elefant »

Here's the part of the code that isn't working.

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")
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
vego
Veteran
Posts: 75
Joined: Thu May 26, 2022 10:49 am

Re: Unit Improvements

Post by vego »

I dont understand
vego
Veteran
Posts: 75
Joined: Thu May 26, 2022 10:49 am

Re: Unit Improvements

Post by vego »

I mean your idea
vego
Veteran
Posts: 75
Joined: Thu May 26, 2022 10:49 am

Re: Unit Improvements

Post by vego »

You want more inteligence form of Carrier using? Like with bombers like in 1942? And maybe problem is rebase or weapon units on Carrier to missions
vego
Veteran
Posts: 75
Joined: Thu May 26, 2022 10:49 am

Re: Unit Improvements

Post by vego »

And remember that Carrier rather dont make a tactical targets. It's strategical. Who has carrier is top. You only using in last situatins.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: Unit Improvements

Post by Ignatus »

Likely, one of the problems is that you write actor.kill() insto actor:kill("killed", killer).
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Unit Improvements

Post by Elefant »

That would be an issue, though it doesn't even start the for loops (you can see that I added a bunch of notify functions to tell how far it goes). As for what I mean by ranged air units, I basically want air combat like civ 4 DCM.
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Post Reply