Resource icon

C3X: EXE Mod including Bug Fixes, Stack Bombard, and Much More Release 17C

I had to look up what Lua scripting is and at best I can only understand it superficially.

Flintlock, could you give an example of what you could do with it?
 
I had to look up what Lua scripting is and at best I can only understand it superficially.

Flintlock, could you give an example of what you could do with it?
Among many other applications, it opens up the sort of complex scripted events available in Civ2 and Civ4 (and beyond). TOTPP adds it to Civ2, and modders can now bypass hardcoded mechanics to directly manipulate combat in the sort of detail seen in Civ4. It has single-handedly revitalized the modding scene for an almost three-decades-old game, and I can't even begin to imagine what Civ3 modders could do with it.

It would also likely simplify implementation of existing and future C3X features, and make their behaviour more malleable by modders.
 
It's not as crazy as it sounds! Getting Lua running from within the Civ 3 process is pretty straight forward, given what C3X can already do. It's not much more difficult than integrating Lua into any C program. (Though it is a bit more difficult since the C source isn't compiled the standard way, in particular there's no linking phase.) The hard part is creating an interface between Lua and the Civ 3 game data & methods. I've been working on automatically generating that interface based on the C interface I already have, but there are a lot of issues to deal with. E.g. methods don't have convenient names, some methods are in vtables, C has no boolean type, ... I haven't even though about memory management yet.


About a year ago I did a little proof of concept of Lua integration, just enough to reimplement the disorder warning in Lua. Here's the code just for the warning:
Code:
local civ3 = require("civ3")

function CheckHappinessAtEndOfTurn()
  local numUnhappyCities, firstUnhappyCity = 0, nil
  for city in civ3.mainScreenForm:GetController():Cities() do
    city:RecomputeHappiness()
    local numHappy, numUnhappy = 0, 0
    for citizen in city:Citizens() do
      if citizen.mood == civ3.CitizenMood.Happy then
        numHappy = numHappy + 1
      end
      if citizen.mood == civ3.CitizenMood.Unhappy then
        numUnhappy = numUnhappy + 1
      end
    end
    if numUnhappy > numHappy then
      numUnhappyCities = numUnhappyCities + 1
      if firstUnhappyCity == nil then firstUnhappyCity = city end
    end
  end

  if firstUnhappyCity ~= nil then
    local response
    if numUnhappyCities > 1 then
      response = civ3.ShowPopup(civ3.GetC3XScriptPath(), "C3X_DISORDER_WARNING_MULTIPLE", firstUnhappyCity:GetName(), numUnhappyCities)
    else
      response = civ3.ShowPopup(civ3.GetC3XScriptPath(), "C3X_DISORDER_WARNING_ONE", firstUnhappyCity:GetName())
    end

    if response == 2 then -- zoom to city
      civ3.mainScreenForm.turnEndFlag = true
      firstUnhappyCity:ZoomTo()
    elseif response == 1 then -- just cancel turn end
      civ3.mainScreenForm.turnEndFlag = true
    -- else do nothing, let turn end
    end
  end
end
I think this is pretty simple & clean, but underneath is a bunch of interface logic that I had to write by hand. The especially laborious parts were the Lua iterators (GetController():Cities() & city:Citizens()) and civ3.ShowPopup. The rest is a very direct mapping to the base game logic, for example city:RecomputeHappiness() just calls a base game method.


I had to look up what Lua scripting is and at best I can only understand it superficially.
Flintlock, could you give an example of what you could do with it?
What got me interested again most recently in integrating Lua is the possibility of custom map scripts. I was playing Civ 4, trying out the Totestra map script for the first time, and I was struck by how much a different kind of map can freshen the experience. Custom map scripts for Civ 3 would be best done through Lua so that way the wider community could contribute them. Technically it would also be possible using C, which all of C3X is already written in, but there's a much higher barrier to entry there.

Other uses for Lua scripting include: (1) A more powerful way to manipulate the AI's production choices. Right now it's possible with perfuming, which is a very blunt tool. I could try to extend perfuming, but the ultimate extension is letting modders write Lua scripts to guide the AI's choices based on whatever conditions they want. (2) Similarly, someone suggested adding city build lists for the human player's convenience. Those would work like a more powerful version of the production queue. Even more powerful would be a Lua script. (3) Like Thorvald mentioned, it's more pleasant to write in Lua than C. I've also been exploring the idea of adding a trade overview screen (kind of like the foreign advisor in Civ 4) and I'd really rather write that in Lua.
 
Adding Lua would be the "Mother of all Miracles" for this fantastic mod. :hatsoff:

The Test Of Time Patch Project added lua to Civ 2 ToT, but there it could be based on an existing Civ 2 events programming. The great Civ 2 modders achieved many astonishing features by using lua besides massively influencing the terrain on the map. Supply of units, political favor, units with new features, rebellions are only some of those features.

The ideal case would be, if Civ 3 mods could use the existing helps for using Lua with ToTPP, especially the templates by Prof. Garfield, and can receive help by the experienced Civ 2 ToTPP modders.
 
These new features look wonderful! Does the Hotseat human-player view option apply to Play-by-Email games as well?
 
These new features look wonderful! Does the Hotseat human-player view option apply to Play-by-Email games as well?
Thanks! Right now shared visibility only works in hotseat but I don't see any reason it couldn't be applied to PBEM as well in the future.
 
Fix potential trade net issue in games with a very large number of tiles and resource generating buildings -- I'm not sure if this fixes the "trade net collapse" issue that was reported, but it fixes a bug that might have caused that. The bug would have prevented resource networks from being calculated at all when the sum of map tiles and resource generating buildings equaled 65536 exactly.
I might be the first one who actually test it. I had few attempts with Wars in Medditerrean mod before. It was one of those mods which attracted my attention to modding and this forum more than 10yrs ago. In fact I was not able finish playing this mod because during the turn change the game was slowing down untill completley freezed. I played again this weekend when I read what you added to your recent release and it looks like you finally fixed this horrible issuse which made lots of old mods with large maps unplayable. I haven't finish playing yet but the game is really advanced, 60-70% of map is conquered and time for turn change no more that 1-2 minutes. Without your addon I had to wait 15-20min for a turn to change untill game freeze to death. First time I made a progress in this mod much much bigger than ever before. And it looks I am going to finish it.
Fantastic work you're doing here Flintlock! I will say no more :)
 
Last edited:
CivII had scripted events. Is anything like that possible? Am thinking of large timescale historical maps where the events load some civilizations at later times. For example, a bronze age scenario might start the game with Sumeria in 3500BC, allowing the Sumerians to build a number of cities and then later use an event to add Celts in 1000BC in the European portion of the map.
 
Recently, @Coronel_Civ3 posted the following question, which I thought worthwhile to repost here:

"The Civilization 3 Conquests v 1.22 [...] "ARMY" option cannot be adjusted in naval unit actions or in air units. For this reason, the system does not allow you to complete the create army operation, however you can enable the option to load both ground and naval units and certainly air units and select the ARMY option in functions or skill characteristics.[...] But could this option be unlocked for the naval and air forces? From a special program or an editor that I know there are hidden functions around here, perhaps that option could be added."
 
Recently, @Coronel_Civ3 posted the following question, which I thought worthwhile to repost here:

"The Civilization 3 Conquests v 1.22 [...] "ARMY" option cannot be adjusted in naval unit actions or in air units. For this reason, the system does not allow you to complete the create army operation, however you can enable the option to load both ground and naval units and certainly air units and select the ARMY option in functions or skill characteristics.[...] But could this option be unlocked for the naval and air forces? From a special program or an editor that I know there are hidden functions around here, perhaps that option could be added."
Incredible! fantastic!

Too bad it's not in Spanish! I'll try to see if I can translate at least the TEXT documents.

Thank you so much!.
 
Incredible! fantastic!

Too bad it's not in Spanish! I'll try to see if I can translate at least the TEXT documents.

Thank you so much!.
My new friend, the purpose of this thread is to ask/see whatever Arcane Magic Flintlock can pull off next :popcorn:
 
I haven't finish playing yet but the game is really advanced, 60-70% of map is conquered and time for turn change no more that 1-2 minutes. Without your addon I had to wait 15-20min for a turn to change untill game freeze to death. First time I made a progress in this mod much much bigger than ever before. And it looks I am going to finish it.
Fantastic work you're doing here Flintlock! I will say no more :)
Thank you! That must be the improvement loop optimization at work. Down to 1-2 minutes from 15-20 is pretty amazing, the most I've seen in my testing is a turn time reduction of about 70%. In general the optimization should be more pronounced for mods that add many city improvements and those that limit how many cities can trade over water (because that shifts the bottleneck from actually computing the trade routes to checking whether cities can trade). There's even more I could do to speed up trade net calculations and a lot more I could say about it. I was planning to post a thread all about that, maybe someday...
CivII had scripted events. Is anything like that possible? Am thinking of large timescale historical maps where the events load some civilizations at later times. For example, a bronze age scenario might start the game with Sumeria in 3500BC, allowing the Sumerians to build a number of cities and then later use an event to add Celts in 1000BC in the European portion of the map.
Scripted events would surely be possible once Lua is integrated into the program, which would be a lot of work but I don't see any real technical limitations there. About spawning in a player in the middle of a game, that might be awkward due to engine limitations. Or maybe not, I've never tried it. Even if it's not possible you could keep a settler for that player on the edge of the map then move it into position at the appropriate date.
"The Civilization 3 Conquests v 1.22 [...] "ARMY" option cannot be adjusted in naval unit actions or in air units. For this reason, the system does not allow you to complete the create army operation, however you can enable the option to load both ground and naval units and certainly air units and select the ARMY option in functions or skill characteristics.
I wonder where the actual limitation is here. Looking at the Unit::can_load function, which determines if one unit can be loaded into another, the condition for armies is only that the two units must have matching classes, not that the passenger must be a land unit. So at least in that way the developers left open the possibility for naval armies. One issue I can think of already with air armies is that air combat involves instant kills, in particular when a ground anti-air unit intercepts a plane, so either that would need to be changed or air armies really wouldn't be desirable.
 
I wonder where the actual limitation is here. Looking at the Unit::can_load function, which determines if one unit can be loaded into another, the condition for armies is only that the two units must have matching classes, not that the passenger must be a land unit. So at least in that way the developers left open the possibility for naval armies. One issue I can think of already with air armies is that air combat involves instant kills, in particular when a ground anti-air unit intercepts a plane, so either that would need to be changed or air armies really wouldn't be desirable.
I don't think that Air Armies are necessarily desirable. From my POV, the main issue I have with Armies, in general, of any sort is that Units of any sort can join an Army, whereas some ratio of, e.g., for Land Armies might be 2:2:1, Att : Def : Arty, and might be great.

Regardless, "Naval Armies" with any mix of units might make Naval Play by the A.I. more interesting.
 
Thank you! That must be the improvement loop optimization at work. Down to 1-2 minutes from 15-20 is pretty amazing, the most I've seen in my testing is a turn time reduction of about 70%. In general the optimization should be more pronounced for mods that add many city improvements and those that limit how many cities can trade over water (because that shifts the bottleneck from actually computing the trade routes to checking whether cities can trade). There's even more I could do to speed up trade net calculations and a lot more I could say about it. I was planning to post a thread all about that, maybe someday...

Scripted events would surely be possible once Lua is integrated into the program, which would be a lot of work but I don't see any real technical limitations there. About spawning in a player in the middle of a game, that might be awkward due to engine limitations. Or maybe not, I've never tried it. Even if it's not possible you could keep a settler for that player on the edge of the map then move it into position at the appropriate date.

I wonder where the actual limitation is here. Looking at the Unit::can_load function, which determines if one unit can be loaded into another, the condition for armies is only that the two units must have matching classes, not that the passenger must be a land unit. So at least in that way the developers left open the possibility for naval armies. One issue I can think of already with air armies is that air combat involves instant kills, in particular when a ground anti-air unit intercepts a plane, so either that would need to be changed or air armies really wouldn't be desirable.
Sorry but I may be a bit clumsy...

As a result of reading you, I have managed to configure an army that is a naval unit and it works... except that it walks on water. The army unit folders are separated by era, so if I can create naval armies with different sounds, in fact I call the army in my scenario a land army and the leader's sound is the famous "Ha o ha" I have replaced it for the original sound of the catapult attack from Civilization II.

So now that it works I can create duplicates of the army unit folder and create new armies but I have a problem:

Following your instructions on the units, I have tried with two ships to enable the load as you say but it does not let me in the game once on top of the army and already at sea to load it...

Where is my mistake?

I already have the C3X mod installed.
 
Your Naval army -- and specifically the boats you want to put in it -- may need to be in port in order to activate the "Load" action for the boats.
 
Your Naval army -- and specifically the boats you want to put in it -- may need to be in port in order to activate the "Load" action for the boats.
I have tried it but I can't get it to work in a coastal city with the Port.

Thanks for the idea, I will wait for more ideas and continue investigating.
 
I think I've found something which may be worth considering - when a wonder puts a improvements with a negative pollution in a city, it seems to not actually counterract the pollution caused by buildings, unlike if it is built normally.

In the screenshot, the Blacksmith produces +1 pollution, and the Gymnasium takes away -2 pollution, however, this Gymnasium (which is provided for free by a wonder) doesn't seem to be removing the pollution at all.
 

Attachments

  • PollutionWonderImprovements.png
    PollutionWonderImprovements.png
    470 KB · Views: 31
Top Bottom