Basic Barbarian Great General Experience (modcomp)

modifieda4

Chief Time Waster
Joined
Sep 3, 2006
Messages
385
Location
Gold Coast
Basic Barbarian Great General Experience by ModifiedA4 v1.1 01/10/2012

The Barbarian Great General Experience mod allows Great General points from Barbarian combat

1.1 Download here
Change Log:
Spoiler :

  • 1.0 initial release
  • 1.1 added max xp check for barbarians, refined code
Requirements:
  • BTS 3.19
  • Gamecore DLL independant
  • BUG 4.4

see readme.txt for installation instructions.

Features:
  • unit combat with barbarians generates Great General points for human and AI players
  • checks max xp allowed from barabarians and animals before awarding GG points
  • awards 1 GG point per barbarians combat regardless of XP awarded
  • known "feature" that GG points are not awarded when maxing the XP for that unit level :p

This mod is so simple I posted the relevant python code here:
Spoiler :

Code:
	def onCombatResult(self, argsList):
		'Combat Result'
		pWinner,pLoser = argsList
		playerX = PyPlayer(pWinner.getOwner())
		unitX = PyInfo.UnitInfo(pWinner.getUnitType())
		playerY = PyPlayer(pLoser.getOwner())
		unitY = PyInfo.UnitInfo(pLoser.getUnitType())

		pPlayerWinner = gc.getPlayer(pWinner.getOwner())
		pPlayerLoser = gc.getPlayer(pLoser.getOwner())
	
		if pPlayerLoser.isBarbarian():
			if pLoser.isAnimal():
				if pWinner.getExperience()<=gc.getDefineINT("ANIMAL_MAX_XP_VALUE"):
					pPlayerWinner.changeCombatExperience(1)					
			elif pWinner.getExperience()<=gc.getDefineINT("BARBARIAN_MAX_XP_VALUE"):
					pPlayerWinner.changeCombatExperience(1)
I think with some tweaking I could make this also work for Barbarians to get GG points from combat.
 
just curious, what is the purpose of decreasing the unit exp by 1 and increasing it back again.

Why not just use pPlayerWinner.changeCombatExperience(1)

2 more issues:
1) Even if the unit does not gain exp from the combat (because of barbarian experience cap), the GG point will still be generated.
2) Amount of experience gained from the combat is irrevelant. Even if the unit gained 5 experience, only 1 GG point earned
 
That's indeed pretty simple :D :goodjob:.

Did you check if it might not interfere with promotion upgrades?
I'm not quite sure how it could, but needs a check imho.

im not sure i understand the scenario..but ill test taking a unit through an upgrade and check the promotions after one more battle.
edit:
ok i tested a warrior with 1 promotion level 1 (4/5xp) against a barbarian warrior. he gained 1xp for 5/5xp, i promoted him (now 5/10xp) and had one more battle and he got to 6/10xp and kept his promotions. was that your question?
 
just curious, what is the purpose of decreasing the unit exp by 1 and increasing it back again.

Why not just use pPlayerWinner.changeCombatExperience(1)

2 more issues:
1) Even if the unit does not gain exp from the combat (because of barbarian experience cap), the GG point will still be generated.
2) Amount of experience gained from the combat is irrevelant. Even if the unit gained 5 experience, only 1 GG point earned

i added and subtracted 1xp because as far as i can tell there is no way after a battle is completed to tell how much xp was awarded. so iwanted the net change to be zero. originally i wanted to match xp awarded, but in order to recalculate the battle xp you need to know who the attacker and defender was. :(

so...by adding and subtracting a known amount, 1xp, i dont change the xp that was already awarded. (that was the idea anyway)

tested your code,
1GG applied, 4 xp awarded to warrior on warrior combat from 0xp
same scenario, my code
2GG applied, 4 xp awarded to warrior (my code seems to double GG based on the static xp added/subtracted)
no code
0GG applied, 4xp awarded to warrior
my code subtract xp only
0GG applied, 3xp awarded to warrior
attacking non-barbarian (no code applies)
4GG applied, 4xp awarded to warrior

so it seems GG awards are static with the code vs normal combat. expected, but better than nothing. I like your code, it works and is simplier.

i added a check for the animal and barbarian limit. only downside is if you cross the limit with a combat you wont get GG for that...oh well.
Spoiler :

Code:
		pPlayerWinner = gc.getPlayer(pWinner.getOwner())
		pPlayerLoser = gc.getPlayer(pLoser.getOwner())
	
		if pPlayerLoser.isBarbarian():
			if pLoser.isAnimal():
				if pWinner.getExperience()<=gc.getDefineINT("ANIMAL_MAX_XP_VALUE"):
					pPlayerWinner.changeCombatExperience(1)					
			elif pWinner.getExperience()<=gc.getDefineINT("BARBARIAN_MAX_XP_VALUE"):
					pPlayerWinner.changeCombatExperience(1)

basically the mod name should be 1GG point per barbarian combat :)
 
Yeah, I thought about the limit as well, but the thing is this:

If BARBARIAN_MAX_XP_VALUE is 10 (BTS default),
A unit with 14 exp who killed a barb won't get GG generated. That's right.
However, a unit with 8 exp who killed a barb and become 12 exp, the GG also won't be generated because the getExperience code only checks the new Exp but not the Exp before battle.
 
was that your question?

Sorry :crazyeye:, when I looked at the code, I somehow that the lines in the other order, so I thought first +XP, then -XP, and feared that the AI might have some dirty tricks to promote units in between (you never know...).
So sorry for the more work, I've been wrong here :blush:.
 
i added and subtracted 1xp because as far as i can tell there is no way after a battle is completed to tell how much xp was awarded. so iwanted the net change to be zero. originally i wanted to match xp awarded, but in order to recalculate the battle xp you need to know who the attacker and defender was. :(
IIRC, we faced a similar problem with this in BUG and the logger - we wanted to log cat withdrawals through escape and through max damage differently. You couldn't tell from the combat results. However, you can set up a variable in one of the pre combat events ...

initialize variable ...
Code:
def onCombatLogCalc(self, argsList):
	...
	self.UnitKilled = 0
	self.WonLastRound = 0

keep track of current status
Code:
def onCombatLogHit(self, argsList):
	...	
	if (iIsAttacker == 0):
		self.WonLastRound = 0
			
	elif (iIsAttacker == 1):
		self.WonLastRound = 1

use the results to generate the message you need (note: message below has been shortened for code clarity)
Code:
def onSelectionGroupPushMission(self, argsList):
	...
	if (AutologOpt.isLogCombat()
	and gc.getPlayer(eOwner).getTeam() == gc.getActivePlayer().getTeam()):

		playerX = PyPlayer(self.WdlDefender.eOwner)
		defCivName = playerX.getCivilizationAdjective()

		if self.UnitKilled == 0:
			if self.WonLastRound == 1:
				message = "TXT_KEY_AUTOLOG_WHILE_ATTACKING_ESCAPES"
				Logger.writeLog(message, vColor="Red")
			else:
				message = "TXT_KEY_AUTOLOG_WHILE_ATTACKING_DECIMATES"
				Logger.writeLog(message, vColor="DarkRed")
 
Words cannot express how happy this makes me. Thank you for making this.
 
Top Bottom