Had a thought r.e. how to handle the 'City Defenders only show up for the first combat in a turn' thing...

By on June 10, 2014 1:02:15 AM from Elemental Forums Elemental Forums


Join Date 03/2009

OK, so the 'SummonCityDefenders' thing apparently only works for the first combat in a given city in a given turn.

I had a thought in the relevant support thread (great, being sidetracked from being sidetracked from being sidetracked) about using BattleAutoCastSpell or something to summon the available defenders each time.

The issue I see with this is that, if the City gives everyone the ability, either directly (some other gamemodifiers are handed down by cities to units) or via a 'give unique resource to everyone, that some spell everyone already has through say Blood_MyRace or whatever, well either EVERYONE can cast their own version of the spell (so say if you had 6 units, you might have up to 6x the normal number of defenders).

This could also have a side effect (don't really see an issue) of allowing units that start a turn in a city, gaining the 'city granted ability or resource' to 'leave' the city, taking some city defenders with them into combat that turn.

This opens the game up to a significant exploit: Throw a token unit into battle with the City for Battle 1, draw off city defenders, attack with the rest of your forces in the next Battle(s).

OK, so I'm going to do some 'If-Then-Else' flowcharting here, and see if the Collective can hit on some way to make this work.

City is Built.  A specialty 'CityDefenseSummon' unit is created, that will (of course) show up in the first combat.  On turn one, this unit casts 'BattleAutoCastSpell' which summons the requisite defenders.  Said unit could stay or die at that point.  I'm thinking this makes a great excuse for a city strongpoint unit, that has to be taken out to 'win' that section of the city/the first battle.

This unit should have 0 strategic move, so it 'has to' remain in the city.  Note that a player might still move him out accidentally, which is a significant issue but for now let's follow this chain of thought.

OK, so the battle commences.

No non-CityDefenders present:

  • Only City defenders show up, so if they lose, city falls.
  • If the defenders win, what happens? Currently, they won't be around for battle #2...

Other units present:

  1. All units eliminated - Attacker wins the city (as expected)
  2. Attacker defeated/escapes:
  • -If 'regular' units are still there, they are available for Battle #2, and could theoretically 'resummon defenders via a spell.
  • If 'the CityDefenseSummoner' unit is present, and has survived, it would be around for the next Battle, and could summon more defenders...
  • If all 'regular' unts are defeated, including the 'CityDefenseSummoner(s)', then the city is wide open for Battle #2.

Sooooo, this is what I'm pondering...

A 'baseline' unit is created, that resides in a city (visible in the strategic window). This unit has 0 or negative Move in strategic.  This unit is the City Marshall/Headquarters

This unit will use 'BattleAutoCastSpell' to summon all other city defenders (Defender's Call)

  • It remains until the end of combat.  If it survives, then it is returned to the City/Map and is available for Battle# 2...
  • It is eventually killed.  If it is 'tough enough, chances are all of the other units will have been killed off by this point, as they were easier targets... hence why I'm leaning to this being a 'Tower with HP' or similar strong point that the Attacker needs to eliminate to win. 

If this unit is essentially a 'strongpoint', it could have say 1 intiative, 0 movement, say 1000 HP, and no attack abilities.  This would mean that other units will have completed say 16 or more actions (assuming the lowest initiative is 16), before this unit is 'asked' to act again.  Of course, it's action would probably be to 'Pass', but perhaps it might have the ability to summon more defenders, heal a unit, or some such.

If the Attackers decide to 'focus' on killing this unit, that'll divert a bunch of attacks away from the other defenders (except perhaps for Area Effect, Sweeping, etc. attacks), giving the other defenders a 'leg up'.  If the attackers kill everyone else off first, well at that point they can finish this unit off, so it shouldn't be TOO tough - lest you endu upspending a whole bunch of rounds basically 'beating down the tower until it is dead', or watch, more or less helplessly while this happens...


Anyways, in order to 'track' the number of city defenders available to it, this 'Strongpoint' unit could have a   'CityDefenseUnitCounter'stat, that tracks the number of units that this unit is able to summon.  It'd also be cool if there was some way to 'track' the number of units this unit has summoned.  Perhaps via the Summoning cap mechanic or some such.  How to do that...

At the start of the battle, BattleAutoCastSpell creates a number of defenders equal to the value of the 'CityDefenseUnitCounter' stat.  Before this happens, the stat is checked against a 'default value', and if the 'CityDefenseUnitCounter' stat is higher than the Default value, it is Set to the default value (see below for why)

Summoned City Defenders each cost 1 'LivingDefenseUnitCounterResource' point each round to maintain.  (The 'Strongpoint' unit is the Caster in this case)

The Caster/Strongpoint unit has alreadya been assigned a 'Max Number' of 'LivingDefenseUnitCounterResource' points each round, equal to the 'maximum number of summons we want to see'.  Note that this value is set when the Stronghold unit was first assigned the 'BattleAutoCastSpell' that summons defenders, and does not change unless an Improvement is built that 'ups' the value.

After earning the new points, a 'comparison check' is made between 'LivingDefenseUnitCounterResource' and the 'Max Value' stat, and if more points are coming in than are going out, this 'adjusts' the 'CityDefenseUnitCounter' stat to a new (lower) value, to account for the lost defenders.   We don't want this value going up or down each time this unit 'acts', hence the need for a comparison attribute.

1 -Set value of 'CityDefenseUnitCounter'to:

  • Calc [['Max Value'] - ['LivingDefenseUnitCounterResource']]
  • Calc2 [[Calc 1] * -1]             (example: max value:6 - LivingMaint:5 (someone died).  Total is 1, so we invert it to -1 for (Calc 3)
  • Calc 3 [['Max Value'] - [Calc2]]   (example: Max Value 6, Calc 2 -1, new value 5)
  • Value [Calc3]

2 -Then, Set value of LivingDefenseUnitCounterResource to:

  • Calc [['Max Value']]
  • Value [Calc]

Step 2 resets this value to 6, which you then subtract the 'summoning maintenance' from on this unit's next action.  Of course, this needs to be 'checked' every round, which means a spell needs to be in effect to make this check.


If this unit survives the combat, when it is called upon at the start of the next battle, the 'CityDefenseUnitCounter' stat will determine the available # of defenders for that next battle.  E.G. if say after the comparison is made the value is '6', then 6 units are available in the next Battle.  If the Value is '3', then only 3 units would be available.


OK, now about that 'CityDefenseUnitCounter' stat being higher check?  I'm thinking that the 'Stronghold' unit will earn a number of 'CityDefenseUnitCounter' stat points each strategic turn.  This adder could reset the value to the 'Maximum', or perhaps regenerate this value at a lower rate.  Since 'calcs' can't be done outside of Spelldefs, this is why you'd need have the check at the start of combat, when the units are first summoned, to set this stat a lower value, if it is higher than the 'maximum number of defenders we want this unit to be able to summon.


Clear as mud, right?


Anyways, the Stronghold unit's summoning abilities will increase as cities grow in size, via a CityModifyAbility stat tied to the new improvement, or perhaps via an 'Unlock spell'.  Note that even if the city ended up 'giving' DefenderCount points to every stationed unit, ONLY the Stronghold unit can actually use them... so by definition this would have to be a 'unit' stat, not a 'global' resource.



In short, it might actually be easier to allow up to 15 units in a city, and then create units with a '0 strategic move' stat.  And then have the appropriate Improvements create new Defender units when they are built (similar to what happens with Elementals and Shards, if you have that particular Ability).  Once they die, you'll have to replace them manually (via building), but at least they will be around for every battle until they die.


OK, that ate up a couple of hours of valuable modding time!    If nothing else, maybe this will spark some other ideas at least...


Locked Post 6 Replies
Search this post
Subscription Options

Reason for Karma (Optional)
Successfully updated karma reason!
June 10, 2014 1:31:49 AM from Elemental Forums Elemental Forums

Oh, and I may or may not have figured out how to bring about the 'Earlier' demise of the Stronghold unit in a battle, once all other units are eliminated...

                <Provides>Subtracts 100 hit points from unit when allies are no longer present</Provides>

I'd be curious to see if this would actually work.  Guess I'll need to to add it to some code and take it for a 'Test Drive'...  SOMETHING along these lines should work.  Or you could draw/earn HP from Allies each turn to offset the penalty, e.g. similar to the spell that costs an ally 3 HP and earns you 12, but in this case it costs allies 0 HP and earns you 100, to offset the -100 HP you suffer each combat round/turn.

Reason for Karma (Optional)
Successfully updated karma reason!
June 10, 2014 6:31:49 AM from Elemental Forums Elemental Forums

So I haven't tested the above code from the last post yet, but I had a thought.

Using the Immobilize tag to 'freeze' a unit in place, then doing the LimitedUnitCap to make the unit 'automatically appear' on the map once the City Hub was built.  I repurposed A Guardian Statue for the job (MarshallGuardian), and made an ability with Immobilize (duration -1)

Sooo, this is what happened.  Sov built City Hub.  Sov AND Guardian are placed next to the City Hub.  MarshallGuardian is immobile, so I can't move him into a city.

So I build an improvement 'under' him, well he doesn't get absorbed into the City.  I move another unit into his square (which does the 'autojoin' army thing, both units are moved into the city.

So I tried attaching the Guardian to a Tower Of Dominion.  Tower gets built, guardian appears in the Tower square OUTSIDE of the city.  Again, I need to send another unit into the Guardian's square before he 'moves' into the city.


Well it almost worked.... the AI won't know how, or that it needs, to 'move' the MarshallGuardian into the city using another unit.  So close...

Another option might be to make the Guardian a Champion, apply a huge minus to hit points when he is summoned via LimitedUnitCap, but since he isn't INSIDE the city he doesn't get a bonus applied to some stat that is used to 'prevent' the application of the -hp thing.  The Guardian dies, and then moves inside the city to 'recuperate'.  Yeah, this sounds clunky too...


If there was a way to automatically add the Guardian to the training cue, with a ridiculously low build cost so he's built immediately, that might work.  But the only way I could see this working is to 1)Make him part of all Unit lists.  2)Negative Production cost for some trait he has 3)Bumping up the AI priority for this unit to some huge amount, so the AI hopefully 'trains' him at the first opportunity.  Building a Guardian takes some special resource that the city generates once when it is built (not a per turn thing), and that gets deducted/used when the Guardian is built.

*sigh*.  Well, closer anyways!

Hmm, now I'm wondering if you could get TransportUnit to automatically transport him to the nearest city (the one he's next to)...


Reason for Karma (Optional)
Successfully updated karma reason!
June 10, 2014 8:50:15 AM from Elemental Forums Elemental Forums

Well if nothing else, you can now make a really useful "stationed in city" trait for Commanders that let's them summon additional defenders during a city siege.  

"Send for reinforcements" aka "The Beacon!! The beacon is lit! Gondor calls for aid!" (love that scene!)  could be a high level perk down the tree.

Could you summon the reinforcements behind the attacking enemies to reflect an army riding to break the siege?

"Look to my coming on the first light of the fifth day, at dawn; look to the east." 
(Gandalf. LOTR The Two Towers) (sorry, 'nother nerdgasm   )

That could be nasty fun!

And if you can't bend the .xml to your will we can just pretend that the city-raised levies break and run after an initial attack if there are no "regulars" there to stiffen their spines...


Thanks for the time you put into the game to make it better! 

Reason for Karma (Optional)
Successfully updated karma reason!
June 10, 2014 9:18:30 AM from Elemental Forums Elemental Forums

Unfortunately I have found a summon using BattleAutoCastSpell to be a bit flakey.  A while back when I played with it... the spell gets cast fine, and if you choose a valid target (tile) then it works ok.  But if you accidentally (or intentionally) click certain invalid targets... like an occupied tile or something, it would hang.

Not a showstopper, but I have avoided using them because of that.  Mind you it might work fine now, this was ages ago, maybe even FE.  Just mentioning it because if you were to go try this stuff that'd be the first thing I'd check out.

Reason for Karma (Optional)
Successfully updated karma reason!
June 10, 2014 2:11:48 PM from Elemental Forums Elemental Forums

This might be a way to create defenses for outpost.  Build outpost, Outpost Marshall is assigned using LimitedUnitCap.  Said Outpost Marshall is immobilized right out of the gate, and has a Summon Defenders spell(s).

It always annoyed me that outposts were pretty much unprotected, and there weren't enough assets to go around to protect them due to the low unit counts.  This could be a way to change that equation.

Especially if there was a 'Defender Pool' stat or something (similar to how Mana is currently implemented) that a player could choose to use or not use as he saw fit.  I.E. the 'shifting defense assets' around idea I mentioned in the other thread under LH Support.

I see that the AI is using summons a fair amount under 1.6, so this might actually help.  Ahhh, sidetracking!


Edit: Yep, this would work for outposts.  Although you might want to choose a smaller unit than a Guardian Statue, or resize him when you 'repurpose' the code.  He's bigger than the outpost, so you can't see the outpost underneath him!

The good news is that you can click him twice to get to the outpost menu/outpost that is underneath him

Reason for Karma (Optional)
Successfully updated karma reason!
June 17, 2014 5:35:42 PM from Elemental Forums Elemental Forums

OK, a random update here.

I had my 'autostation a guardian statue when a Monument is built' playtest thingie running in the background while I was testing some other stuff.

A couple of things happened...


One, there was this immobile Guardian Statue in the middle of nowhere/placed about 2 squares away from the monument that spawned it.  I don't know if the AI was able to move it on the first turn or exactly what happened, but he was out of position.

Secondly, one was also stationed next to a city.  Not sure what happened there either.

Thirdly, the AI decided that these Guardian Statues needed defending, so some units were stacked with the immobile guardians.  This left their cities a little less defended, and allowed me to 'cap' one Champion before I subsequently took the nearby city, with the now hobbled Champion (whom I picked off with one ranged attack).


Soooo, the short form is the 'autobuild an immobile unit' thing isn't working correctly, as the units are appearing in places other than where they are supposed to be, and are tying up other units in the process, which are being 'tasked' to defend these units.

It was worth a shot anyways!

Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #101114  walnut1   Server Load Time: 00:00:00.0000344   Page Render Time: