Making Improvements Obsolete?

sman1975

Emperor
Joined
Aug 27, 2016
Messages
1,376
Location
Dallas, TX
Hello,

I'm working on a mod that adds a few improvements throughout the tech tree, but it would be nice if I could remove some of the earlier ones when their later (and better stats/more capable) versions become available.

Since the Improvements table doesn't have an ObsoleteTech entry and I can't find an 'OnCanBuildImprovement' - like game.event, I was wondering is anyone could speculate on a way to remove obsolete improvements?

Thanks!
 
Do you mean an improved version of an improvement? If yes. would not all earlier improvements be updated?
 
It could be an improved version of the earlier improvement, but from what I've seen so far, is if I use different models based on Tech but still using the same "IMPROVEMENT_ ... " type, the latter version would only change the looks of the improvement, not the stats.

For example, say I want to add an "Improved Fort" - which looks more modern than the original in-game Fort, and also gives a defensive bonus of 75% (vice 50% for the Fort).

When the Improved Fort becomes available, it makes no sense to have the original Fort in the game. I'd like to forbid the construction of any more original Forts.

The mod I'm testing all this with has 3 different versions of the same improvement type (early, main, and late version), each arriving at different Eras. Once a player reaches the prereq tech for the 2nd or 3rd version, I'd like to remove the earlier versions from the game - mostly because the Worker's "unit action/builds" panel is getting quite full.


I should also say that I'm trying to avoid replacing the UnitPanel UI if possible. It just breaks compatibility with too many mods when I do.
 
If you're using a custom DLL you have PlayerCanBuild and PlotCanImprove. If not, the only way I can think of doing it is to associate the three forts with un-researchable techs, and then use the tech event to grant and remove those techs as the ones you want to associate the forts with are researched.
 
Thanks, @whoward69! Again, unfortunately, I'm not using the DLL, so I'm forced to do things the hard way...

As I understand you, does the TeamSetHasTech event fire when a team discovers a tech?

If so, then I think i would need to build a solution that does something like this:

10. Create a "dummy tech" as a prereq to each (well at least the first 2) improvements. (e.g. TECH_GUNPOWDER_DUMMY)
20. Listen for the TeamSetHasTech event and check if a player just finished researching the in-game prereq tech. (TECH_GUNPOWDER)
30. Award the corresponding dummy tech to the player just getting the normal tech.
40. Keep listening to TeamSetHasTech - when the "obsolete tech" for that improvement is earned, then remove the dummy tech from the player.

I saw a different post of yours that uses a stub like this:
Code:
GameEvents.TeamSetHasTech.Add(function(iTeam, iTech, bAdopted) end)

Sorry, but I didn't see this while googling earlier.

I like this approach primarily because I don't have to touch UnitPanel, but it also leaves all the existing improvements in their original (now "cute," and archaic) versions.
 
Quick update - using the approach described above, everything works perfectly. Except...

I'm getting the "Tech Discovered" popup for the dummy techs and when you look at the upper left side of the screen, the Tech Tree area where you select the new tech to research, it shows the dummy tech as the last tech researched. Looks shabby.

Here is the simplified version of the function:
Code:
GameEvents.TeamSetHasTech.Add(function(iTeam, iTech, bAdopted)
    local pTeam = Teams[iTeam]
    local iPlayer = Game.GetActivePlayer()
    local pPlayer = Players[iPlayer]
    if iTech == GameInfoTypes.TECH_GUNPOWDER then      
        pTeam:SetHasTech(GameInfoTypes.TECH_WAW_GUNPOWDER_DUMMY, true, iPlayer, false, false)      
    end
end)

The last "false" in the SetHasTech method is the boolean for 'bAnnounce' - which I thought would prevent the main popup, but it doesn't seem to work.

Was wondering that since the dummy techs are awarded using the SetHasTech method - but from within the SetHasTech event - is there some kind of recursion problem? Or is there another problem in the structure?
 
The Disable column may fix some of the issues.

And to avoid the popup, use pTeam:GetTeamTechs():SetHasTech(iTech, true)
 
The new syntax stopped the popup, which is about 99.2% of the problem I was having. Am still seeing this after the popup is dismissed:

upload_2018-12-23_10-11-3.png

I think I'll simply change the name of the dummy techs to match the real techs and call it a day...


Thanks, @WHoward! - you always give the best advice!
 

Attachments

  • upload_2018-12-23_10-10-22.png
    upload_2018-12-23_10-10-22.png
    3.7 MB · Views: 188
You could do

On Tech A researched
Remove tech A
Grant dummy tech A'
Grant tech A

Which would fix the display
 
Back
Top Bottom