Using SQL based on Era start?

sman1975

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

I'm working on a mod that would add free melee units when a game starts in the Industrial Eras or later. The easiest way to do this is to modify the Era.xml file.

Unfortunately, the units the game normally spawns depends on the highest combat strength unit available at that point of the Tech Tree. Often this isn't the unit you want.

So, it would save a lot of time, hassle, and game instability, if I could grant a free tech to all Civs via SQL. Using LUA is too late in the process - the units have already spawned.

For example, I want to start the game in the Modern Era (WW1). Normally, the game spawns Riflemen units, as they are the best available. I'd prefer to use Great War Infantry, but since no one has Replaceable Parts discovered, this won't happen. Same thing for starting in the Atomic (WW2) Era. I get GWI, but would prefer the standard Infantry unit.

What I need is a SQL-based statement that can somehow sense the game's starting Era, then award an appropriate Tech (e.g. Replaceable Parts, Plastics, etc.).

I've been using code like this, but I need to some how make it conditional, based on start Era:

Code:
INSERT INTO Civilization_FreeTechs (CivilizationType, TechType)
    SELECT Type, 'TECH_REPLACEABLE_PARTS' FROM Civilizations
    WHERE Type <> 'CIVILIZATION_BARBARIAN';


Any hope for me? Am hoping so, since my original approach simply spawned the units via LUA, but when you spawn a lot of units at game start, more often than not, the game unceremoniously CTD's...

EDIT: And P.S. - Yes, I've tried Triggers, but the results would have been comical if they weren't so sad... :cry:
 
You cannot have the database "sense" or "know" what era you are starting in. You can only define the effects to be implemented based on an Era a player chooses to start in. IE, the stuff in the Eras table.

And as far as the lua issue goes, have you tried delaying the spawn of the units until LoadScreenClose or the player founds a first city (assuming you are not pre-placing all cities) or until the first human-player player turn processing (Events.ActivePlayerTurnEnd)?

You can always allow the players to receive X number of crappy units via the game's normal systems in the Database and then remove those crappy units via lua to be replaced with an equal number of better units.
 
Last edited:
Thanks, @LeeS - you always are pretty solid at finding alternatives.

The original design spawned the units at SequenceGameInitComplete, and extra gold/culture/strategic resources during the human player's next turn. The problem is I'm trying to spawn about 15-20 units per civ, focused around the GetStartingPlot() for each civ. About 75% of the time, CTD. I was assuming too many units were spawning near the same point, even with a JumpToNearestValidPlot() thrown in for each one. I even used your Unit Spawn Handler, but with similar crashing results. I also played around with using plots near the starting plot, so that only a few units were spawning at any one given plot, but still no change in results.

What I'm basically trying to do is start a game in a later Era, e.g. the WW2/Atomic Era, coupled with an "End at WW2/Atomic Era" mod, so an entire game can be played in a single Era. The goal is to jump start the process with a lot of units (land, naval, civilians), gold, culture, and strategic resources at the beginning, then cut the cost of units in half - just to make things more interesting. On a small map, things might work more better. But on a Large map (with 6 added AI civs through Advanced Start), almost no chance the game will survive. I'm beginning to wonder if my problem isn't with Advanced Start. I attempted to use Gen. Tso's "Really Advanced Setup" but without any change.

My current plan is to award a portion of the total number of units/culture/gold each turn for perhaps 5 turns at the beginning of the game. Maybe spreading things out will make the game more stable. I do like the idea of using LUA to "convert" the wrong type units to the correct type during SequenceGameInitComplete. That does seem like the simplest solution.
 
I've never used SequenceGameInitComplete. I've always triggered all my "starting" stuff based on using LoadScreenClose and then checking for such things as Game.GetElaspsedTurns() being 1 or greater. Or some similar method that can be used to reliably detect whether the code has already executed when a saved game is reloaded. I'm not exactly sure when SequenceGameInitComplete executes as compared to map generation and starting unit placements is concerned. LoadScreenClose executes when the human player clicks the Start-Journey/Continue-Journey button. This means that everything the game needs to do to start a new game or rebuild a game from a save file has already been completed.

I've never had any trouble using this method regardless of the number of units I've tried to spawn. 20-ish units per player does not seem to me like a high enough number that it ought in and of itself be causing CTD.

Another method I've used with reliable results is triggering off PlayerCityFounded and executing my code only when the player founds their first (original capital) city.
 
Hey, @LeeS - I did get the mod working well, using a combination of database changes and unit replacement functions like you suggested. When it works, it works well...

When I use a "Tiny" map size, it works all the time. The larger map I use, the more likely the chance of CTD. By the time I get to Large or Huge maps, it crashes almost every time.

I tested this with using different mod mix (leaving this new one out, and having cleared cache), and noticed that when using Advanced Setup (to select a later starting Era), I do indeed experience crashes. Perhaps more with this new mod enabled, but still...

Has anyone else experienced crashes when using Advanced Setup? I remember in the past when I used Adv. Setup to select Civs I wanted to play against, it would often crash there, too.

I've validated my install via Steam, so there are no issues there. So, if anyone has any suggestions on how to beat Adv. Setup into shape, I'd appreciate it. I did experiment with the "Really Advanced Setup" but had the same results.


EDIT: So my bottom line is, I am starting to believe there really isn't anything in the mod's design that's causing the crash. It is somehow related to Adv. Setup more than the contents of the new mod?
 
Come to think of it my most common usage of Advanced Setup mode is to pick a scenario map and make setup choices there, and then returning to the normal Modded Game Start menu in order to click on the "Load Scenario" button and start the game from the standard Modded Start menu.
 
Top Bottom