friendly mercenary tribes

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
User avatar
meynaf
Veteran
Posts: 83
Joined: Sun Jan 21, 2018 10:27 am
Location: Lyon / France
Contact:

friendly mercenary tribes

Postby meynaf » Mon Jan 22, 2018 6:08 pm

Hello,

Again working on my ruleset.
This time it's about huts.

Both Legion and Horsemen have the "Hut" flag set.
However when going into huts I only get legions, never horsemen...

Did i miss something somewhere ?
Is random choice between all available units for huts implemented and working ?

Besides, how to setup the ruleset so these have no home city when recruited ?

Akechi
Posts: 25
Joined: Thu Dec 07, 2017 12:17 pm

Re: friendly mercenary tribes

Postby Akechi » Wed Jan 24, 2018 9:07 am

According to data/default/default.lua(_deflua_hut_get_mercenaries), we search unit which have role 'HutTech', with player information.
According to common/scriptcore/api_game_find.c(api_find_role_unit_type) and common/unittype.c(best_role_unit_for_player), last defined unit in units.ruleset is selected which you can build.
If you cannot build any 'HutTech' role unit, then we backed to default.lua, and search unit which have role 'Hut', without any player information.
According to api_game_find.c and unittype.c(get_role_unit), first defined unit selected.

e.g. in classic ruleset:
We obtain Knights if we have technology Chivalry (but must not have Leadership).
If we have not Chivalry or Knights is obsoleted, then we obtain Musketeers if we have technology Gunpowder (but must not have Conscription).
If we have not Gunpowder or Musketeers is obsoleted, then we obtain Legion. :shock:
We cannot obtain Horsemen and Chariot by hut.

This behavior is implemented from Freeciv 2.2, it seems.
In Freeciv 1.14 to 2.1, it seems chosen at random from 'HutTech' units and 'Hut' units if no eligible unit.

To set no homecity in unit which spawned from hut, you need copy data/default/default.lua to your ruleset, and change unit:get_homecity() to nil in function _deflua_hut_get_mercenaries.

User avatar
GriffonSpade
Elite
Posts: 578
Joined: Mon Apr 29, 2013 4:41 pm

Re: friendly mercenary tribes

Postby GriffonSpade » Wed Jan 24, 2018 10:18 am

Akechi wrote:We obtain Knights if we have technology Chivalry (but must not have Leadership).
If we have not Chivalry or Knights is obsoleted, then we obtain Musketeers if we have technology Gunpowder (but must not have Conscription).
If we have not Gunpowder or Musketeers is obsoleted, then we obtain Legion. :shock:
We cannot obtain Horsemen and Chariot by hut.


Oh, hmm, that's not good, now is it? Not only does using more than one Hut unit not work, units aren't even in order of tech level by default (They're ordered by 'group' first). It means that Knights are preferred over Musketeers. And if you have Leadership, even that is Broken!?
Seems like there should be a priority level instead or something...

Akechi
Posts: 25
Joined: Thu Dec 07, 2017 12:17 pm

Re: friendly mercenary tribes

Postby Akechi » Wed Jan 31, 2018 12:26 pm

GriffonSpade wrote:Oh, hmm, that's not good, now is it? Not only does using more than one Hut unit not work, units aren't even in order of tech level by default (They're ordered by 'group' first). It means that Knights are preferred over Musketeers. And if you have Leadership, even that is Broken!?
Seems like there should be a priority level instead or something...
Below code is not smart, but if you prefer 1.14 to 2.1 hut mercenaries behavior in Classic ruleset, try this code to default.lua in your own ruleset:

Code: Select all

-- Get a mercenary unit from entering a hut.
function _deflua_hut_get_mercenaries(unit)
  local owner = unit.owner

-- Comment out.
--[[
  local type = find.role_unit_type('HutTech', owner)

  if not type or not type:can_exist_at_tile(unit.tile) then
    type = find.role_unit_type('Hut', nil)
    if not type or not type:can_exist_at_tile(unit.tile) then
      type = nil
    end
  end
--]]

  local type = nil
  local chivalry = owner:knows_tech(find.tech_type("Chivalry"))
  local gunpowder = owner:knows_tech(find.tech_type("Gunpowder"))
  local chance = random(0, 5)

  if chivalry == true and gunpowder == true then
    if chance == 0 or chance == 1 or chance == 2 then
      type = find.unit_type("Knights")
    else
      type = find.unit_type("Musketeers")
    end
  elseif gunpowder == true then
    type = find.unit_type("Musketeers")
  elseif chivalry == true then
    type = find.unit_type("Knights")
  end

  if not type or not type:can_exist_at_tile(unit.tile) then
    if chance == 0 or chance == 1 then
      type = find.unit_type("Legion")
    elseif chance == 2 or chance == 3 then
      type = find.unit_type("Horsemen")
    else
      type = find.unit_type("Chariot")
    end
    if not type or not type:can_exist_at_tile(unit.tile) then
      type = nil
    end
  end

  if type then
    notify.event(owner, unit.tile, E.HUT_MERC,
                 _("A band of friendly mercenaries joins your cause."))
    owner:create_unit(unit.tile, type, 0, unit:get_homecity(), -1)
    return true
  else
    return false
  end
end
I tested above code in 2.6 beta-2, but if you use 2.5, rename _deflua_hut_get_mercenaries to default_hut_get_mercenaries.

User avatar
meynaf
Veteran
Posts: 83
Joined: Sun Jan 21, 2018 10:27 am
Location: Lyon / France
Contact:

Re: friendly mercenary tribes

Postby meynaf » Wed Jan 31, 2018 3:03 pm

If simple lua script can fix this i'll gladly apply !
However you say default.lua and in the ruleset there is only script.lua.
Did the name simply change since 2.5 ? Or is this another file ? I don't want to touch any global file...

Akechi
Posts: 25
Joined: Thu Dec 07, 2017 12:17 pm

Re: friendly mercenary tribes

Postby Akechi » Wed Jan 31, 2018 4:14 pm

meynaf wrote:If simple lua script can fix this i'll gladly apply !
However you say default.lua and in the ruleset there is only script.lua.
Did the name simply change since 2.5 ? Or is this another file ? I don't want to touch any global file...

default.lua is placed on data/default/.
https://github.com/freeciv/freeciv/blob ... efault.lua
If you copy this file to your own ruleset, Freeciv may load your default.lua instead of data/default/default.lua.
So ruleset modder can change hut behavior and partisan behavior in own ruleset.

User avatar
Caedo
Elite
Posts: 465
Joined: Sun Feb 10, 2013 10:21 pm
Location: Stuttgart, Germany

Re: friendly mercenary tribes

Postby Caedo » Wed Jan 31, 2018 7:31 pm

A better alternative to overwriting default.lua in your ruleset is to define everything necessary in script.lua, but returning false from the function. This should (in principle) tell the engine not to stop processing that event, so it won't execute the default code. I haven't actually tried it though.
~S.C. L.

User avatar
meynaf
Veteran
Posts: 83
Joined: Sun Jan 21, 2018 10:27 am
Location: Lyon / France
Contact:

Re: friendly mercenary tribes

Postby meynaf » Wed Jan 31, 2018 9:18 pm

Ok, I will try. Thanks for your help :)

Btw. Are there other files that can be overridden this way ?

User avatar
Caedo
Elite
Posts: 465
Joined: Sun Feb 10, 2013 10:21 pm
Location: Stuttgart, Germany

Re: friendly mercenary tribes

Postby Caedo » Wed Jan 31, 2018 11:30 pm

All .ruleset files have to be supplied/overridden if I'm not mistaken. I'm not sure if adding an empty script.lua file is necessary or if that is assumed blank if not supplied. Only default.lua is imported from /data/default/ if it isn't supplied (and it is recommended to not override it). So really, that's the only case where you have the choice whether to use the existing one or not.
~S.C. L.

User avatar
meynaf
Veteran
Posts: 83
Joined: Sun Jan 21, 2018 10:27 am
Location: Lyon / France
Contact:

Re: friendly mercenary tribes

Postby meynaf » Thu Feb 01, 2018 11:13 am

It seems default.lua isn't big and having to make a diff when upgrading shouldn't be too much of a hassle.
Therefore I duplicated it in my dir and did the patch given here.
It works !

Another problem solved.
But the further I go, the hotter it gets...