- bugfix, now support proper saving and reloading of games where attack boost is applied to units

This commit is contained in:
SoftCoder 2013-12-22 16:10:00 -08:00
parent 6cd1d237ab
commit da3c55c00b
3 changed files with 103 additions and 39 deletions

View File

@ -566,6 +566,11 @@ void Renderer::initGame(const Game *game, GameCamera *gameCamera) {
}
void Renderer::manageDeferredParticleSystems() {
// if(deferredParticleSystems.empty() == false) {
// printf("deferredParticleSystems.size() = %d\n",(int)deferredParticleSystems.size());
// }
for(unsigned int i = 0; i < deferredParticleSystems.size(); ++i) {
std::pair<ParticleSystem *, ResourceScope> &deferredParticleSystem = deferredParticleSystems[i];
ParticleSystem *ps = deferredParticleSystem.first;
@ -605,6 +610,7 @@ void Renderer::manageDeferredParticleSystems() {
}
}
manageParticleSystem(ps, rs);
//printf("Managing ps [%p]\n",ps);
}
deferredParticleSystems.clear();
//printf("After deferredParticleSystems.size() = %d\n",deferredParticleSystems.size());

View File

@ -308,7 +308,10 @@ UnitAttackBoostEffect::~UnitAttackBoostEffect() {
const Unit * UnitAttackBoostEffect::getSource() {
if(source == NULL && unitPtr != NULL && unitId > 0) {
source = unitPtr->getFaction()->findUnit(unitId);
//printf("#1 Get source - boost effect unitId = %d unitPtr = %s source = %p\n",unitId,unitPtr->getFullName(false).c_str(),source);
}
//printf("#2 Get source - boost effect unitId = %d unitPtr = %s source = %p\n",unitId,unitPtr->getFullName(false).c_str(),source);
return source;
}
@ -316,37 +319,75 @@ void UnitAttackBoostEffect::setSource(const Unit *unit) {
source = unit;
}
void UnitAttackBoostEffect::loadGame(const XmlNode *rootNode, Unit *unit, const SkillType *skillType) {
//const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->getChild("UnitAttackBoostEffect");
const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode;
void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemType *upstPtr,const XmlNode *node, Unit* unit) {
if (upstPtr != NULL) {
bool showUnitParticles = Config::getInstance().getBool("UnitParticles","true");
if (showUnitParticles == true) {
upst = new UnitParticleSystemType();
*upst = *upstPtr;
upst->loadGame(node);
AttackBoost *load_boost = new AttackBoost();
load_boost->loadGame(unitAttackBoostEffectOriginatorNode,unit->getFaction(),skillType);
boost = load_boost;
ups = new UnitParticleSystem(200);
//ups->loadGame(node2);
ups->setParticleOwner(unit);
upst->setValues(ups);
ups->setPos(unit->getCurrVector());
if (unit->getFaction()->getTexture()) {
ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0));
}
//printf("Adding attack boost particle to deferred buffer: %p\n",ups);
Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame));
}
}
}
if(unitAttackBoostEffectOriginatorNode->hasAttribute("source") == true) {
unitId = unitAttackBoostEffectOriginatorNode->getAttribute("source")->getIntValue();
void UnitAttackBoostEffect::loadGame(const XmlNode *rootNode, Unit *unit, World *world, bool applyToOriginator) {
const XmlNode *unitAttackBoostEffectNode = rootNode;
if(unitAttackBoostEffectNode->hasAttribute("source") == true) {
unitId = unitAttackBoostEffectNode->getAttribute("source")->getIntValue();
unitPtr = unit;
source = unit->getFaction()->findUnit(unitId);
// printf("#1 Loaded boost effect unitId = %d unitPtr = [%d - %s] source = %p\n",
// unitId,unitPtr->getId(),unitPtr->getType()->getName(false).c_str(),source);
}
if(unitAttackBoostEffectOriginatorNode->hasChild("UnitParticleSystemType") == true) {
//const XmlNode *node = unitAttackBoostEffectOriginatorNode->getChild("UnitParticleSystemType");
// Lets determine the originator unit's attack boost based on the skill used to trigger it
if(unitAttackBoostEffectNode->hasAttribute("source-faction") == true) {
string factionName = unitAttackBoostEffectNode->getAttribute("source-faction")->getValue();
string unitTypeName = unitAttackBoostEffectNode->getAttribute("source-unit-type")->getValue();
string skillTypeName = unitAttackBoostEffectNode->getAttribute("source-skill-type")->getValue();
SkillClass skillClass = static_cast<SkillClass>(unitAttackBoostEffectNode->getAttribute("source-skill-class")->getIntValue());
upst = new UnitParticleSystemType();
upst->loadGame(unitAttackBoostEffectOriginatorNode);
const UnitType *unitType = world->findUnitTypeByName(factionName, unitTypeName);
if(unitType != NULL) {
const SkillType *skillType = unitType->getSkillType(skillTypeName,skillClass);
if(skillType != NULL) {
boost = skillType->getAttackBoost();
// printf("#2 boost effect unitId = %d unitPtr = [%d - %s] source = %p attackBoost src [%p] dest [%p]\n",
// unitId,unitPtr->getId(),unitPtr->getType()->getName(false).c_str(),
// source,boost->unitParticleSystemTypeForSourceUnit,boost->unitParticleSystemTypeForAffectedUnit);
}
}
}
if(unitAttackBoostEffectOriginatorNode->hasChild("UnitParticleSystem") == true) {
const XmlNode *node = unitAttackBoostEffectOriginatorNode->getChild("UnitParticleSystem");
if(boost != NULL) {
// printf("unit [%d - %s] applyToOriginator: %d src [%p] dest [%p] Boost attackBoost->enabled = %d:\n%s\n",
// unit->getId(),unit->getType()->getName(false).c_str(),applyToOriginator,boost->unitParticleSystemTypeForSourceUnit,boost->unitParticleSystemTypeForAffectedUnit,boost->enabled,boost->getDesc(false).c_str());
ups = new UnitParticleSystem(200);
ups->loadGame(node);
ups->setParticleOwner(unit);
upst->setValues(ups);
Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame));
if(applyToOriginator == true) {
applyLoadedAttackBoostParticles(boost->unitParticleSystemTypeForSourceUnit,
unitAttackBoostEffectNode, unit);
}
else {
applyLoadedAttackBoostParticles(boost->unitParticleSystemTypeForAffectedUnit,
unitAttackBoostEffectNode, unit);
}
}
else {
printf("******!!!! unit [%d - %s] applyToOriginator: %d NO BOOST FOUND!!!\n",unit->getId(),unit->getType()->getName(false).c_str(),applyToOriginator);
}
}
@ -359,8 +400,13 @@ void UnitAttackBoostEffect::saveGame(XmlNode *rootNode) {
boost->saveGame(unitAttackBoostEffectNode);
}
// const Unit *source;
if(source != NULL) {
unitAttackBoostEffectNode->addAttribute("source",intToStr(source->getId()), mapTagReplacements);
if(getSource() != NULL) {
unitAttackBoostEffectNode->addAttribute("source",intToStr(getSource()->getId()), mapTagReplacements);
unitAttackBoostEffectNode->addAttribute("source-faction",getSource()->getFaction()->getType()->getName(false), mapTagReplacements);
unitAttackBoostEffectNode->addAttribute("source-unit-type",getSource()->getType()->getName(false), mapTagReplacements);
unitAttackBoostEffectNode->addAttribute("source-skill-type",getSource()->getCurrSkill()->getName(), mapTagReplacements);
unitAttackBoostEffectNode->addAttribute("source-skill-class",intToStr(getSource()->getCurrSkill()->getClass()), mapTagReplacements);
}
// UnitParticleSystem *ups;
if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) {
@ -383,7 +429,7 @@ UnitAttackBoostEffectOriginator::~UnitAttackBoostEffectOriginator() {
currentAppliedEffect = NULL;
}
void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *unit) {
void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *unit, World *world) {
const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->getChild("UnitAttackBoostEffectOriginator");
SkillClass skillClass = scStop;
@ -416,7 +462,7 @@ void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *un
if(unitAttackBoostEffectOriginatorNode->hasChild("UnitAttackBoostEffect") == true) {
currentAppliedEffect = new UnitAttackBoostEffect();
currentAppliedEffect->loadGame(unitAttackBoostEffectOriginatorNode, unit,this->skillType);
currentAppliedEffect->loadGame(unitAttackBoostEffectOriginatorNode, unit,world, true);
}
}
@ -2574,6 +2620,7 @@ bool Unit::update() {
}
}
//printf("Unit has attack boost? unit = [%d - %s] size = %d\n",this->getId(), this->getType()->getName(false).c_str(),(int)currentAttackBoostEffects.size());
for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) {
UnitAttackBoostEffect *effect = currentAttackBoostEffects[i];
if(effect != NULL && effect->ups != NULL) {
@ -2582,8 +2629,13 @@ bool Unit::update() {
effect->ups->setPos(getCurrVector());
effect->ups->setRotation(getRotation());
}
//printf("i = %d particleValid = %d\n",i,particleValid);
}
//printf("i = %d effect = %p effect->ups = %p\n",i,effect,(effect ? effect->ups : NULL));
}
if(currentAttackBoostOriginatorEffect.currentAppliedEffect != NULL) {
if(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups != NULL) {
bool particleValid = Renderer::getInstance().validateParticleSystemStillExists(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups,rsGame);
@ -2693,6 +2745,9 @@ bool Unit::unitHasAttackBoost(const AttackBoost *boost, const Unit *source) {
break;
}
}
//printf("Unit has attack boost? source = [%d - %s] [%p] boost [%s] result = %d\n",source->getId(), source->getType()->getName(false).c_str(),source,boost->name.c_str(),result);
return result;
}
@ -5141,7 +5196,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// UnitAttackBoostEffectOriginator currentAttackBoostOriginatorEffect;
// !!! TODO: Softcoder - in progress work to load attack boosts, not working properly yet
//result->currentAttackBoostOriginatorEffect.loadGame(unitNode,result);
result->currentAttackBoostOriginatorEffect.loadGame(unitNode,result, world);
// std::vector<UnitAttackBoostEffect *> currentAttackBoostEffects;
// for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) {
@ -5150,17 +5205,18 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// }
// !!! TODO: Softcoder - in progress work to load attack boosts, not working properly yet
// if(unitNode->hasChild("UnitAttackBoostEffect") == true) {
// vector<XmlNode *> unitParticleSystemNodeList = unitNode->getChildList("UnitAttackBoostEffect");
// for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) {
// XmlNode *node = unitParticleSystemNodeList[i];
//
// UnitAttackBoostEffect *attackBoostEffect = new UnitAttackBoostEffect();
// attackBoostEffect->loadGame(node,result,result->getCurrSkill());
//
// result->currentAttackBoostEffects.push_back(attackBoostEffect);
// }
// }
if(unitNode->hasChild("UnitAttackBoostEffect") == true) {
vector<XmlNode *> unitParticleSystemNodeList = unitNode->getChildList("UnitAttackBoostEffect");
for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) {
XmlNode *node = unitParticleSystemNodeList[i];
UnitAttackBoostEffect *attackBoostEffect = new UnitAttackBoostEffect();
attackBoostEffect->loadGame(node,result,world,false);
result->currentAttackBoostEffects.push_back(attackBoostEffect);
}
}
//printf("Unit [%d - %s] has currentAttackBoostEffects count: %d\n",result->getId(),result->getType()->getName(false).c_str(),(int)result->currentAttackBoostEffects.size());
// Mutex *mutexCommands;

View File

@ -300,6 +300,8 @@ private:
const Unit *unitPtr;
const Unit *source;
void applyLoadedAttackBoostParticles(UnitParticleSystemType *upstPtr,const XmlNode* node, Unit* unit);
public:
UnitAttackBoostEffect();
@ -313,7 +315,7 @@ public:
UnitParticleSystemType *upst;
virtual void saveGame(XmlNode *rootNode);
virtual void loadGame(const XmlNode *rootNode, Unit *unit, const SkillType *skillType);
virtual void loadGame(const XmlNode *rootNode, Unit *unit, World *world, bool applyToOriginator);
};
class UnitAttackBoostEffectOriginator {
@ -327,7 +329,7 @@ public:
UnitAttackBoostEffect *currentAppliedEffect;
virtual void saveGame(XmlNode *rootNode);
virtual void loadGame(const XmlNode *rootNode, Unit *unit);
virtual void loadGame(const XmlNode *rootNode, Unit *unit, World *world);
};
class Unit : public BaseColorPickEntity, ValueCheckerVault, public ParticleOwner {