August 23, 2002, 12:09
|
#1
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
(how) Does mod_UnitAttack work?
I did a quick search of the forums and found no answers so here goes:
I was toying around with a random idea to do with modifying a units attack when a given tech is has been researched. This example would increase the attack of a bronze age unit after iron working has been researched to simulate weapons upgrading (don't know how realistic that is, but hey). Do any of you know if the following code outline would work in principle. I'm concerned mainly about the function's arguments, return type and return value.
Code:
|
int_f mod_UnitAttack(unit_t localunit, int_t localattack)
{
int_t alittlebit;
alittlebit = 2;
//insert proper 'if' code
if((localunit is a bronze age unit) && (localunit.owner has adv_iron_working))
{
//beef up my attack
return localattack + alittlebit;
}
else
{
return localattack;
}
} |
And do you guys know when the function is called. Is it only when a unit attacks (move into an enemy unit) or all battles that the unit fights?
Any ideas? If not I'll try and mess around with it myself, but I'd rather someone else already has!
Thanks in advance, MATT:-)
|
|
|
|
August 23, 2002, 12:31
|
#2
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
mod_* functions are called at all times, basically. There is no need to call them them from anywhere - as soon as the issue becomes needed, the mod_* function springs into action.
However, the "last 3" mod functions, i.e. the ones not used in the Activision scenarios - mod_UnitAttack, mod_UnitDefense, and mod_UnitRangedAttack are not known to be functioning. Test it with some extreme values first to see whether it does actually work. Personally, I doubt it does. MrOgre mentioned the function only once on the forum, as a function "he will include" - but as both the Alexander and Samurai scenarios find different ways to do the same thing, we remain in uncertainty as to whether the function was implemented, or included and left dead.
Its a good idea though, and the code above would feasibly work with proper if() statements in.
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 16:49
|
#3
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
Thanks for the info. I've done some testing and here's what I found so far, which may be wrong:
Code:
|
int_f mod_UnitAttack(unit_t theAttacker, unit_t theDefender, int_t normalAttackValue)
{
return modifiedAttackValue;
}
int_f mod_UnitDefense(unit_t theDefender, unit_t theAttacker, int_t normalDefenseValue)
{
return modifiedDefenseValue;
}
//int_f mod_UnitRangedAttack() doesn't seem to be implemented anywhere so is useless |
The return values are the modified attack/defense values to use in the battle. The units are what you expect them to be. The normal attack/defense values are the appropriate values for the attacking/defending units. Note that the defense value takes into account bonuses for terrain and fortifications as far as I can tell. The veteran status of a unit doesn't seem to be accounted for in this value (at least not for the attacker that I tested), it may be included after the function is called or in a seperate call to the function, or not at all!
As an example of how the functions are called, an infantryman attacks a warrior (no bonuses for anything) :
First mod_UnitAttack() is called twice (?why?) with the infantryman as attacker and attack value of 25. Then mod_UnitDefense() is called with warrior as defender, defense value 10.
Then the same functions, but with infantryman and warrior reversed, ie twice mod_UnitAttack() with warrior as attacker (value 10) then once mod_UnitDefense() with Infantryman as defender (value 35).
Then repeated until someone dies.
Now, if the warrior was in a forest, his defense value would rise to 12 (10 +25% bonus rounded down), and his attack value would remain at 10. If the infantryman was on a mountain his defense would rise to 70 (35 +100% bonus), but his attack would remain at 25. This happens regardless of who initiated the battle.
[This gets more complicated when ranged units are included too. All the ranged units do their attacking first and then enemy ranged units, then front line units attack as above. No calls to mod_UnitRangedAttack() are made though, only an appropriate mod_UnitDefense().]
I hope that makes sense! If that's not clear I'll try again.
TTFN, MATT:-)
|
|
|
|
August 23, 2002, 17:11
|
#4
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
So to summarise:
mod_UnitRangedAttack doesn't work.
the mod function returns the attack or defense value to be used in the battle.
I don't get why it needs two unit arguments. I loaded a game successfully with just one unit, one integer, to alter that unit's attack/defense throughout the game.
Also, how did you find out when the functions were being called? With a messagebox?
What happens there are two attackers against one defending unit?
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 18:02
|
#5
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
Your summary is much more elegant than my ramble, I wish I'd thought of it!
I guess the two unit arguments are there for functionality. For example you could script a defense bonus for pikemen against mounted units, a la civ2, by checking the appropriate unit arguments. It seems that you can script the function with as many arguments as you like, there is no error check as far as this is concerned (well not with debugslic=no anyway).
I did use message boxes to work out when the functions were called, and also what arguments were passed into the function (via a text output).
As for 2(knights - as flankers) vs 1(warrior), it is as you might expect. One knight attacks and the warrior defends, then the next knight attacks and the warrior defends again. Finally the warrior attacks the knight he is facing. Then the knights go again, and so on.
It seems that the only difference between being an overall attacker or defender in a battle is who strikes first.
|
|
|
|
August 23, 2002, 18:10
|
#6
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
does it have any effect though?
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 18:31
|
#7
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
(I assume you're referring to my last sentence in which case...)
All other things being equal, it will (statistically speaking) make little or no difference whether you are the overall attacker or defender. It will have a larger effect if you outnumber the enemy and have flankers/ranged units in your line in which case the first strike will kill off the enemy quicker, but that may only result in a few less hit points lost by your units in a battle you're very likely to win anyway!
Having said that, little or no difference might be 1 hit point difference between the overall attacker and overall defender, which is the difference between a dead unit and one that can be healed and return to fight again.
I have a distinct feeling that I may be wrong on that though - it seems a bit odd.
Last edited by MATT:-) C; August 23, 2002 at 18:36.
|
|
|
|
August 23, 2002, 18:38
|
#8
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
no-no, does the actual function have any effect on the attack and defense stats of the unit?
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 18:48
|
#9
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
Sorry! From my testing it appears that the mod functions change the value to use for that particular round of combat. It doesn't permanently change the stats of the units. I guess that's the effect hoped for.
|
|
|
|
August 23, 2002, 18:52
|
#10
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
Quote:
|
From my testing it appears that the mod functions change the value to use for that particular round of combat. It doesn't permanently change the stats of the units
|
Yeah, but if it's called on every round of combat, then it might as well be permanant.
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 19:00
|
#11
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
True, that would reduce function overheads too. The only problem with permanace might be that you'd have to check if the bonus had been applied each time the function was called, creating another function overhead instead. It looks like either way could have been implemented and the programmers happened to choose that one. It's a shame we'll never know why!
Thanks for your help on this one.
|
|
|
|
August 23, 2002, 19:23
|
#12
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
Don't try a battle between two units with 0 attack. It um, crashes the game...
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 19:28
|
#13
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
On second thoughts, maybe make that a "no it doesn't work". I just tried it, by setting all my units to have 100 attack/defence and it had no effect.
|
|
|
|
August 23, 2002, 19:36
|
#14
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
all the attack figures are scaled up by 100. 100 in units.txt = 1 attack point. Try varying it.
I haven't been able to determine accurately whether it can return more than 1 and 0 or a range
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 23, 2002, 19:47
|
#15
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
Ah, my mistake. I see what you mean.
|
|
|
|
August 23, 2002, 20:19
|
#16
|
Deity
Local Time: 08:48
Local Date: November 1, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
|
Great to finally see someone trying to figure this out
It's *extremely* annoying the ranged function doesn't work though, I had several uses in mind for that one should we ever have gotten in to work
I briefly messed with this myself and so far I found out two important things:
(1) it doesn't matter what arguments or return value you use, even when they are left out altogether the messageboxes appear. So the function (I only tested Attack, I assume Defense works the same) is *always* called during combat, regardless of what arguments value are used. The only thing you need to do is spell the function name correctly This means finding out proper arguments and return values could turn out to be tricky...
(2) I couldn't seem to get the function to work, even with very high return values (100000) it didn't seem to make much of a difference. However, when I used the following code:
Code:
|
int_f mod_UnitAttack() {
return 0;
} |
The first round of combat was fought out normally, but then they units kept attacking eachother without results, as one would expect with an attack value of 0. Of course, this continued forever and closing the combat screen froze the game, as the game had entered an infinite loop. But apparently this function *does* do something...
|
|
|
|
August 23, 2002, 20:30
|
#17
|
Settler
Local Time: 06:48
Local Date: November 1, 2010
Join Date: May 2001
Location: London
Posts: 25
|
Yeah, I got that too. I've only been able to get rid of a units attack or defense and not much else. Only int values can be returned and I see no change yet except for when I use 0. Maybe it's like the other mod_CanCityBuild* functions, a boolean saying you can or can't attack/defend. Hohum, on with the testing just in case . . .
|
|
|
|
August 23, 2002, 20:33
|
#18
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
Yeah, that latter result is what I got as well.
I got a weird result when I set it up to return the unit's defence value. I got hoplites that wouldn't die. It killed a tank.
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
August 24, 2002, 04:00
|
#19
|
King
Local Time: 06:48
Local Date: November 1, 2010
Join Date: Jan 2000
Location: Gone Fishin, Canada
Posts: 1,059
|
So, IW, another Civ3 feature that we can import into CTP2.
|
|
|
|
August 24, 2002, 04:44
|
#20
|
Deity
Local Time: 08:48
Local Date: November 1, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
|
|
|
|
|
August 24, 2002, 05:43
|
#21
|
Prince
Local Time: 07:48
Local Date: November 1, 2010
Join Date: Dec 2000
Location: in perpetuity
Posts: 4,962
|
__________________
Concrete, Abstract, or Squoingy?
"I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
All times are GMT -4. The time now is 02:48.
|
|