Fun things to do when the turn ends

Skajaquada

Crazy Engineer
Joined
Mar 4, 2007
Messages
134
I've been wanting to make a morale- and routing-system for some time but for the last several months I've been really busy working with and importing models.

Going through the unit-functions with all things like "is great general near", "get terrain", "get hit points" really seem to beg for a morale-system. I was thinking quite simply at the end of the turn, or the beginning, we loop through all units and check things like adjacent enemies, hit-points etc. then determine if the unit should flea.

The first thought I had against the idea is the way Civ 5 works you kind of want units with low hit-points to run away and heal up. I was then thinking is it possible to lock a unit in a routed state? I think so, it's just some variable for how many turns they should be away. Then every turn we check "if is still routed", then give it a hefty negative defence-modifier and maybe only make it run a single hex every turn. The question is just if this would drag the performance down significantly? Is there already a unit-loop I could put my code in?

I could even have a fear-table for all units with lots of things adding to this like low hit-points, adjacent much more powerful enemies, even terrain like jungles. I'm thinking I'll just have a table in LUA like this:

local g_unit_fear_points = {}

Then if I can't bake it into an existing loop I'll just set it like this for built units:

g_unit_fear_points[tostring( unitID )] = 0;

Then add it up differently for different units. I could for example use the RunCombatSim to add more fear-points if it's a pretty scary enemy.

Then of course comes the route-state. I was thinking at the begining of a turn I could check that fear-value, if it's too high the unit becomes routed. It'll then move around, if it's way too performance-heavy to make the unit run away from a enemy it could just be random.

Any thoughts? Anyone seen anything like this in a mod or DLC?

I was also thinking it could be fun doing other stuff, perhaps dialogues could appear like those in BtS giving you different choices. The programming challenge there might be more making some tables and functions that handling those easy.

Another thing that struck me was ripping off Dune (and not just Total War) and make desert-hexes and tundra really dangerous to end the turn on. Would that have any chance of working game-play-wise? I really don't like gimmicks in games though if the morale-system could be worked into something really complex and meaningful I think it could be fun. Then I was thinking morale-promotions and whatnot could reduce the fear to make it like feel part of the game.
 
@ Skajaquada
A unit cycle loop wouldn't affect time all that much. There are quite a few mods out there that cycle through all the tiles at the beginning of each turn i.e. the forest growth mod yet that doesn't slow down the game that much if at all.
 
I think the biggest problem is what I've read that there are no events for starting any civilization-turn, just the player-turn. I assume the tree-growth mod only grow trees on the player's turn? Though that's probably not as important when you're growing trees as when you're routing units. Then this would just be for yourself, though the AI is already limited this might have a positive side-effect of levelling the playing field in another way than giving the AI more gold and production.

Is there any way to deal with the computer-player's turn? I've noticed the unit-built event at-least fires every time. I suppose the on-attack does the same. Then maybe I can do this on a unit-basis and not turn-basis? The problem is then that we can't really "lock" units as removing their moves after an attack does nothing. Perhaps it could be down-sized to an attack-modifier? Like for every attack a comparison is made with like a "fear spread value" and "fear-resistance value". If a fear-value is too high the unit is routed and can basically not do any damage. The fleeing part will then be left to the player (possibly only player-units flee, which would also balance it for the AI-player).

The problem then is just what will lower the fear-value. I was thinking proximity perhaps to cities and Great General could lower it every turn or so, perhaps even other units. Perhaps it can simply be so that every-time a unit kills a unit it's fear-resistance increases and total fear is lowered. Then every time it survives combat without killing something fear is simply increased. Another method may be having some turn-counter for every unit that's simply increased on the player's turn, but when an unit attack it checked "if fear greater than 50 and turn since last attack less than 10".
 
I know this is an old thread, but the GameEvents.PlayerDoTurn(iPlayer) event fires for all players on the map, even the City States.
The argument iPlayer maps to an index in the Players table, so you could do

Code:
function TurnListener(iPlayer)
     local pPlayer = Players[iPlayer];
     print(pPlayer:GetName());
end
This prints every players' name at the start of their turn.


Or, a 'once per turn' implementation:

Code:
local lastTurn;

function TurnListener(iPlayer)
     local turn = Game:GetGameTurn();
     if not lastTurn then
          lastTurn = turn;
     end
     if lastTurn < turn then
          -- do stuff
          lastTurn = turn;
     end
end
This implementation ensures that your listener gets notified only once per game turn, and could even be tuned to only fire once per game turn on a specific players' turn.

Adding a listener:
Code:
GameEvents.PlayerDoTurn.Add(TurnListener);

The PlayerDoTurn is fairly stable, it does not fire on turn 0 though, but i have not notcied that it only fires for the human player on turn 1, as some suggest.
 
I know this is an old thread, but the GameEvents.PlayerDoTurn(iPlayer) event fires for all players on the map, even the City States.

Except for turn 0, this is correct. Unfortunately, there are no similar GameEvents analogues to the end-of-turn, start-of-combat and end-of-combat serial events. So there's a bit of a limitation on what you can shift to those GameEvent functions. But yes, I've done quite a bit with that start-of-turn event in my own mod.
 
True, i forgot to mention that, thanks. It's like the AI is not a "player" until turn 1.

No one is actually a player until they found their first city, according to the game engine; since the player takes his turns before the AIs, it'd make sense that start-of-turn events wouldn't kick in until the player's second turn. I mean, you use the non-GameEvent start of turn event, and you can loop over players on turn 0 and do some things with them, but until someone founds their first city they can't have any Projects or Techs. My Mythology mod uses a series of behind-the-scenes Projects, awarded to each civ on the first turn, to provide each player with a set of pantheon-specific units. It was crashing when I tried awarding a Project to the players before they'd settled their first cities, but once a city was in place it worked just fine.

There are a lot of little bits like this; the game's not really structured to handle lots of changes to that first turn or two, but once you get past that the start-of-turn GameEvent can be used for all kinds of fun things. But as I said before, we really need GameEvent analogues of a lot of the other serial events, like the start-of-combat and end-of-combat CombatSim events to avoid the conflicts with Strategic View or Quick Combat.
 
can players get policies before settled?
i'd like to mod in nomad civs, capable of getting policies and techs. is it possible?
can i say give them a city and then remove it to 'initiate' them as players? (with 'require complete kills' option for instance, as otherwise they'd be killed i assume).
 
No one is actually a player until they found their first city, according to the game engine;

Is this the logic behind GameEvents.PlayerDoTurn(iPlayer)? I could use that logic, if I knew for sure that this doesn't fire before settling and it does fire the turn after settling. (But I'm not sure if that is what you are implying here.)
 
Back
Top Bottom