BUG python bugs when used in Pitboss

karadoc

AI programmer
Joined
Oct 3, 2005
Messages
1,568
Location
Australia
There are a bunch of different parts of BUG python code which will fail when used in the Pitboss host. Mostly, they are bits of code which assume the "active team" will be a valid team; which is not true for the pitboss host. These bugs will usually just cause the particular parts of the code to fail with no ill effects; but they could potentially cause unpredictable behaviour.

To fix this, for K-Mod, I'm intending to just disable all parts of BUG when "isPitbossHost()" is true.

But first, I'd like to confirm that this isn't going to break something, or disable certain game mechanics or anything like that.

In particular, I'd like to know if the BUG event manager is used to run any normal game mechanics. eg. is it used to replace the standard random events system or anything like that? Or can I safely just disable all of the "addEventHandler" things for the Pitboss host without changing the gameplay?
 
Unfortunately, I've struck a problem...

CyGame().isPitbossHost() does not work at the time the event manager is being initialized. ie. it always returns false. Apparently the event manager is initialized because the pitboss exe sets the pitboss variable thing to true... or something like that. In any case, it doesn't work at that particular point in the code; and I haven't yet thought of a way to work around it.

(Note to programmers: this is why you should always initialize your variables at the same time they are created! Otherwise, who knows when someone will come along and try to use the variable in-between creation and initialization?)
 
Hi, I'm a mod developer and have a pitboss mod.
My mod is mixed with code of dll BUG
.
Could you explain this fails in order to solve it in my mod ?
thanks in advance
 
I haven't dug into this aspect but I would guess that some of the screens won't work properly ...

- spy v spy
- victory conditions (turns to cultural victory)

As well as that, some of the info reported in the logger probably won't work (so and so changed religion, civics, etc). Best option is to search the python code for 'active team' references.
 
@DaveShack
The effects of the bug are essentially nil. All that happens is the python call to particular C functions crashes. It doesn't have any noticeable gameplay effects. But the nature of the problem is such that it could have gameplay effects, because it's possible that it could result in undefined, unpredictable behaviour instead of simply crashing.

@Manolo65
You can see the changes I've made to fix the problem here and here. (note that some of the changes in those commits are not related the the BUG code; and some of the changes in the first commit are actually undone by the second.)

Also, if you want to fix some more serious pitboss bugs in your mod, check out this and this.

@ruff_hi
I don't think that stuff will matter, because it will only be disabled for the pitboss host itself; not for the players. The pitboss host can't open those screens anyway.
 
Hi karadoc,

I would like to merge your changes in my private project, but since I´m new to modding I´m not really sure about the changes. On websites of your links the parts which should be added are green, the ones to delete or comment out are red. Correct?

Could you verify, that the changes are working well or have they caused any problems?

Thank you for your help.
 
Hi,

I´ve tried to merge the things, but at one point, I don´t know what to do. in the CvUnit.cpp your code is like this:

Code:
	int extraTime = 0;

// extra time for seige towers and surrendering leaders.
if ((pAttackUnit->getLeaderUnitType() != NO_UNIT && pAttackUnit->isDead()) ||
(pDefenceUnit->getLeaderUnitType() != NO_UNIT && pDefenceUnit->isDead()) ||
pAttackUnit->showSeigeTower(pDefenceUnit))
{
extraTime = BATTLE_TURNS_MELEE;
}

// K-Mod note: the original code used:
// gDLL->getEntityIFace()->GetSiegeTower(pAttackUnit->getUnitEntity()) || gDLL->getEntityIFace()->GetSiegeTower(pDefenceUnit->getUnitEntity())
// I've changed that to use showSeigeTower, because GetSiegeTower does not work for the Pitboss host, and therefore can cause OOS errors.

return BATTLE_TURNS_SETUP + BATTLE_TURNS_ENDING + kBattle.getNumMeleeRounds() * BATTLE_TURNS_MELEE + kBattle.getNumRangedRounds() * BATTLE_TURNS_MELEE + extraTime;
}

In my CvUnit.cpp is kBattleDefinition used, which is different from yours:
Code:
int extraTime = 0;
	if((attackerLeader && attackerDie) || (defenderLeader && defenderDie))
		extraTime = BATTLE_TURNS_MELEE;
	if(gDLL->getEntityIFace()->GetSiegeTower(kBattleDefinition.getUnit(BATTLE_UNIT_ATTACKER)->getUnitEntity()) || gDLL->getEntityIFace()->GetSiegeTower(kBattleDefinition.getUnit(BATTLE_UNIT_DEFENDER)->getUnitEntity()))
		extraTime = BATTLE_TURNS_MELEE;

	return BATTLE_TURNS_SETUP + BATTLE_TURNS_ENDING + kBattleDefinition.getNumMeleeRounds() * BATTLE_TURNS_MELEE + kBattleDefinition.getNumRangedRounds() * BATTLE_TURNS_MELEE + extraTime;
}

How should my code look like after merging? Thank you for your help.
 
@Alrik2002 To fix that particular problem, the final code should look exactly like the K-Mod code. Unfortunately the "showSeigeTower" function is not in the original code, so that will need to be added as well.

Alternatively, you could just copy the body of showSeigeTower into that part you are looking at. The reason I gave it its own function is so that I could be 100% sure it was consistent with the actual rules for when the siege tower is created - even if those rules change in the future. (Note that the showSeigeTower condition is also used to decide when to call "CvDLLEntity::SetSiegeTower" - this is happens inside CvUnit::setCombatUnit.)
 
Ok. Since I´m just starting with sdk-stuff it would be very nice if you could say me where in your source files the body of showSeigeTower is, which I have to copy.
 
Top Bottom