Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Miscellaneous > Archive > CtP2-Creation/AI/Mods/Scenarios-Archive > (how) Does mod_UnitAttack work?
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
Question  Old Post 23-08-2002 21:09
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
(how) Does mod_UnitAttack work? Support Apolyton, buy Call to Power 2

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:-)

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 23-08-2002 21:31 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

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.

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 01:49
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Support Apolyton buy from Amazon

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:-)

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 02:11 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

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?

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 03:02
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Full PM-box? Change here!

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.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 03:10 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton

does it have any effect though?

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 03:31
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Support Apolyton

(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 on 24-08-2002 at 03:36

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 03:38 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Suffering from ads?

no-no, does the actual function have any effect on the attack and defense stats of the unit?

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 03:48
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Browse Apolyton AD-FREE

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.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 03:52 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Support Apolyton or Terrorists Win

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.

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 04:00
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Avatar Enlargement: We've got the solution

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.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 04:23 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Browse Apolyton AD-FREE

Don't try a battle between two units with 0 attack. It um, crashes the game...

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 04:28
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Support Apolyton buy from Amazon

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.

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 04:36 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Get a bigger avatar today!

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

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 04:47
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

Ah, my mistake. I see what you mean.

Locutus is offline Locutus
ACS CTP1/2 Manager & Civ4 Co-Manager
Hengelo, The Netherlands
Nov 1999
time: 06:21
  Old Post 24-08-2002 05:19 Visit Locutus<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Support Apolyton or Terrorists Win

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...

MATT:-) C is offline MATT:-) C
Settler
London
May 2001
time: 05:21
  Old Post 24-08-2002 05:30
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
Support Apolyton, buy Call to Power 2

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 . . .

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 05:33 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Support Apolyton, buy Civilization 2

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.

Peter Triggs is offline Peter Triggs
Prince
Gone Fishin, Canada
Jan 2000
time: 05:21
  Old Post 24-08-2002 13:00
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Increase the size of your Attachments

So, IW, another Civ3 feature that we can import into CTP2.

Locutus is offline Locutus
ACS CTP1/2 Manager & Civ4 Co-Manager
Hengelo, The Netherlands
Nov 1999
time: 06:21
  Old Post 24-08-2002 13:44 Visit Locutus<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

Immortal Wombat is offline Immortal Wombat
Prince
in perpetuity
Dec 2000
time: 05:21
  Old Post 24-08-2002 14:43 Visit Immortal Wombat's homepage!
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Support Apolyton buy from Amazon

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:21.
Apolyton Time is 00:21.
    top of page
Rate This Thread:
archivepost
Forum Jump:
Forum 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
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0601 seconds (91.01% PHP - 8.99% MySQL) with 31 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net