Using improvements to make other improvements obsolete

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
Post Reply
FriendAtArms
Posts: 36
Joined: Thu Apr 16, 2026 9:35 pm

Using improvements to make other improvements obsolete

Post by FriendAtArms »

I've currently got an improvement called a "Sanctuary", with a small anti-disease effect. Eventually you can build another improvement called a "Hospital", with a big anti-disease effect. My intention is, if you've got a Sanctuary in your city, it keeps working until you build a Hospital, and then becomes obsolete and disappears.

Right now, the Sanctuary's obsolete_by entry says:
obsolete_by =
{ "type", "name", "range"
"Building", "Hospital", "City"
}
I run a test game and build a Hospital in one of my cities. The Sanctuary's name in that city is crossed out and "(O)" is tacked on, so I know it's considered obsolete. Sanctuaries in other cities are unaffected. But then the obsolete Sanctuary sticks around for several turns before the automatic deletion kicks in.

Is that how it's supposed to work? I know that in standard rulesets, Barracks I gets instantly deleted when you research Gunpowder, and I'm not sure why using a technology as the obsolescence condition would be different from using an improvement.

(Of course if worse comes to worst, I can just solve this like I did the "standard Temple vs. Temple of Artemis" problem I posted about earlier. The Sanctuary just loses its effect, rather than being properly "obsolete", leaving its deletion to the player's discretion. But I am curious about whether Freeciv distinguishes between improvement-obsolescence and technology-obsolescence somehow.)
John Campbell
Posts: 21
Joined: Wed Jan 18, 2023 6:57 pm

Re: Using improvements to make other improvements obsolete

Post by John Campbell »

I have something similar with walls, where I have a series of progressively more advanced walls that take progressively more advanced Artillery units to bypass, so there's an arms race between offensive and defensive technology. But I don't want walls to just vanish when the tech to build better ones is developed and leave cities vulnerable even to things that the older walls would protect against. So I have them set up so that you can no longer build obsolete walls after the tech for the newer ones is developed, but the walls don't actually disappear until a newer one is actually built in the city.

So my entry for City Walls, which are the earliest iteration, looks like this:

Code: Select all

[building_city_walls]
name            = _("City Walls")
genus           = "Improvement"
flags           = "VisibleByOthers"
reqs    =
    { "type", "name", "range", "present"
      "Tech", "Masonry", "Player", TRUE
      "Tech", "Construction", "Player", FALSE
    }
graphic = "b.citywalls"
graphic_alt     = "-"
obsolete_by     =
    { "type", "name", "range"
        "Building", "Curtain Walls", "City"
        "Building", "Bastions", "City"
        "Building", "Fortifications", "City"
    }
build_cost      = 60
upkeep          = 1
sabotage        = 50
sound           = "b_city_walls"
sound_alt       = "b_generic"
helptext        = _("\
City Walls make it easier to defend a city.  They give a +200% bonus to the\
 defense strength of units within the city against Land and Wheeled units.  They are\
 ineffective against airborne and sea units as well as artillery units and\
 armored vehicles.\
 City Walls also prevent the loss of population which occurs when a\
 defending unit is destroyed by a ground unit.\
 They are made obsolete by Construction and the development of more\
 effective Curtain Walls; however, old walls remain standing until new ones\
 are built.\
")
Curtain Walls, which are the next iteration up, look like so:

Code: Select all

[building_curtain_walls]
name            = _("Curtain Walls")
genus           = "Improvement"
flags           = "VisibleByOthers"
reqs    =
    { "type", "name", "range", "present"
      "Tech", "Construction", "Player", TRUE
      "Tech", "Military Architecture", "Player", FALSE
    }
graphic = "b.city_walls"
graphic_alt     = "-"
obsolete_by     =
    { "type", "name", "range"
        "Building", "Bastions", "City"
        "Building", "Fortifications", "City"
    }
build_cost      = 60
upkeep          = 1
sabotage        = 50
sound           = "b_city_walls"
sound_alt       = "b_generic"
helptext        = _("\
Curtain Walls make it easier to defend a city.  They give a +200% bonus to\
 the defense strength of units within the city against Land and Wheeled\
 units, as well as Catapults.  They are ineffective against airborne and\
 sea units as well as gunpowder Artillery units and armored vehicles.\
 Curtain Walls also prevent the loss of population which occurs when a\
 defending unit is destroyed by a ground unit.\
 They are made obsolete by Military Architecture and the development of more\
 effective Bastions; however, old walls remain standing until newer ones\
 are built.\
")
And so on.

The practical effect of this is that, when you develop Masonry, you can build City Walls (which I'm thinking about renaming "Palisades", because the City/Curtain Wall distinction keeps confusing even me), which protect against most ground units, but can be bypassed by Catapults or any other Artillery unit. When you develop Construction, you gain the ability to build Curtain Walls, which protect against Catapults, but can still be bypassed by Cannons or better, but lose the ability to build City Walls. However City Walls that were already built don't immediately get sold off like Barracks did. They remain, and remain effective, until you actually build Curtain Walls (or Bastions or Fortifications, which are the next iterations, enabled by Military Architecture and Ferroconcrete Construction, respectively) in the city. Even then, it's not until the turn after the new walls are built that the old ones get sold off. I think the obsolescence check happens before the production check, so on the turn the new walls are built, the old ones aren't yet obsolete when it's checked. You can go in and manually sell them off if you want the cash faster, or just wait until the next turn when they're sold automatically.

I have the wall effects set up to explicitly exclude older walls when there's a newer wall in the city, so they don't double up on the turn between the new ones being built and the old ones being sold off, like so:

Code: Select all

[effect_city_walls]
type    = "Defend_Bonus"
value   = 200
reqs    =
    { "type", "name", "range", "present"
      "Building", "City Walls", "City", TRUE
      "Building", "Great Wall", "Player", FALSE
      "Building", "Curtain Walls", "City", FALSE
      "Building", "Bastions", "City", FALSE
      "Building", "Fortifications", "City", FALSE
      "UnitClass", "Artillery", "Local", FALSE 
      "UnitClass", "Armor", "Local", FALSE 
      "UnitClass", "LTA", "Local", FALSE 
      "UnitClass", "Light Air", "Local", FALSE 
      "UnitClass", "Air", "Local", FALSE 
      "UnitClass", "Helicopter", "Local", FALSE 
      "UnitClass", "Missile", "Local", FALSE 
      "UnitClass", "Sail", "Local", FALSE 
      "UnitClass", "Sea", "Local", FALSE 
      "UnitClass", "Brown Water", "Local", FALSE 
      "UnitClass", "Green Water", "Local", FALSE 
    }
(The Great Wall acts as Curtain Walls in all cities, so it overrides local City Walls, but it doesn't force the sell-off of local City Walls like building actual Curtain Walls or better in the city would. It also never goes obsolete, which is my policy for Wonders that are still extant, but it gets a lot less effective as technology improves and more and more of what the enemy's fielding bypasses it.)

Also, annoyingly, the tech-tree skein generator for the Research tab apparently doesn't distinguish between positive and negative tech requirements, so City Walls appear on the tech tree under both Masonry and Construction, with no indication that the latter makes it so you can't build them. and likewise for the more advanced walls.
FriendAtArms
Posts: 36
Joined: Thu Apr 16, 2026 9:35 pm

Re: Using improvements to make other improvements obsolete

Post by FriendAtArms »

However City Walls that were already built don't immediately get sold off like Barracks did. They remain, and remain effective, until you actually build Curtain Walls
Okay yeah, this is what I'm going for with my Sanctuaries! And it looks like your obsolete_by format is the same as mine, so at least I can be sure I got that part right.
Even then, it's not until the turn after the new walls are built that the old ones get sold off.
This is my main problem. For some reason the older building doesn't get sold off on the turn after, or even the turn after that.

I see you've got True/False entries in the requirements for effect_city_walls. I'll add those to my effect_sanctuary, and see if it helps. Thank you very much!
User avatar
Corbeau
Elite
Posts: 1320
Joined: Mon Jan 13, 2014 11:13 pm

Re: Using improvements to make other improvements obsolete

Post by Corbeau »

What I have in my Sim ruleset is that you can build (medieval) Workshop/Manufaktur, but once you build a Factory in the city, the Manufaktur becomes a museum and gives you 2 Gold instead of 2 Production. You may want to think about what would be the effect of the older walls once the new ones are built. Do they make the new ones' upkeep cheaper? Do they add to defence? Are they actually in the way? Are they a tourist attraction?
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
Dino the Dinosore
Hardened
Posts: 231
Joined: Sun Dec 31, 2017 3:41 am

Re: Using improvements to make other improvements obsolete

Post by Dino the Dinosore »

Also, annoyingly, the tech-tree skein generator for the Research tab apparently doesn't distinguish between positive and negative tech requirements, so City Walls appear on the tech tree under both Masonry and Construction, with no indication that the latter makes it so you can't build them. and likewise for the more advanced walls.
That looks like a bug to me, maybe start a ticket for it.

Related - if you have > 1 tech as a positive req for a unit (maybe for buildings also), that unit shows up in multiple techs. Which I think is the right thing to do.

And speaking of obsolete_by, civ2civ3 buildings.ruleset has this for Barracks, which I don't understand -

Code: Select all

obsolete_by	=
    { "type", "name", "range"
      "Tech", "Gunpowder", "Player"
      "Building", "Barracks II", "City"
      "Building", "Barracks III", "City"
    }
Since you can't build Barracks II without having Gunpowder, isn't that redundant?
cazfi
Elite
Posts: 3489
Joined: Tue Jan 29, 2013 6:54 pm

Re: Using improvements to make other improvements obsolete

Post by cazfi »

Dino the Dinosore wrote: Thu Jun 11, 2026 8:36 pmSince you can't build Barracks II without having Gunpowder, isn't that redundant?
Even when you cannot build Barracks II by yourself, you may conquer a city with one.
FriendAtArms
Posts: 36
Joined: Thu Apr 16, 2026 9:35 pm

Re: Using improvements to make other improvements obsolete

Post by FriendAtArms »

Update: I've rewritten how my Sanctuary works in the Effects file, to include True/False statements.
[effect_sanctuary]
type = "Health_Pct"
value = 20
reqs =
{ "type", "name", "range", "present"
"Building", "Sanctuary", "City", TRUE
"Building", "Hospital", "City", FALSE
}
But the timing of Sanctuary deletion is still random. Sometimes it's the same turn a Hospital is built; sometimes it takes several turns.

It looks like I have to go with the "improvement has no effect but still hangs around and must be manually deleted" option. Frustrating, given that I know Freeciv is capable of instantly deleting Barracks I/II. But I'm not even halfway through this ruleset, and I'd like to finish at some point before we all die of old age. I may implement Corbeau's suggestion for "the improvement does something different after X" later, depending on whether I see the AI habitually keeping Sanctuaries in cities that also have Hospitals.

Thank you all!
John Campbell
Posts: 21
Joined: Wed Jan 18, 2023 6:57 pm

Re: Using improvements to make other improvements obsolete

Post by John Campbell »

FriendAtArms wrote: Tue Jun 09, 2026 3:03 am
However City Walls that were already built don't immediately get sold off like Barracks did. They remain, and remain effective, until you actually build Curtain Walls
Okay yeah, this is what I'm going for with my Sanctuaries! And it looks like your obsolete_by format is the same as mine, so at least I can be sure I got that part right.
Even then, it's not until the turn after the new walls are built that the old ones get sold off.
This is my main problem. For some reason the older building doesn't get sold off on the turn after, or even the turn after that.
I don't really build walls all that often, much less upgrade them — walls aren't upkeep-free in my ruleset, and I figure that if the enemy is actually making attacks against my cities, I've already screwed up in several distinct ways, and anyway the current AI is too stupid to do anything but spam infantry and turtle in its cities, which even the lowest-tech walls will defend against. So I've messed around with it enough to determine that the obsolete_by basically works, and it does sell off the walls, but I'm not 100% certain about the timing.

So I've been making a point of building and upgrading walls more than I normally do in my current game to see how it behaves. I just finished my first upgrade, an AI city that had City Walls when I captured it, which I built Curtain Walls in. The City Walls got sold automatically the same turn the Curtain Walls were finished. I also discovered a new tech the same turn, and the "obsolete City Walls sold" message didn't happen in the build phase after the "Curtain Walls built" message, but at the end of the turn-beginning stuff after the "Rifling discovered" message. So it may be that selling off obsolete improvements is being processed as part of tech discovery, on the assumption that that's what obsoletes them? Need more data points, probably. Or actually digging around in the code, which I don't have time for right now.
I see you've got True/False entries in the requirements for effect_city_walls. I'll add those to my effect_sanctuary, and see if it helps. Thank you very much!
Yeah, if I don't want effects combining, I explicitly disallow them from doing so, even if I think there shouldn't be any way for it to actually happen. Because sometimes there's weird corner cases I haven't thought of. Like, I hadn't considered the possibility of capturing a city with a newer Barracks than I could build and then building an older Barracks there. (Barracks don't go obsolete in my ruleset anyway.)

And my situation is complicated by having the Great Wall in the mix, which acts as Curtain Walls in all cities and never goes obsolete, so it needs to override local City Walls, but be overridden by local Bastions or Fortifications, and at least not double up with local Curtain Walls. But I don't want it forcing the sale of redundant walls, or preventing them from being built, in case the Great Wall is lost or destroyed and the local wall needs to take over again.

Another thing you might consider, instead of messing about with trying to get it to sell off Sanctuaries properly and prevent them from combining if both are in a city at once, is to just have them both and let them combine. Reduce the Hospital effect by the Sanctuary effect, maybe reduce the Hospital build and upkeep cost, and just let them stack. Maybe have the Sanctuary required to build the Hospital, like Aqueducts and Sewer Systems or Temples and Cathedrals in the standard rules.
Corbeau wrote: Tue Jun 09, 2026 8:35 am What I have in my Sim ruleset is that you can build (medieval) Workshop/Manufaktur, but once you build a Factory in the city, the Manufaktur becomes a museum and gives you 2 Gold instead of 2 Production. You may want to think about what would be the effect of the older walls once the new ones are built. Do they make the new ones' upkeep cheaper? Do they add to defence? Are they actually in the way? Are they a tourist attraction?
I'm just figuring the old ones are demolished to make room for the new ones. Modern trenchworks and bunkers and tank traps, Napoleonic star forts, and medieval castle walls are different enough that I don't think it makes sense for them to be upgrades, or force someone through the whole chain of them to build the latest, and I figure they're probably competing for the same real estate.
Dino the Dinosore wrote: Thu Jun 11, 2026 8:36 pm
Also, annoyingly, the tech-tree skein generator for the Research tab apparently doesn't distinguish between positive and negative tech requirements, so City Walls appear on the tech tree under both Masonry and Construction, with no indication that the latter makes it so you can't build them. and likewise for the more advanced walls.
That looks like a bug to me, maybe start a ticket for it.
I haven't been able to figure out how to actually open a ticket. I don't think the freeciv bug tracker likes my browser.
Post Reply