Correct the rulesets civ1 and civ2

Do you want to help out with Freeciv development? Then check out this forum.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

Hydro plants.

Comments in building.ruleset for civ1:

Code: Select all

; Civ1 would allow building Hydro Plant if there`s either River OR Mountains
; but it is not possible to implement with current ruleset format.
and civ2:

Code: Select all

; Civ2 would allow building Hydro Plant if there`s either River OR Mountains
; but it is not possible to implement with current ruleset format.

Freeciv reqs vectors have little or no facility for disjunction for ruleset files other than in effects.ruleset. This had meant that the criteria for hydro plants in Civ I & II (etc.) could not be implemented in full. Of the two predicates (river & mountain) the fc tradition has been to just use the former.

IT MAY BE 25 YEARS BUT THE WAIT IS OVER:

Add the following two sections to terrain.ruleset:

Code: Select all

[extra_hydro]
name           = _("Hydro")
category       = "Natural"
causes         = "Base"
graphic        = "None"
activity_gfx   = "None"
rmact_gfx      = "None"
buildable      = FALSE
helptext       = _("\
Marks a tile that if next to a city will enable hydro plant \
and Hoover Dam\
") 
[base_hydro]
extra          = "Hydro"
gui_type       = "Other"
Remove the following predicate from the section [building_hydro_plant] (in buildings.ruleset)

Code: Select all

      "Extra", "River", "Adjacent"
and replace it with:

Code: Select all

      "Extra", "Hydro", "Adjacent"
i.e replace "River" with "Hydro".

The river predicate is usually missing from hoover dam (in all rulesets) but I believe the same criteria applies to Civ I (& II) - except for factory - so ADD the hydro predicate to the reqs vector in [building_hoover_dam].

Add the following shell to script.lua:

Code: Select all

    function whole_map()
        for tile 
        in  whole_map_iterate()
        do
            local tname = tile.terrain:rule_name()
-- insert active code here          
          
        end
        return false
    end
   
signal.connect("map_generated", "whole_map")


next ....
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

Insert the following into the iterate loop:

Code: Select all

        
--  nef 2018/12/8

--  This lua script provides the feature in Civilization (Civ I) 
--  where a hydro plant and/or the Hoover Dam can be built if the
--  city center is Adjacent to a river OR a mountain. 
 
-- requires changes to the ruleset:
--  a.  inclusion of a suitable 'extra' in terrain.ruleset with
--   the name "Hydro".  This should NOT have category "Bonus".
-- category       = "Natural"
-- causes         = "Base"
-- graphic        = "None"
-- activity_gfx   = "None"
-- rmact_gfx      = "None"
-- buildable      = FALSE
--       the companion base section comprises:
-- extra          = "Hydro"
-- gui_type       = "Other"

--  b. altering the predicate from "River" to "Hydro" for 
--    section [building_hydro_plant] and adding it to section
--    [building_hoover_dam] both in buildings.ruleset.

-- insert the following code into a suitable 
-- whole_map_iterate loop

          if   tname == "Mountains" 
          or   tile:has_extra ("River") 
          then edit.create_extra(tile,"Hydro")
          end
          
-- the name "Hydro" throughout is user selectable


I see no reason why this could not be used for any fc ruleset that has hydro plants and/or hoover dam


A similar trick could be used to reduce the number of civ2civ3 aqueducts from three to two. E.g.

Code: Select all

          if   tname == "Lake" 
          or   tile:has_extra ("River") 
          then edit.create_extra(tile,"Fresh")
          end
etc..

Finally, since Civ I only allows river on grassland (which was implemented as a separate terrain in Civ I) and for some other reasons, I suggest adding the following to section [effect_mining_tf] in effects.ruleset:

Code: Select all

reqs	=                                   ;nef
    { "type",  "name",  "range", "present"  ;nef
      "Extra", "River", "Local",  FALSE     ;nef
    }                                       ;nef
Edit: confirmation by meynaf that riverine transform is not allowed so I have deleted the alternative.

Also there seems to be some confusion over reqs and effects. My recollection is that you needed to have a factory to build hydro plant (but not Hoover Dam) - this being as it is in the civ1 ruleset. But also the production benefit only occurs if you have a factory (in both cases). This is NOT the way the effects are coded in civ1.

The Civ I wiki is a disaster - so it needs someone who actually knows to sort this out.
Last edited by nef on Mon Jan 28, 2019 1:56 pm, edited 1 time in total.
User avatar
meynaf
Hardened
Posts: 155
Joined: Sun Jan 21, 2018 10:27 am
Location: Lyon / France
Contact:

Re: Correct the rulesets civ1 and civ2

Post by meynaf »

nef wrote: Can someone please confirm or deny that this riverine transform is/is not possible in Civ I.
River in civ1 is considered as a distinct terrain type. It can not be changed to something else.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

Mapgen in freeciv is idiomatic and does not match Civ I/II resource extra allocation.

I have raised this issue elsewhere but current developments are going in the opposite direction, so I have created a partial solution with Lua and some [extra]'s.

The low hanging fruit was to
  • Assign a one shield resource extra to grassland with a density of 1/2 instead of the fc 'one size fits all' that applies to general resource extras.
    Provide this to relevant transformable terrain which in Civ I comprises the terrains Swamp and Jungle.
    Provide a facility to anticipate the result of these transforms.
It would be possible to provide some facilities for the converse e.g. latent general resources for forest and plains but I have put them on the "backburner" for various reasons. Fc 3.0 will make those easier.

Another feature of Civ I/II was that resources were assigned in patterns. This could be easily done for grassland but I see no point and I kinda like it random. Petition me if you disagree.


Include the following sections into terrain.ruleset:

Code: Select all

[extra_shield]
name           = _("Shield")
category       = "Natural" ;  make it more like [resource]
causes         = "Road"
graphic        = "ts.grassland_resources";   this graphic name
               ; needs to be included in  [extras] "styles =" 
               ;  in *.tilespec for any tileset used
activity_gfx   = "None"
rmact_gfx      = "None"
buildable      = FALSE
hidden_by      = "Grass_shield"
reqs =
    { "type",    "name",   "range", "present", "quiet"
      "Terrain", "Forest", "Local",  FALSE,     TRUE
    }
helptext       = _("\
Provides grassland resources instead of using MapGen\
")

[road_shield]
extra          = "Shield"
move_cost      = -1  ; no effect on movement
shield_incr    =  1  ; reason for using road as extra cause

[extra_grass_shield]
name           = _("Grass_Shield")
category       = "Natural" ;  make it more like [resource]
causes         = "Road"
graphic        = "None"
activity_gfx   = "None"
rmact_gfx      = "None"
buildable      = FALSE
reqs =
    { "type",    "name",      "range", "present", "quiet"
      "Terrain", "Grassland", "Local",  FALSE,     TRUE
    }
helptext       = _("\
A tile with this extra will have grassland resource\
 if changed to grassland\
")

[road_grass_shield]
extra          = "Grass_Shield"
move_cost      = -1  ; no effect on movement

In section [terrain_grassland] disable resources:

Code: Select all

; resources            = "Resources"
and add/change:

Code: Select all

road_shield_incr_pct = 100

next ....
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

Insert the following into the whole map iterate loop used for hydro:

Code: Select all

--  nef 2019/01/12

--  B. added code to allow swamp and jungle to be included
--  as potential grassland/shield 'i' transforms

--  nef 2019/01/10

--  A. code to create Civ I (and Civ II) style grassland
--  resource extra

--  Part A requires changes to the ruleset:
--  a.  inclusion of a road/extra pair in terrain.ruleset
--   with the name "Shield". Add/change the following
--   fields in the extra section
-- graphic     = "ts.grassland_resources"
-- buildable   = FALSE
-- reqs        =
--     { "type",    "name",   "range", "present", "quiet"
--       "Terrain", "Forest", "Local",  FALSE,     TRUE
--     }

--   Road section comprises:
-- extra          = "Shield"
-- move_cost      = -1
-- shield_incr    = 1

--  b. in section [terrain_grassland] disable resources:
-- ; resources            = "Resources"
-- and add/change:
-- road_shield_incr_pct = 100


--  d. adding to the [extras] section (styles =) in *.tilespec
--  e.g. amplio2 etc.:
--        "ts.grassland_resources", "Single1"

-- the extra name "Shield" throughout is user selectable


-- Part B requires changes to the ruleset:
--   inclusion of a road/extra pair in terrain.ruleset with
--   the name "Grass_Shield". Add/change the following
--   fields in the extra section:
-- graphic     = "None"
-- buildable   = FALSE
-- reqs        =
--     { "type",    "name",      "range", "present", "quiet"
--       "Terrain", "Grassland", "Local",  FALSE,     TRUE
--     }

--   Road section comprises:
-- extra          = "Grass_Shield"
-- move_cost      = -1
-- the extra name "Grass_Shield" throughout is user selectable


            if  random(1, 100) <= 50               -- part A
            then
          
              if     tname == "Grassland"
              then   edit.create_extra(tile,"Shield")
              elseif tname == "Swamp"                     -- part B
              or     tname == "Jungle"
              then 
                     edit.create_extra(tile,"Grass_Shield")
                     edit.create_extra(tile,"Shield") -- end part B
              end
            
            end                                -- end part A
Include "ts.grassland_resources" into the [extras] section in any *.tilespec you may want to use:

Code: Select all

        "ts.grassland_resources", "Single1"
Note that this introduces a slight glitch in graphics layering. Some might say the result is actually better.

The "specials" server option seems to have a fudge factor of 2, so the default value of 250 appears to give a density of 1/8 (not 1/4). Civ I (and Civ II) have a 'patch' density of 1/9 (for general resource extras) but there was some extra space between patches - suggesting a value of 1/10 might be more accurate - i.e. a "specials" value of 200. This reduction would be appropriate now that grassland resource density will be increased from 1/8 to 1/2. To put this into effect add the following to the section [settings] in game.ruleset

Code: Select all

      "specials", 200, FALSE                  ; nef
Change FALSE to TRUE if you want to insist on Civ I accuracy (along with those for most of the others).

The code I am supplying is for use in the civ1 ruleset. Extension to civ2 and other fc rulesets is problematic because of indefinite tranforms to/from grassland. The problem is to have a simple general procedure for hiding the graphic for the grassland shield. The alternative is to use an end and/or start turn callback and do a whole map iterate each turn. For the moment, I will leave that to others. The actual shield bonus is no trouble - but may need a slightly more robust approach i.e. use the effect Output_Add_Tile.

Having said all that it appears to me that this procedure would work perfectly well in Civ II - except that when creating grassland using the "o" transform you would never get a 1 shield resource special. Even with these, some simple changes could be made to give you a one shot chance. Other rulesets such as classic would need yet more tinkering since there are typically other options for creating/destroying grasssland.

A callback for terrain transform would make this a breeze for all rulesets. And fc3.x would help too. Even better would be valid_resource_extra iterate on a terrain.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

The slightly more robust technique is to not use the new (arcane?) fields in [terrain_*], and [road_*] but rely instead on ye olde faithful [effect_*] Output_Add_Tile.
  • Delete the addition road_shield_incr_pct to [terrain_grassland].
    Delete the shield_incr in [road_shield]
    Add the following rule to effects.ruleset:

Code: Select all

[effect_grassland_shield]
type    = "Output_Add_Tile"
value   = 1
reqs  =
    { "type",       "name",         "range"
      "Terrain",    "Grassland",    "Local"
      "Extra",      "Grass_Shield", "Local"
      "OutputType", "Shield",       "Local"
    }

Eagle eyes should see that there is now NOTHING needed in the [base_*]/[road_*] sections to effect (sic) ALL the changes made to date. So yet another suggestion:

Add to the list of possible "causes" for an extra, another cause which simply means 'no particular cause'. And be adventurous: make this the default.

And another; all these:

Code: Select all

graphic        = "None"
activity_gfx   = "None"
rmact_gfx      = "None"
should default to umm, err, "None".

Doing so would allow one to remove so much crap from terrain.ruleset.
cazfi
Elite
Posts: 3069
Joined: Tue Jan 29, 2013 6:54 pm

Re: Correct the rulesets civ1 and civ2

Post by cazfi »

nef wrote:The slightly more robust technique is to not use the new (arcane?) fields in [terrain_*], and [road_*] but rely instead on ye olde faithful [effect_*] Output_Add_Tile.
Such conversions would not end in a civ1/civ2 compatible ruleset, as the terrain_ and road_ defined bonuses are added to the calculation at different time than Output_Add_Tile -> they are subject to different bonuses (what multiplications apply to them) and also rounding rules would cause differences in outcome.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

cazfi wrote: Such conversions would not end in a civ1/civ2 compatible ruleset, as the terrain_ and road_ defined bonuses are added to the calculation at different time than Output_Add_Tile -> they are subject to different bonuses (what multiplications apply to them) and also rounding rules would cause differences in outcome.
As best I can tell there is only one road type multiplier for civ1/civ2 - and that is +50% for railroad (others are just yes/no). In the case of shields on grassland there is only 1 so with a multiplier of 1.5 the result is still just 1. In the special case of the Wonder (KRC) one could just have second rule with different predicates - except that KRC uses the same effect - so there is no special case. (I am not entirely convinced that this is actually correct for Civ II - and similar comments apply to the colossus trade bonus for both Civ I & II.)

Maybe my comment was taken out of context. It was only in connection with my proposal for adding shields to grassland. I was NOT suggesting anything more general. But having said that one could make do with just effects - the difference being that complexity due to the number and variety of rules may become excessive.

I can assure you that I was aware that "road" type multipliers are applied before ANY of the direct tile effects with the multiplier effect itself (Output_Per_Tile) coming after Output_Add_Tile and Output_Inc_*.

For my complete analysis :

Code: Select all

Tile produce in freeciv 2.6

[effect_*]

type    = "Irrigation_Pct" ; pct modulator factor to [terrain].irrigation_food_incr
type    = "Mining_Pct"     ; pct modulator factor to [terrain].mining_shield_incr

N.b. these have NOTHING to do with [extras] with cause = "irrigation" | "mining" which are just placeholders for i/m orders, reqs predicates, conflicts, hidden_by, graphics etc..  These extras do NOT feature in any calculations other than indirectly as potential predicates to [effect_*] with types described above.  So first off we have:

** = [terrain_*].irrigation_food_incr * {[effects_*].Irrigation_Pct/100}; # = food
** = [terrain_*].mining_shield_incr   * {[effects_*].Mining_Pct/100};     # = shield
** = 0;                                                                   # = trade
** = 0;                                                  # = (gold, luxury, science)

    ; {} = summation over effects, extras

base tile produce before ANY direct [effect_*] tile modulator =

(   ** + [terrain_*].# + [resource_*].# + {[road_*].#_incr_const}
       + [terrain_*].road_#_incr_pct/100  * { [road_*].#_incr }      ) 
 *  ( 1 +{[road_*].#_bonus/100}  ) ; # = (food, shield, trade) 
            
0 ; # = (gold, luxury, science)
-------------------------
Direct modulators (applied in order)

[effect_*]

type    = "Output_Add_Tile"            ;  + value
type    = "Output_Inc_Tile"            ;) + value if tile >= 1
type    = "Output_Inc_Tile_Celebrate"  ;) + value if tile >= 1 and celebrating
type    = "Output_Per_Tile"            ;  + value pct 
type    = "Output_Penalty_Tile"        ;  -1 if tile >= value and NOT celebrating
type    = "Output_Tile_Punish_Pct"     ;  - value pct  

"tile" is tile produce after previous modulators have been applied
to that calculated from formula above (base tile produce).

"OutputType" can be any of (food, shield, trade, gold, luxury, science)

[civstyle] (game.ruleset)

min_city_center_# = <value>           ;   minimum tile produce for city center
      ; # = (food, shield, trade)
-------------------------
After this, all "OutputType"'s roll up to the city.  
I think you may be able to see why I said "arcane".
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

In my previous post I commented on how the civ1 AI were not afraid of militia and calvary, making the game a farce. With no response to date I decided to take it on myself.

So here's what I came up with:

Change BOTH of the following two values from 1 to 2 for ALL units in the civ1 ruleset so:

Code: Select all

hitpoints     = 2     ;nef 
firepower     = 2     ;nef
While you are at it also remove the DamageSlows flag from [unitclass_land]

Code: Select all

 
; flags         = "TerrainSpeed", "DamageSlows", "CanOccupyCity", "BuildAnywhere",
flags         = "TerrainSpeed",  "CanOccupyCity", "BuildAnywhere", ;nef
and [unitclass_sea]:

Code: Select all

; flags         = "DamageSlows", "AttackNonNative", "AttFromNonNative"
flags         =  "AttackNonNative", "AttFromNonNative"   ;nef
These flags have no place in Civ I but are harmless in the civ1 distro. Not so with my changes - removal will help mitigate the adverse consequences of a hard coded 'feature'.


I have only just looked at this so my roadtesting is quite limited. From what I've seen so far I can say with confidence that
The civ1 game is now playable.
Now I know that there are some who will scoff at my efforts, thinking of Civ I as 'old hat'. But for those who want -
  • A change.
    A game that is NOT Civ II.
    A game that gives you enough time to engage in military adventures before the tech tree is finished.
    A game that focuses more on strategy and less on understanding minutia in the rules.
    A game that focuses more on strategy and less on micromanagement.
then I suggest you now give it try.
nef
Elite
Posts: 324
Joined: Mon Jun 25, 2018 5:01 pm

Re: Correct the rulesets civ1 and civ2

Post by nef »

I mentioned in my reply to caz a concern that I had about the order of the railroad multiplier bonus.

Can someone confirm that the rail bonus of 50% applies BEFORE these tile effects:
  • a. Output_Add_Tile
    b. Output_Inc_Tile
    c. Output_Inc_Tile_Celebrate
In Civ I a fairly simple test to check (b) is to use republic or democracy, for (c) celebration under monarchy or communism. The criterion in both cases is: does a normal railroad tile produce 2 or 3 trade? (Normal = grassland|plains|desert.) An alternative/additional test for (b) in Civ I is to use the Colossus (instead of gov). It would be even better to find out if the same rule order applied to each situation. And of course, there is a 'sanity' test - trying both on the same tile.

For (a) one could use King Richard's Crusade (in Civ II) and test for shields. In this case a grassland tile would need the resource special.

In all three (simple) cases 2 means BEFORE, 3 means AFTER.

"BEFORE" is the current and traditional method for fc rulesets but that's no guarantee it's actually true for Civ I&II.

Obviously, the sky is not going to fall in if this remains unaswered, but for me, it's a prickly loose end.

The tests described above are the only examples I could find in Civ I & II where the order of the bonus multiplier makes a difference. If anyone can identify any others - I'm all ears.
Post Reply