Now, forts can attack nearby enemy units

Joined
Feb 6, 2006
Messages
796
Maybe, something similar has already be done, but I post it anyway.
I've been asking for such a feature for ages, maybe in the official release, but forts are still of little use, during wars. So, here comes my modification.

When an enemy civ (that you are at war with) sends his units close to one of your forts, and there are archer or siege units inside that fort, then your units have the chance to hit the enemy, and slightly damage him.
A random number of enemy units is hit, and the damage depends on the strength ratio between your attacker and each of the hit units.

At the moment, only ONE fort per turn is affected. If your enemy sends his units close to more than one forts of yours, the other forts don't attack.
Maybe I'll work on it in the next days.
 

Attachments

Not so difficult!
I use a "weight -1" event (which always triggers as soon as possible), which locates a fort in your territory, and picks a rival civ you are at war with.
Then, the event calls a python script, and here is where I make it all happens!
I use the information the event trigger gives me, and locate all the enemy units near the fort, and damage some of them.
 
I tried this mod out and it didn't work. I kept getting an event text box with nothing but a green dot and when I clicked on it I ended up getting a bunch of gold. But I never got any message that an enemy unit took any damage.
 
Yeah sure. I miss having ZOC in the game in some form. Any reason though why you need to have that event box come up? It seems to me that simply having messages should be good enough.
 
Add the attached py file to the Assets\Python\EntryPoints\ folder.

Then, add this code to the CvEventManager.py (it is to trigger the newly added file).
Add this 'import' at the beginning:
import MyModSpecials
In the onBeginPlayerTurn method, at the end of the method:
MyModSpecials.triggerFortAttack(iPlayer)

That's it. Each turn, the code will be execute per each player. Each fort wil have a 50% chance to bombard close enemies (there must be siege weapons inside, to bombard).

You can easily disable the feature by modifying the file MyModSpecials.
Where you read 'TO DISABLE THE FEATURE, uncomment the return', well.... do as you read!! :)
 

Attachments

Of course, you also need to add this in one of the xml text files!

Code:
	<TEXT>
		<Tag>TXT_KEY_FEAT_FORT_HAS_ATTACKED</Tag>
		<English>A %s fort has attacked some enemy units.</English>
		<French>A %s fort has attacked some enemy units.</French>
		<German>A %s fort has attacked some enemy units.</German>
		<Italian>Un forte %s ha attaccato e danneggiato alcune unit&#224; nemiche.</Italian>
		<Spanish>A %s fort has attacked some enemy units.</Spanish>
	</TEXT>
 
I'm just getting an error message, "Error in the method MyModSpecials.triggerFortAttack" and nothing's happening. Thanks anyway.
 
This reminds me of Opportunity Fire from Dale's Combat Mod where Siege Weapons automatically attack adjacent enemy units.

Suggestion: allow forts to attack enemy units even without any units in it. This way forts are a lot more useful IMHO and they have a ZoC.
Don't know of this is possible in Python only but I very much like the idea.

Anyway, thanks for your effort :goodjob:
 
It's possible, allright, and if you have a minimum of experience with Python, is quite easy.
Where I loop every plot and check if there are units inside, you have to remove this condition. In addition (since the inflicted damage depends on the attacker strength), you also have either to set a default attacker strength, or to modify the damage formula.

If you find the way to make the AI move its units considering those forts, well, let me know!!
 
Thanks VK for your quick reply but I am a Python-noob.
Would it also be possible to adjust the strength of the fort based on techs?

I mean something like this:

default: strength = 4
with engineering: strength = 8
with rifling: strength = 12
with artillery: strength = 16
 
mmmm, let me have a look....
You should comment the code from
# count the attackers in the fort....
to
(unit,iter) = pAttacker.nextUnit
by adding a # at the beginning of each line.

Then, you add the manual setting of the variables.
Write a couple of lines, aligning them to the other existing lines like unitsToAttack = [] (be careful to that: add a number of tabs at the beginning, so each line always starts at the same column).
The variables you need are:
iAttackerAverageStrength = 4
iNumAttackers = 1
Just copy-and-paste them (and align them!).

This will make it work as a single strength 4 siege unit was inside the fort (a trebuchet).
Since you are not familiar with Python, start trying if that works.
 
mmmm, let me have a look....
You should comment the code from
# count the attackers in the fort....
to
(unit,iter) = pAttacker.nextUnit
by adding a # at the beginning of each line.

Then, you add the manual setting of the variables.
Write a couple of lines, aligning them to the other existing lines like unitsToAttack = [] (be careful to that: add a number of tabs at the beginning, so each line always starts at the same column).
The variables you need are:
iAttackerAverageStrength = 4
iNumAttackers = 1
Just copy-and-paste them (and align them!).

This will make it work as a single strength 4 siege unit was inside the fort (a trebuchet).
Since you are not familiar with Python, start trying if that works.

Thanks VK, but I think it's a bit more complicated.
Forts should only attack if there's no enemy unit in it, so that should be checked too. It makes no sense if a fort attacks enemy units if it's occupied by enemy troops.
Also it would be nice to make the strength of the fort depend on researched techs. I suppose a check of these techs should be made. See my previous post.
 
I like this concept very much :). I never build forts close to my city if I can build a decent improvement instead, but maybe with this modcomp that would change ^^. So let me get this straight, the new version gives all forts a 50% chance to attack each, and not just one per turn, right?
 
to Arian: I was only trying to give you some hints of how to modify this script. This was not the final solution, of course. However, about checking if enemy troops are inside.... it's a nice question. The fort is in your land, so it might be sensible to attack anyway.... or, instead, the enemies could have sabotaged it!

to Chiyu: the post of Oct 11 gives EACH fort a 50% chance to attack, so it's possible that a given turn all your forts attack.
I repeat, the feature seems to work properly, but the AI is still confused and doesn't know how to behave, so his troops remain fortified outside the fort, being bombarded.
 
to Arian: I was only trying to give you some hints of how to modify this script. This was not the final solution, of course. However, about checking if enemy troops are inside.... it's a nice question. The fort is in your land, so it might be sensible to attack anyway.... or, instead, the enemies could have sabotaged it!

If the fort is in my land and there are enemy troops inside it shouldn't attack other enemy troops. It would be 'friendly fire'.
You can think of forts in your own land which have no troops inside are manned by your own people which would automatically attack any enemy troops. Hopes this clears it a bit :)
 
I've found the possible cause of the error Willem could be experiencing.
The file still references a python I've added, MyModUtils, but it's quite useless (apart of reporting possible errors).
The error could be caused by this not-found file.
You can remove those two occurrences of MyModUtils. Instead of
MyModUtils.SendDebugMessage("Errore nel metodo MyModSpecials.triggerFortAttack")
just write "return".
 
Back
Top Bottom