attempt to fix morph out of synch

This commit is contained in:
Mark Vejvoda 2013-05-25 22:44:39 +00:00
parent 60a7ea172d
commit fd9ce54063
4 changed files with 42 additions and 5 deletions

View File

@ -1033,7 +1033,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
throw megaglest_runtime_error(szBuf);
}
ct= unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
if(unit->getFaction()->getIndex() != networkCommand->getUnitFactionIndex()) {
@ -1077,6 +1077,14 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
// !!!Test out of synch behaviour
//ct = NULL;
// Check if the command was for the unit before it morphed, if so cancel it
if(ct == NULL && unit->getPreMorphType() != NULL) {
const CommandType *ctPreMorph = unit->getPreMorphType()->findCommandTypeById(networkCommand->getCommandTypeId());
if(ctPreMorph != NULL) {
ct = unit->getType()->getFirstCtOfClass(ccStop);
}
}
if(ct == NULL) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d]\nCan not find command type for network command = [%s]\n%s\nfor unit = %d\n[%s]\n[%s]\nactual local factionIndex = %d.\nUnit Type Info:\n[%s]\nNetwork unit type:\n[%s]\nGame out of synch.",

View File

@ -3019,6 +3019,9 @@ void ScriptManager::saveGame(XmlNode *rootNode) {
unRegisterCellTriggerEventListNode->addAttribute("eventId",intToStr(unRegisterCellTriggerEventList[i]), mapTagReplacements);
}
scriptManagerNode->addAttribute("registeredDayNightEvent",intToStr(registeredDayNightEvent), mapTagReplacements);
scriptManagerNode->addAttribute("lastDayNightTriggerStatus",intToStr(lastDayNightTriggerStatus), mapTagReplacements);
luaScript.saveGame(scriptManagerNode);
}
@ -3129,6 +3132,13 @@ void ScriptManager::loadGame(const XmlNode *rootNode) {
unRegisterCellTriggerEventList.push_back(node->getAttribute("eventId")->getIntValue());
}
if(scriptManagerNode->hasAttribute("registeredDayNightEvent") == true) {
registeredDayNightEvent = scriptManagerNode->getAttribute("registeredDayNightEvent")->getIntValue() != 0;
}
if(scriptManagerNode->hasAttribute("lastDayNightTriggerStatus") == true) {
lastDayNightTriggerStatus = scriptManagerNode->getAttribute("lastDayNightTriggerStatus")->getIntValue();
}
luaScript.loadGame(scriptManagerNode);
}

View File

@ -2906,7 +2906,7 @@ void Unit::morphAttackBoosts(Unit *unit) {
}
}
bool Unit::morph(const MorphCommandType *mct){
bool Unit::morph(const MorphCommandType *mct) {
if(mct == NULL) {
char szBuf[8096]="";
@ -2922,9 +2922,14 @@ bool Unit::morph(const MorphCommandType *mct){
throw megaglest_runtime_error(szBuf);
}
Field morphUnitField=fLand;
if(morphUnitType->getField(fAir)) morphUnitField=fAir;
if(morphUnitType->getField(fLand)) morphUnitField=fLand;
Field morphUnitField = fLand;
if(morphUnitType->getField(fAir)) {
morphUnitField = fAir;
}
else if(morphUnitType->getField(fLand)) {
morphUnitField = fLand;
}
map->clearUnitCells(this, pos, false);
if(map->isFreeCellsOrHasUnit(pos, morphUnitType->getSize(), morphUnitField, this,morphUnitType)) {
map->clearUnitCells(this, pos, true);
@ -2947,6 +2952,7 @@ bool Unit::morph(const MorphCommandType *mct){
checkModelStateInfoForNewHpValue();
preMorph_type = type;
type= morphUnitType;
currField=morphUnitField;
computeTotalUpgrade();
@ -3848,6 +3854,7 @@ void Unit::saveGame(XmlNode *rootNode) {
unitNode->addAttribute("id",intToStr(id), mapTagReplacements);
// For info purposes only
unitNode->addAttribute("name",type->getName(), mapTagReplacements);
// int hp;
unitNode->addAttribute("hp",intToStr(hp), mapTagReplacements);
// int ep;
@ -3908,6 +3915,9 @@ void Unit::saveGame(XmlNode *rootNode) {
unitNode->addAttribute("rotationX",floatToStr(rotationX,16), mapTagReplacements);
// const UnitType *type;
unitNode->addAttribute("type",type->getName(), mapTagReplacements);
unitNode->addAttribute("preMorph_type",(preMorph_type != NULL ? preMorph_type->getName() : ""), mapTagReplacements);
// const ResourceType *loadType;
if(loadType != NULL) {
unitNode->addAttribute("loadType",loadType->getName(), mapTagReplacements);
@ -4155,6 +4165,12 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
//Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
Unit *result = new Unit(newUnitId, newpath, newUnitPos, ut, faction, world->getMapPtr(), newModelFacing);
if(unitNode->hasAttribute("preMorph_name") == true) {
string newUnitType_preMorph = unitNode->getAttribute("preMorph_name")->getValue();
const UnitType *ut_premorph = faction->getType()->getUnitType(newUnitType_preMorph);
result->preMorph_type = ut_premorph;
}
result->lastRotation = unitNode->getAttribute("lastRotation")->getFloatValue();
result->targetRotation = unitNode->getAttribute("targetRotation")->getFloatValue();
result->rotation = unitNode->getAttribute("rotation")->getFloatValue();

View File

@ -376,6 +376,7 @@ private:
float rotationZ;
float rotationX;
const UnitType *preMorph_type;
const UnitType *type;
const ResourceType *loadType;
const SkillType *currSkill;
@ -527,6 +528,8 @@ public:
inline Faction *getFaction() const {return faction;}
inline const ResourceType *getLoadType() const {return loadType;}
inline const UnitType *getType() const {return type;}
inline const UnitType *getPreMorphType() const {return preMorph_type;}
inline const SkillType *getCurrSkill() const {return currSkill;}
inline const TotalUpgrade *getTotalUpgrade() const {return &totalUpgrade;}
inline float getRotation() const {return rotation;}