Vincentz Rangestrike

vincentz

Programmer
Joined
Feb 4, 2009
Messages
3,614
Location
Denmark
Download link here

This mod adds Rangestrikes (Ranged Combat) to sieges and ships from Frigate and forward.
The sieges are no longer able to perform direct combat, only rangestrikes. The ships can do both.
AI will use it for Land2Land, Land2Sea, Sea2Land, Continent2Continent and sometimes Sea2Sea.

The formula for hit chance is depending on airdamage, enemy strength and how many enemy units on plot.



When a rangestrike is made and a defender with rangestrike is being targeted, it will automatically return fire.
To make sure its the rangestriker that defends, the <UnitCombatDefenders> can be used on the rangestrikers in the CIV4UnitInfos.xml.
Otherwise it will be the strongest defender that will be hit.
Code:
<UnitCombatDefenders>
	<UnitCombatDefender>
		<UnitCombatDefenderType>UNITCOMBAT_SIEGE</UnitCombatDefenderType>
		<bUnitCombatDefender>1</bUnitCombatDefender>
	</UnitCombatDefender>
</UnitCombatDefenders>

To enable rangestrike for a unit, 3 things have to be changed in the CIV4UnitInfos.XML :
1) <iAirRange>
the range the unit can hit
2) <iAirCombat>
the damage done by an attack (Random 1-100%)
3) <iAirCombatLimit>
the max % of damage possible to enemy unit

The RANGE_COMBAT_DAMAGE in GlobalDefines.xml can be used to adjust the overall damage done by rangestrikes.

Note: Messaging is not completely done, and will be adjusted in later version.

Special thanks to everyone who helped with the coding. :goodjob:
 
Very nice! Can't wait for the next version! Still feels rather unfinished, unfortunately, because of the messages in particular. Also, outranged defenders being able to return fire seems a bit odd.
 
yeah, sorry for not posting the newest version. I've been kinda busy.
Both issues have been fixed in the newest version. I'll see if I can upload it this week.

Great! Can't wait!
 
Hey vincentz,

i like your modification, there is only one thing annoying. If a unit is completely destroyed by siege units, the death animation is not shown (as in an usual combat).
The destroyed unit just dissapears.

Are you going to fix this? :)
 
yeah, I saw it as well. Donno why death animation isnt shown, but it is definitely on my todo list ;)
I reckon its because I added extra time in between the shot to hit animation, coz I think it did it right in the beginning, but will have to check.

Looking at the code I suspect its the //delay death that needs to syncronize with the added *2 I added in the setmissiontime. Just a wild guess really, but it would somehow make sense.
Spoiler :
PHP:
	if (pPlot->isActiveVisible(false))
	{
		// Range strike entity mission
		CvMissionDefinition kDefiniton;
		kDefiniton.setMissionTime(GC.getMissionInfo(MISSION_RANGE_ATTACK).getTime() * gDLL->getSecsPerTurn() * 2); //Vincentz Rangestrike
		kDefiniton.setMissionType(MISSION_RANGE_ATTACK);
		kDefiniton.setPlot(pDefender->plot());
		kDefiniton.setUnit(BATTLE_UNIT_ATTACKER, this);
		kDefiniton.setUnit(BATTLE_UNIT_DEFENDER, pDefender);
		gDLL->getEntityIFace()->AddMission(&kDefiniton);

		//delay death
		pDefender->getGroup()->setMissionTimer(GC.getMissionInfo(MISSION_RANGE_ATTACK).getTime());

Im working on it (and my VIP mod which uses it as well) atm, as I have a few other things I want to do to it. I managed to add a few variables to the GlobalDefinesAlt.xml so its easy to configure/finetune without going into the dll.
Im thinking to expose the following :

Hit chance
Damage (is already there)
How many movepoints used per attack

anything else that should be exposed? Like should it be optional for the return fire, and if unit have already used an attack, should it still be able to return fire?
 
I am glad to hear that you are still working on it because it's a very considerable modification in my eyes.

Finally cannons on land may attack ships and the other way around. :goodjob:
It's worth to keep working on it.

I am not really sure how the hit chance works. Can you explain it more deeper?
How to influence the hit chance?

I will scrutinize the return fire and report back to you.
 
Im glad you ask, coz its one of the things I need to clean up/clear up :
PHP:
	if (((GC.getGameINLINE().getSorenRandNum(GC.getDefineINT("MAX_INTERCEPTION_DAMAGE"), "Random")) + airBaseCombatStr() * 2 * currHitPoints() / maxHitPoints()) < ((GC.getGameINLINE().getSorenRandNum(GC.getDefineINT("MAX_INTERCEPTION_DAMAGE"), "Random")) + pDefender->baseCombatStr() * pDefender->currHitPoints() / pDefender->maxHitPoints()))

Translated:
If RandomNumber(0-XXX*) + (Our Airstrength x 2 x Health% is less than
RandomNumber(0-XXX*) + (Their Strength x Health%) then it misses, otherwise it hits.

XXX* Should have another define in the GlobalDefinesAlt.xml than Max_Interception_Damage as it is now.

So basically if our "dice" and twice our Airstrength (regulated down if we are damaged) are higher than their "dice" and normal Strength (regulated down if they are damaged) then we hit.
So its easier to hit a damaged unit, but harder to shoot if we are damaged.

Now, the thought behind it was that you could have f.ex. an Artillery with strength 5 but Airstrength 15, so (A) when it was direct-attacked it would be easy to destroy and (B) when someone attacked it in a stack it would stay "behind the frontline" and be attacked last (unless cavalry was used for flanking ;))

The return fire is simply calculated the other way around with Their Attackstrength vs our Strength, and checking if its possible for their Rangestriker to hit ours :
PHP:
	if (pDefender->canRangeStrikeAt(this->plot(), this->plot()->getX_INLINE(), this->plot()->getY_INLINE()))

edit: the unit disapperaing instead of dying have been fixed, as it was indeed the *2 and *3 i added to timer. now they fire instantaneous and simultaneous.

edit: added the following to GlobalDefinesAlt.xml (not uploaded yet though)
PHP:
	<!--SIZE OF THE ATTACK-DICE, THE HIGHER, THE LESS AIRSTRENGTH/STRENGHT IS A FACTOR -->
	<Define>
		<DefineName>RANGESTRIKE_DICE</DefineName>
		<iDefineIntVal>100</iDefineIntVal>
	</Define>
	<!--1 FOR EQUAL ATTACK/DEFENSE (LOTS OF MISSES), >1 FOR EASIER HIT-->
	<Define>
		<DefineName>RANGESTRIKE_HIT_MODIFIER</DefineName>
		<iDefineIntVal>2</iDefineIntVal>
	</Define>
	<!--1 FOR ENABLE RANGESTRIKE RETURN FIRE, 0 FOR DISABLE -->
	<Define>
		<DefineName>RANGESTRIKE_RETURN_FIRE</DefineName>
		<iDefineIntVal>1</iDefineIntVal>
	</Define>
	<!--THE FORMULA FOR RANGESTRIKE HIT SUCCESS IS  -->
 
Thanks for the explanation. Sounds a like bit complex. ;)

I think for mod makers it would be the easiest way to define the hit chance in only one xml tag in CIV4UnitInfos.xml. So they can determine the hit chance of each siege combat unit (f.ex: the chance that an old trebuchet unit hits its enemy is lesser than an modern artillery unit, seperated from all other factors).

I have checked the return fire. Works fine. The return fire does only hit the unit which has fired before and not the whole enemy stack. I think this is wanted.

Ok, I am waiting for an new upload :)
 
the hitchance is already defined in unitinfos with the airstrength. The GlobalDefineAlt is just a way of finetuning on the fly (can be changed while game is running).
I'll upload as soon as I have finished testing, but the AI is doing a really good job using it imho. It shot at my ships and then at my attack stack:
Spoiler :
 
Have you considered editing the hotkey for range bombard to Shift+B or Alt+B instead of just B? Currently it uses just B, which is exactly the same bind as bombarding city defenses, which is annoying if you want to bombard city defenses and hitting B range bombards instead of lowers defense.

Also where is precision handled? Range attacks seem to miss a little too much for my test.

Good work at any rate, I will certainly incorporate this into my DoC modmod.
 
The hotkey is R ;) (or atleast it is with the version I'm running in my mod)

I'm currently testing it in my mod. There are some strange numbers when return fire sometimes, which doesnt look right, so gotta look at it at a time where I can focus and not too tired (having two kids age 1 and 4), so wait a bit merging it.
I also need to make AI bombard if possible before rangestriking (iirc it does it in the rangestrike mod, but not in my VIP mod), so gotta clean the code a bit, fix any AI issues, and then I will upload it here.
The precision is handled in globalDefinesAlt.xml (though not sure it is made in this uploaded version).
I'll try to do it over the weekend, but weather is incredible here, so cant promise anything ;)
 
Well, good news is I finally got the "if unitA with range 2 attacks unitB with only range 1, and they are 2 tiles apart, then unitB cannot rangestrike back" fixed. stupid mistake really ...
I also fixed the strange numbers (another stupid mistake) so now the return fire shows the correct damage. And have changed so it doesnt say (-xx% damage) but (xx% damage), otherwise a negative damage would actually be healing ;)
Gotta have a look at the Bombard before Rangestrike and then upload what might be a final release :D
 
Gotta have a look at the Bombard before Rangestrike and then upload what might be a final release :D

Sooooooo what's your progress on this?
 
I'm currently testing it in my VIP mod. There are however a few loose ends:

I want, for return fire, to get best defender, which can rangestrike, instead of preselected enemy (in unitinfos.xml), so there is less initial setup, and inter-domain return-fire attacks are better.

Sometimes the damage is 0% (instead of just showing "A miss")

Perhaps add range to Bombarding (it feels a bit off to be able to strike from range 3, but have to go next to city to bombard defenses.


Kids on holiday from Nursery/Kindergarten atm, so not really doing any programming atm though.
 
This is an awesome mod! How much do the normal unit bonuses affect the ranged damage? Like if I have an AT infantry and a normal infantry both range striking a tank with the same air damage and everything, the AT inf should do more damage, right?
 
This is an awesome mod! How much do the normal unit bonuses affect the ranged damage? Like if I have an AT infantry and a normal infantry both range striking a tank with the same air damage and everything, the AT inf should do more damage, right?

Yup... All bonus that would apply a normal attack applies to rangestrikers too.
And on top of that the walls, castles and bunkers give bonus to defense.
I also added an extra range when sieges are positioned in cities or forts (to illustrate its placed in an fortified defensive position).
All that is in the VIP mod, but when I feel the Rangestriking is starting to be finished I will export it and add it here. Having multiple mods with dll edits at the same time (especially with overlaps) kinda confuses me ;)
 
Top Bottom