diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index d89677e06..2dd5d6a3f 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -182,7 +182,7 @@ bool CSpellEffectAnim::init() { if(effect == -1 || graphics->battleACToDef[effect].size() != 0) { - const CStack* destStack = LOCPLINT->cb->battleGetStackByPos(destTile, false); + const CStack* destStack = owner->curInt->cb->battleGetStackByPos(destTile, false); Rect &tilePos = owner->bfield[destTile].pos; SBattleEffect be; be.effectID = ID; @@ -370,7 +370,7 @@ void CReverseAnim::nextFrame() { owner->creDir[stackID] = !owner->creDir[stackID]; - const CStack * curs = LOCPLINT->cb->battleGetStackByID(stackID, false); + const CStack * curs = owner->curInt->cb->battleGetStackByID(stackID, false); Point coords = CBattleHex::getXYUnitAnim(hex, owner->creDir[stackID], curs, owner); owner->creAnims[stackID]->pos.x = coords.x; @@ -404,7 +404,7 @@ void CReverseAnim::nextFrame() void CReverseAnim::endAnim() { CBattleAnimation::endAnim(); - if( LOCPLINT->cb->battleGetStackByID(stackID) )//don't do that if stack is dead + if( owner->curInt->cb->battleGetStackByID(stackID) )//don't do that if stack is dead owner->creAnims[stackID]->setType(2); delete this; @@ -441,7 +441,7 @@ bool CDefenceAnim::init() if(attAnim && attAnim->stackID != stackID) continue; - const CStack * attacker = LOCPLINT->cb->battleGetStackByID(IDby, false); + const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); if(IDby != -1) { int attackerAnimType = owner->creAnims[IDby]->getType(); @@ -461,8 +461,8 @@ bool CDefenceAnim::init() return false; - const CStack * attacker = LOCPLINT->cb->battleGetStackByID(IDby, false); - const CStack * attacked = LOCPLINT->cb->battleGetStackByID(stackID, false); + const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); + const CStack * attacked = owner->curInt->cb->battleGetStackByID(stackID, false); //reverse unit if necessary if(attacker && isToReverse(attacked->position, attacker->position, owner->creDir[stackID], attacker->hasFeatureOfType(StackFeature::DOUBLE_WIDE), owner->creDir[IDby])) @@ -510,7 +510,7 @@ void CDefenceAnim::nextFrame() if(!owner->creAnims[stackID]->onLastFrameInGroup()) { - if( owner->creAnims[stackID]->getType() == 5 && (owner->animCount+1)%(4/LOCPLINT->sysOpts.animSpeed)==0 + if( owner->creAnims[stackID]->getType() == 5 && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0 && !owner->creAnims[stackID]->onLastFrameInGroup() ) { owner->creAnims[stackID]->incrementFrame(); @@ -535,8 +535,8 @@ void CDefenceAnim::endAnim() if(IDby!=-1) owner->printConsoleAttacked(stackID, dmg, amountKilled, IDby); - const CStack * attacker = LOCPLINT->cb->battleGetStackByID(IDby, false); - const CStack * attacked = LOCPLINT->cb->battleGetStackByID(stackID, false); + const CStack * attacker = owner->curInt->cb->battleGetStackByID(IDby, false); + const CStack * attacked = owner->curInt->cb->battleGetStackByID(stackID, false); CBattleAnimation::endAnim(); @@ -561,7 +561,7 @@ bool CBattleStackMoved::init() steps = owner->creAnims[stackID]->framesInGroup(0)*owner->getAnimSpeedMultiplier()-1; whichStep = 0; int hexWbase = 44, hexHbase = 42; - const CStack * movedStack = LOCPLINT->cb->battleGetStackByID(stackID, false); + const CStack * movedStack = owner->curInt->cb->battleGetStackByID(stackID, false); if(!movedStack || owner->creAnims[stackID]->getType() == 5) { endAnim(); @@ -657,7 +657,7 @@ void CBattleStackMoved::nextFrame() void CBattleStackMoved::endAnim() { - const CStack * movedStack = LOCPLINT->cb->battleGetStackByID(stackID); + const CStack * movedStack = owner->curInt->cb->battleGetStackByID(stackID); CBattleAnimation::endAnim(); @@ -691,7 +691,7 @@ void CBattleStackMoved::endAnim() CBattleStackMoved::CBattleStackMoved(CBattleInterface * _owner, int _number, int _destHex, bool _endMoving, int _distance) : CBattleStackAnimation(_owner, _number), destHex(_destHex), endMoving(_endMoving), distance(_distance), stepX(0.0f), stepY(0.0f) { - curStackPos = LOCPLINT->cb->battleGetPos(stackID); + curStackPos = owner->curInt->cb->battleGetPos(stackID); } //move started @@ -701,7 +701,7 @@ bool CBattleMoveStart::init() if( !isEarliest(false) ) return false; - const CStack * movedStack = LOCPLINT->cb->battleGetStackByID(stackID, false); + const CStack * movedStack = owner->curInt->cb->battleGetStackByID(stackID, false); if(!movedStack || owner->creAnims[stackID]->getType() == 5) { @@ -722,7 +722,7 @@ void CBattleMoveStart::nextFrame() } else { - if((owner->animCount+1)%(4/LOCPLINT->sysOpts.animSpeed)==0) + if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0) owner->creAnims[stackID]->incrementFrame(); } } @@ -746,7 +746,7 @@ bool CBattleMoveEnd::init() if( !isEarliest(true) ) return false; - const CStack * movedStack = LOCPLINT->cb->battleGetStackByID(stackID, false); + const CStack * movedStack = owner->curInt->cb->battleGetStackByID(stackID, false); if(!movedStack || owner->creAnims[stackID]->framesInGroup(21) == 0 || owner->creAnims[stackID]->getType() == 5) { endAnim(); @@ -815,8 +815,8 @@ bool CBattleAttack::checkInitialConditions() CBattleAttack::CBattleAttack(CBattleInterface * _owner, int _stackID, int _dest, int _attackedID) : CBattleStackAnimation(_owner, _stackID), dest(_dest) { - attackedStack = LOCPLINT->cb->battleGetStackByID(_attackedID, false); - attackingStack = LOCPLINT->cb->battleGetStackByID(_stackID, false); + attackedStack = owner->curInt->cb->battleGetStackByID(_attackedID, false); + attackingStack = owner->curInt->cb->battleGetStackByID(_stackID, false); assert(attackingStack && "attackingStack is NULL in CBattleAttack::CBattleAttack !\n"); if(attackingStack->creature->idNumber != 145) //catapult is allowed to attack not-creature @@ -825,7 +825,7 @@ CBattleAttack::CBattleAttack(CBattleInterface * _owner, int _stackID, int _dest, } else //catapult can attack walls only { - assert(LOCPLINT->cb->battleGetWallUnderHex(_dest) >= 0); + assert(owner->curInt->cb->battleGetWallUnderHex(_dest) >= 0); } attackingStackPosBeforeReturn = attackingStack->position; } @@ -1059,11 +1059,11 @@ void CBattleInterface::addNewAnim(CBattleAnimation * anim) animsAreDisplayed.setn(true); } -CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect) +CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen) : attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), stackToActivate(-1), mouseHoveredStack(-1), previouslyHoveredHex(-1), currentlyHoveredHex(-1), spellDestSelectMode(false), spellToCast(NULL), givenCommand(NULL), myTurn(false), resWindow(NULL), animIDhelper(0), - moveStarted(false), moveSh(-1), siegeH(NULL), bresult(NULL), queue(NULL) + moveStarted(false), moveSh(-1), siegeH(NULL), bresult(NULL), queue(NULL), attackerInt(att), defenderInt(defen), curInt(att) { ObjectConstruction h__l__p(this); @@ -1074,8 +1074,8 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C //create stack queue bool embedQueue = screen->h < 700; - queue = new CStackQueue(embedQueue); - if(!embedQueue && LOCPLINT->sysOpts.showQueue) + queue = new CStackQueue(embedQueue, this); + if(!embedQueue && curInt->sysOpts.showQueue) { pos.y += queue->pos.h / 2; //center whole window queue->moveTo(Point(pos.x, pos.y - queue->pos.h)); @@ -1087,18 +1087,18 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C queue->update(); //preparing siege info - const CGTownInstance * town = LOCPLINT->cb->battleGetDefendedTown(); + const CGTownInstance * town = curInt->cb->battleGetDefendedTown(); if(town && town->hasFort()) { siegeH = new SiegeHelper(town, this); } - LOCPLINT->battleInt = this; + curInt->battleInt = this; //initializing armies this->army1 = army1; this->army2 = army2; - std::map stacks = LOCPLINT->cb->battleGetStacks(); + std::map stacks = curInt->cb->battleGetStacks(); for(std::map::iterator b=stacks.begin(); b!=stacks.end(); ++b) { newStack(b->second.ID); @@ -1108,7 +1108,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C if(siegeH) { background = BitmapHandler::loadBitmap( siegeH->getSiegeName(0), false ); - ui8 siegeLevel = LOCPLINT->cb->battleGetSiegeLevel(); + ui8 siegeLevel = curInt->cb->battleGetSiegeLevel(); if(siegeLevel >= 2) //citadel or castle { //print moat/mlip @@ -1129,7 +1129,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C } else { - std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; + std::vector< std::string > & backref = graphics->battleBacks[ curInt->cb->battleGetBattlefieldType() ]; background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()], false ); } @@ -1181,7 +1181,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C //loading hero animations if(hero1) // attacking hero { - attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this); + attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == curInt->playerID ? hero1 : NULL, this); attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40 + pos.x, pos.y); } else @@ -1190,7 +1190,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C } if(hero2) // defending hero { - defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this); + defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == curInt->playerID ? hero2 : NULL, this); defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690 + pos.x, pos.y); } else @@ -1275,7 +1275,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen); //preparing obstacle defs - std::vector obst = LOCPLINT->cb->battleGetAllObstacles(); + std::vector obst = curInt->cb->battleGetAllObstacles(); for(int t=0; theroh->obstacles[obst[t].ID].defName); @@ -1330,29 +1330,29 @@ CBattleInterface::~CBattleInterface() delete g->second; delete siegeH; - LOCPLINT->battleInt = NULL; + curInt->battleInt = NULL; } void CBattleInterface::setPrintCellBorders(bool set) { - LOCPLINT->sysOpts.printCellBorders = set; - LOCPLINT->sysOpts.settingsChanged(); + curInt->sysOpts.printCellBorders = set; + curInt->sysOpts.settingsChanged(); redrawBackgroundWithHexes(activeStack); GH.totalRedraw(); } void CBattleInterface::setPrintStackRange(bool set) { - LOCPLINT->sysOpts.printStackRange = set; - LOCPLINT->sysOpts.settingsChanged(); + curInt->sysOpts.printStackRange = set; + curInt->sysOpts.settingsChanged(); redrawBackgroundWithHexes(activeStack); GH.totalRedraw(); } void CBattleInterface::setPrintMouseShadow(bool set) { - LOCPLINT->sysOpts.printMouseShadow = set; - LOCPLINT->sysOpts.settingsChanged(); + curInt->sysOpts.printMouseShadow = set; + curInt->sysOpts.settingsChanged(); } void CBattleInterface::activate() @@ -1377,7 +1377,7 @@ void CBattleInterface::activate() attackingHero->activate(); if(defendingHero) defendingHero->activate(); - if(LOCPLINT->sysOpts.showQueue) + if(curInt->sysOpts.showQueue) queue->activate(); LOCPLINT->cingconsole->activate(); @@ -1405,7 +1405,7 @@ void CBattleInterface::deactivate() attackingHero->deactivate(); if(defendingHero) defendingHero->deactivate(); - if(LOCPLINT->sysOpts.showQueue) + if(curInt->sysOpts.showQueue) queue->deactivate(); LOCPLINT->cingconsole->deactivate(); @@ -1413,7 +1413,7 @@ void CBattleInterface::deactivate() void CBattleInterface::show(SDL_Surface * to) { - std::map stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places + std::map stacks = curInt->cb->battleGetStacks(); //used in a few places ++animCount; if(!to) //"evaluating" to to = screen; @@ -1431,7 +1431,7 @@ void CBattleInterface::show(SDL_Surface * to) { //showing background blitAt(background, pos.x, pos.y, to); - if(LOCPLINT->sysOpts.printCellBorders) + if(curInt->sysOpts.printCellBorders) { CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, &pos); } @@ -1454,7 +1454,7 @@ void CBattleInterface::show(SDL_Surface * to) //calculating spell schoold level const CSpell & spToCast = CGI->spellh->spells[spellToCast->additionalInfo]; ui8 schoolLevel = 0; - if( LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned ) + if( curInt->cb->battleGetStackByID(activeStack)->attackerOwned ) { if(attackingHeroInstance) schoolLevel = attackingHeroInstance->getSpellSchoolLevel(&spToCast); @@ -1468,7 +1468,7 @@ void CBattleInterface::show(SDL_Surface * to) std::set shaded = spToCast.rangeInHexes(b, schoolLevel); for(std::set::iterator it = shaded.begin(); it != shaded.end(); ++it) //for spells with range greater then one hex { - if(LOCPLINT->sysOpts.printMouseShadow && (*it % BFIELD_WIDTH != 0) && (*it % BFIELD_WIDTH != 16)) + if(curInt->sysOpts.printMouseShadow && (*it % BFIELD_WIDTH != 0) && (*it % BFIELD_WIDTH != 16)) { int x = 14 + ((*it/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(*it%BFIELD_WIDTH) + pos.x; int y = 86 + 42 * (*it/BFIELD_WIDTH) + pos.y; @@ -1476,7 +1476,7 @@ void CBattleInterface::show(SDL_Surface * to) } } } - else if(LOCPLINT->sysOpts.printMouseShadow) //when not casting spell + else if(curInt->sysOpts.printMouseShadow) //when not casting spell { int x = 14 + ((b/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%BFIELD_WIDTH) + pos.x; int y = 86 + 42 * (b/BFIELD_WIDTH) + pos.y; @@ -1493,7 +1493,7 @@ void CBattleInterface::show(SDL_Surface * to) SDL_SetClipRect(to, &pos); //preparing obstacles to be shown - std::vector obstacles = LOCPLINT->cb->battleGetAllObstacles(); + std::vector obstacles = curInt->cb->battleGetAllObstacles(); std::multimap hexToObstacle; for(int b=0; b &images = idToObstacle[curOb.ID]->ourImages; //reference to animation of obstacle - blitAt(images[((animCount+1)/(4/LOCPLINT->sysOpts.animSpeed))%images.size()].bitmap, x, y, to); + blitAt(images[((animCount+1)/(4/curInt->sysOpts.animSpeed))%images.size()].bitmap, x, y, to); } //showing wall pieces @@ -1659,7 +1659,7 @@ void CBattleInterface::show(SDL_Surface * to) Rect posWithQueue = Rect(pos.x, pos.y, 800, 600); - if(LOCPLINT->sysOpts.showQueue) + if(curInt->sysOpts.showQueue) { if(!queue->embedded) { @@ -1677,19 +1677,19 @@ void CBattleInterface::show(SDL_Surface * to) //printing border around interface if(screen->w != 800 || screen->h !=600) { - CMessage::drawBorder(LOCPLINT->playerID,to,posWithQueue.w + 28, posWithQueue.h + 28, posWithQueue.x-14, posWithQueue.y-15); + CMessage::drawBorder(curInt->playerID,to,posWithQueue.w + 28, posWithQueue.h + 28, posWithQueue.x-14, posWithQueue.y-15); } } void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key) { if(key.keysym.sym == SDLK_q && key.state == SDL_PRESSED) { - if(LOCPLINT->sysOpts.showQueue) //hide queue + if(curInt->sysOpts.showQueue) //hide queue hideQueue(); else showQueue(); - LOCPLINT->sysOpts.settingsChanged(); + curInt->sysOpts.settingsChanged(); } else if(key.keysym.sym == SDLK_ESCAPE && spellDestSelectMode) { @@ -1722,11 +1722,11 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) { if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end()) { - const CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber); - const CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack); + const CStack *shere = curInt->cb->battleGetStackByPos(myNumber); + const CStack *sactive = curInt->cb->battleGetStackByID(activeStack); if(shere) { - if(shere->owner == LOCPLINT->playerID) //our stack + if(shere->owner == curInt->playerID) //our stack { CGI->curh->changeGraphic(1,5); //setting console text @@ -1740,13 +1740,13 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) creAnims[shere->ID]->playOnce(1); } } - else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy + else if(curInt->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy { CGI->curh->changeGraphic(1,3); //setting console text char buf[500]; //calculating estimated dmg - std::pair estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID); + std::pair estimatedDmg = curInt->cb->battleEstimateDamage(sactive->ID, shere->ID); std::ostringstream estDmg; estDmg << estimatedDmg.first << " - " << estimatedDmg.second; //printing @@ -1774,7 +1774,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) sectorCursor.push_back(12); sectorCursor.push_back(7); - const bool doubleWide = LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE); + const bool doubleWide = curInt->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE); bool aboveAttackable = true, belowAttackable = true; // Exclude directions which cannot be attacked from. @@ -1896,7 +1896,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) //setting console info char buf[500]; //calculating estimated dmg - std::pair estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID); + std::pair estimatedDmg = curInt->cb->battleEstimateDamage(sactive->ID, shere->ID); std::ostringstream estDmg; estDmg << estimatedDmg.first << " - " << estimatedDmg.second; //printing @@ -1927,7 +1927,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) else //available tile { //setting console text and cursor - const CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack); + const CStack *sactive = curInt->cb->battleGetStackByID(activeStack); if(sactive) //there can be a moment when stack is dead ut next is not yet activated { char buf[500]; @@ -1969,7 +1969,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) else { //get dead stack if we cast resurrection or animate dead - const CStack * stackUnder = LOCPLINT->cb->battleGetStackByPos(myNumber, spellToCast->additionalInfo != 38 && spellToCast->additionalInfo != 39); + const CStack * stackUnder = curInt->cb->battleGetStackByPos(myNumber, spellToCast->additionalInfo != 38 && spellToCast->additionalInfo != 39); if(stackUnder && spellToCast->additionalInfo == 39 && !stackUnder->hasFeatureOfType(StackFeature::UNDEAD)) //animate dead can be cast only on undead creatures stackUnder = NULL; @@ -1978,10 +1978,10 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) switch(spellSelMode) { case 1: - whichCase = stackUnder && LOCPLINT->playerID == stackUnder->owner; + whichCase = stackUnder && curInt->playerID == stackUnder->owner; break; case 2: - whichCase = stackUnder && LOCPLINT->playerID != stackUnder->owner; + whichCase = stackUnder && curInt->playerID != stackUnder->owner; break; case 3: whichCase = stackUnder; @@ -2064,10 +2064,10 @@ void CBattleInterface::bFleef() if(spellDestSelectMode) //we are casting a spell return; - if( LOCPLINT->cb->battleCanFlee() ) + if( curInt->cb->battleCanFlee() ) { CFunctionList ony = boost::bind(&CBattleInterface::reallyFlee,this); - LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, 0, false); + curInt->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector(), ony, 0, false); } else { @@ -2075,17 +2075,17 @@ void CBattleInterface::bFleef() std::string heroName; //calculating fleeing hero's name if(attackingHeroInstance) - if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) + if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) heroName = attackingHeroInstance->name; if(defendingHeroInstance) - if(defendingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) + if(defendingHeroInstance->tempOwner == curInt->cb->getMyColor()) heroName = defendingHeroInstance->name; //calculating text char buffer[1000]; sprintf(buffer, CGI->generaltexth->allTexts[340].c_str(), heroName.c_str()); //printing message - LOCPLINT->showInfoDialog(std::string(buffer), comps); + curInt->showInfoDialog(std::string(buffer), comps); } } @@ -2109,11 +2109,11 @@ void CBattleInterface::bSpellf() CGI->curh->changeGraphic(0,0); const CGHeroInstance * chi = NULL; - if(attackingHeroInstance->tempOwner == LOCPLINT->playerID) + if(attackingHeroInstance->tempOwner == curInt->playerID) chi = attackingHeroInstance; else chi = defendingHeroInstance; - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), chi); + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), chi, curInt); GH.pushInt(spellWindow); } @@ -2153,7 +2153,7 @@ void CBattleInterface::bConsoleDownf() void CBattleInterface::newStack(int stackID) { - const CStack * newStack = LOCPLINT->cb->battleGetStackByID(stackID); + const CStack * newStack = curInt->cb->battleGetStackByID(stackID); Point coords = CBattleHex::getXYUnitAnim(newStack->position, newStack->owner == attackingHeroInstance->tempOwner, newStack, this);; @@ -2209,11 +2209,11 @@ void CBattleInterface::newRound(int number) console->addText(CGI->generaltexth->allTexts[412]); //unlock spellbook - //bSpell->block(!LOCPLINT->cb->battleCanCastSpell()); + //bSpell->block(!curInt->cb->battleCanCastSpell()); //don't unlock spellbook - this should be done when we have axctive creature //handle regeneration - std::map stacks = LOCPLINT->cb->battleGetStacks(); + std::map stacks = curInt->cb->battleGetStacks(); for(std::map::const_iterator it = stacks.begin(); it != stacks.end(); ++it) { if( it->second.hasFeatureOfType(StackFeature::HP_REGENERATION) && it->second.alive() ) @@ -2229,12 +2229,12 @@ void CBattleInterface::newRound(int number) void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional) { - if(!LOCPLINT->cb->battleGetStackByID(stack) && action != 1 && action != 4 && action != 5) + if(!curInt->cb->battleGetStackByID(stack) && action != 1 && action != 4 && action != 5) { return; } BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack() - ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false; + ba->side = defendingHeroInstance ? (curInt->playerID == defendingHeroInstance->tempOwner) : false; ba->actionType = action; ba->destinationTile = tile; ba->stackNumber = stack; @@ -2244,7 +2244,7 @@ void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 addit switch(action) { case 6: - assert(LOCPLINT->cb->battleGetStackByPos(additional)); //stack to attack must exist + assert(curInt->cb->battleGetStackByPos(additional)); //stack to attack must exist case 2: case 7: case 9: assert(tile < BFIELD_SIZE); break; @@ -2267,7 +2267,7 @@ bool CBattleInterface::isTileAttackable(const int & number) const bool CBattleInterface::blockedByObstacle(int hex) const { - std::vector obstacles = LOCPLINT->cb->battleGetAllObstacles(); + std::vector obstacles = curInt->cb->battleGetAllObstacles(); std::set coveredHexes; for(int b = 0; b < obstacles.size(); ++b) { @@ -2283,16 +2283,16 @@ bool CBattleInterface::isCatapultAttackable(int hex) const if(!siegeH) return false; - int wallUnder = LOCPLINT->cb->battleGetWallUnderHex(hex); + int wallUnder = curInt->cb->battleGetWallUnderHex(hex); if(wallUnder == -1) return false; - return LOCPLINT->cb->battleGetWallState(wallUnder) < 3; + return curInt->cb->battleGetWallState(wallUnder) < 3; } void CBattleInterface::hexLclicked(int whichOne) { - const CStack * actSt = LOCPLINT->cb->battleGetStackByID(activeStack); + const CStack * actSt = curInt->cb->battleGetStackByID(activeStack); if( ((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack || (actSt->hasFeatureOfType(StackFeature::CATAPULT) && !spellDestSelectMode ) ) @@ -2307,15 +2307,15 @@ void CBattleInterface::hexLclicked(int whichOne) switch(spellSelMode) { case 1: - if(!LOCPLINT->cb->battleGetStackByPos(whichOne, onlyAlive) || LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(whichOne, onlyAlive)->owner ) + if(!curInt->cb->battleGetStackByPos(whichOne, onlyAlive) || curInt->playerID != curInt->cb->battleGetStackByPos(whichOne, onlyAlive)->owner ) allowCasting = false; break; case 2: - if(!LOCPLINT->cb->battleGetStackByPos(whichOne, onlyAlive) || LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(whichOne, onlyAlive)->owner ) + if(!curInt->cb->battleGetStackByPos(whichOne, onlyAlive) || curInt->playerID == curInt->cb->battleGetStackByPos(whichOne, onlyAlive)->owner ) allowCasting = false; break; case 3: - if(!LOCPLINT->cb->battleGetStackByPos(whichOne, onlyAlive)) + if(!curInt->cb->battleGetStackByPos(whichOne, onlyAlive)) allowCasting = false; break; case 4: @@ -2327,23 +2327,23 @@ void CBattleInterface::hexLclicked(int whichOne) if(allowCasting) { spellToCast->destinationTile = whichOne; - LOCPLINT->cb->battleMakeAction(spellToCast); + curInt->cb->battleMakeAction(spellToCast); endCastingSpell(); } } else //we don't cast any spell { - const CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one + const CStack* dest = curInt->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one if(!dest || !dest->alive()) //no creature at that tile { - const CStack * sactive = LOCPLINT->cb->battleGetStackByID(activeStack); + const CStack * sactive = curInt->cb->battleGetStackByID(activeStack); if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range { CGI->curh->changeGraphic(1, 6); //cursor should be changed - if(LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE)) + if(curInt->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE)) { - std::vector acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false); - int shiftedDest = whichOne + (LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned ? 1 : -1); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); + int shiftedDest = whichOne + (curInt->cb->battleGetStackByID(activeStack)->attackerOwned ? 1 : -1); if(vstd::contains(acc, whichOne)) giveCommand(2,whichOne,activeStack); else if(vstd::contains(acc, shiftedDest)) @@ -2360,21 +2360,22 @@ void CBattleInterface::hexLclicked(int whichOne) } } else if(dest->owner != actSt->owner - && LOCPLINT->cb->battleCanShoot(activeStack, whichOne) ) //shooting + && curInt->cb->battleCanShoot(activeStack, whichOne) ) //shooting { CGI->curh->changeGraphic(1, 6); //cursor should be changed giveCommand(7,whichOne,activeStack); } else if(dest->owner != actSt->owner) //attacking { - const CStack * actStack = LOCPLINT->cb->battleGetStackByID(activeStack); + const CStack * actStack = curInt->cb->battleGetStackByID(activeStack); int attackFromHex = -1; //hex from which we will attack chosen stack switch(CGI->curh->number) { case 12: //from bottom right { - bool doubleWide = LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE); - int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ) + doubleWide; + bool doubleWide = actStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE); + int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ) + + (actStack->attackerOwned && doubleWide ? 1 : 0); if(vstd::contains(shadedHexes, destHex)) attackFromHex = destHex; else if(actStack->attackerOwned) //if we are attacker @@ -2408,9 +2409,9 @@ void CBattleInterface::hexLclicked(int whichOne) } case 8: //from left { - if(LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && !LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned) + if(actStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && !actStack->attackerOwned) { - std::vector acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne - 1; else @@ -2441,8 +2442,9 @@ void CBattleInterface::hexLclicked(int whichOne) } case 10: //from top right { - bool doubleWide = LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE); - int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ) + doubleWide; + bool doubleWide = actStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE); + int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ) + + (actStack->attackerOwned && doubleWide ? 1 : 0); if(vstd::contains(shadedHexes, destHex)) attackFromHex = destHex; else if(actStack->attackerOwned) //if we are attacker @@ -2459,9 +2461,9 @@ void CBattleInterface::hexLclicked(int whichOne) } case 11: //from right { - if(LOCPLINT->cb->battleGetStackByID(activeStack)->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned) + if(actStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && actStack->attackerOwned) { - std::vector acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false); + std::vector acc = curInt->cb->battleGetAvailableHexes(activeStack, false); if(vstd::contains(acc, whichOne)) attackFromHex = whichOne + 1; else @@ -2478,7 +2480,7 @@ void CBattleInterface::hexLclicked(int whichOne) int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ); if(vstd::contains(shadedHexes, destHex)) attackFromHex = destHex; - else if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) //if we are attacker + else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker { if(vstd::contains(shadedHexes, destHex+1)) attackFromHex = destHex+1; @@ -2495,7 +2497,7 @@ void CBattleInterface::hexLclicked(int whichOne) int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ); if(vstd::contains(shadedHexes, destHex)) attackFromHex = destHex; - else if(attackingHeroInstance->tempOwner == LOCPLINT->cb->getMyColor()) //if we are attacker + else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker { if(vstd::contains(shadedHexes, destHex+1)) attackFromHex = destHex+1; @@ -2534,16 +2536,16 @@ void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca) SDL_FreeSurface(siegeH->walls[it->first.first + 2]); siegeH->walls[it->first.first + 2] = BitmapHandler::loadBitmap( - siegeH->getSiegeName(it->first.first + 2, LOCPLINT->cb->battleGetWallState(it->first.first)) ); + siegeH->getSiegeName(it->first.first + 2, curInt->cb->battleGetWallState(it->first.first)) ); } } void CBattleInterface::battleFinished(const BattleResult& br) { bresult = &br; - LOCPLINT->pim->unlock(); + curInt->pim->unlock(); animsAreDisplayed.waitUntil(false); - LOCPLINT->pim->lock(); + curInt->pim->lock(); displayBattleFinished(); } @@ -2561,7 +2563,7 @@ void CBattleInterface::spellCast(SpellCast * sc) { CSpell &spell = CGI->spellh->spells[sc->id]; - if(sc->side == !LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned) + if(sc->side == !curInt->cb->battleGetStackByID(activeStack)->attackerOwned) bSpell->block(true); std::vector< std::string > anims; //for magic arrow and ice bolt @@ -2587,7 +2589,7 @@ void CBattleInterface::spellCast(SpellCast * sc) //initial variables std::string animToDisplay; Point srccoord = (sc->side ? Point(770, 60) : Point(30, 60)) + pos; - Point destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow + Point destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, curInt->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow destcoord.x += 250; destcoord.y += 240; //animation angle @@ -2628,7 +2630,7 @@ void CBattleInterface::spellCast(SpellCast * sc) case 39: //animate dead for(std::set::const_iterator it = sc->affectedCres.begin(); it != sc->affectedCres.end(); ++it) { - displayEffect(spell.mainEffectAnim, LOCPLINT->cb->battleGetStackByID(*it, false)->position); + displayEffect(spell.mainEffectAnim, curInt->cb->battleGetStackByID(*it, false)->position); } break; case 66: case 67: case 68: case 69: //summon elemental @@ -2639,7 +2641,7 @@ void CBattleInterface::spellCast(SpellCast * sc) //support for resistance for(int j=0; jresisted.size(); ++j) { - int tile = LOCPLINT->cb->battleGetStackByID(sc->resisted[j])->position; + int tile = curInt->cb->battleGetStackByID(sc->resisted[j])->position; displayEffect(78, tile); } @@ -2647,15 +2649,15 @@ void CBattleInterface::spellCast(SpellCast * sc) if(sc->affectedCres.size() == 1) { std::string text = CGI->generaltexth->allTexts[195]; - boost::algorithm::replace_first(text, "%s", LOCPLINT->cb->battleGetFightingHero(sc->side)->name); + boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetFightingHero(sc->side)->name); boost::algorithm::replace_first(text, "%s", CGI->spellh->spells[sc->id].name); - boost::algorithm::replace_first(text, "%s", LOCPLINT->cb->battleGetStackByID(*sc->affectedCres.begin(), false)->creature->namePl ); + boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetStackByID(*sc->affectedCres.begin(), false)->creature->namePl ); console->addText(text); } else { std::string text = CGI->generaltexth->allTexts[196]; - boost::algorithm::replace_first(text, "%s", LOCPLINT->cb->battleGetFightingHero(sc->side)->name); + boost::algorithm::replace_first(text, "%s", curInt->cb->battleGetFightingHero(sc->side)->name); boost::algorithm::replace_first(text, "%s", CGI->spellh->spells[sc->id].name); console->addText(text); } @@ -2671,7 +2673,7 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse) { for(std::set::const_iterator ci = sse.stacks.begin(); ci!=sse.stacks.end(); ++ci) { - displayEffect(CGI->spellh->spells[sse.effect.id].mainEffectAnim, LOCPLINT->cb->battleGetStackByID(*ci)->position); + displayEffect(CGI->spellh->spells[sse.effect.id].mainEffectAnim, curInt->cb->battleGetStackByID(*ci)->position); } redrawBackgroundWithHexes(activeStack); } @@ -2682,13 +2684,13 @@ void CBattleInterface::castThisSpell(int spellID) ba->actionType = 1; ba->additionalInfo = spellID; //spell number ba->destinationTile = -1; - ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2; - ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false; + ba->stackNumber = (attackingHeroInstance->tempOwner == curInt->playerID) ? -1 : -2; + ba->side = defendingHeroInstance ? (curInt->playerID == defendingHeroInstance->tempOwner) : false; spellToCast = ba; spellDestSelectMode = true; //choosing possible tragets - const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance; + const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == curInt->playerID) ? attackingHeroInstance : attackingHeroInstance; spellSelMode = 0; if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos) //spell to be cast on one specific creature { @@ -2739,7 +2741,7 @@ void CBattleInterface::castThisSpell(int spellID) if(spellSelMode == -1) //user does not have to select location { spellToCast->destinationTile = -1; - LOCPLINT->cb->battleMakeAction(spellToCast); + curInt->cb->battleMakeAction(spellToCast); endCastingSpell(); } else @@ -2755,27 +2757,30 @@ void CBattleInterface::displayEffect(ui32 effect, int destTile) void CBattleInterface::setAnimSpeed(int set) { - LOCPLINT->sysOpts.animSpeed = set; - LOCPLINT->sysOpts.settingsChanged(); + curInt->sysOpts.animSpeed = set; + curInt->sysOpts.settingsChanged(); } int CBattleInterface::getAnimSpeed() const { - return LOCPLINT->sysOpts.animSpeed; - LOCPLINT->sysOpts.settingsChanged(); + return curInt->sysOpts.animSpeed; + curInt->sysOpts.settingsChanged(); } void CBattleInterface::activateStack() { activeStack = stackToActivate; stackToActivate = -1; + myTurn = true; + curInt = attackerInt->playerID == LOCPLINT->cb->battleGetStackByID(activeStack)->owner ? attackerInt : defenderInt; + queue->update(); redrawBackgroundWithHexes(activeStack); - bWait->block(vstd::contains(LOCPLINT->cb->battleGetStackByID(activeStack)->state,WAITING)); //block waiting button if stack has been already waiting + bWait->block(vstd::contains(curInt->cb->battleGetStackByID(activeStack)->state, WAITING)); //block waiting button if stack has been already waiting //block cast spell button if hero doesn't have a spellbook - bSpell->block(!LOCPLINT->cb->battleCanCastSpell()); + bSpell->block(!curInt->cb->battleCanCastSpell()); GH.fakeMouseMove(); @@ -2785,7 +2790,7 @@ void CBattleInterface::activateStack() float CBattleInterface::getAnimSpeedMultiplier() const { - switch(LOCPLINT->sysOpts.animSpeed) + switch(curInt->sysOpts.animSpeed) { case 1: return 3.5f; @@ -2816,7 +2821,7 @@ void CBattleInterface::showAliveStack(int ID, const std::map & stac const CStack &curStack = stacks.find(ID)->second; int animType = creAnims[ID]->getType(); - int affectingSpeed = LOCPLINT->sysOpts.animSpeed; + int affectingSpeed = curInt->sysOpts.animSpeed; if(animType == 1 || animType == 2) //standing stacks should not stand faster :) affectingSpeed = 2; bool incrementFrame = (animCount%(4/affectingSpeed)==0) && animType!=5 && animType!=20 && animType!=2; @@ -2848,10 +2853,10 @@ void CBattleInterface::showAliveStack(int ID, const std::map & stac //printing amount if(curStack.amount > 0 //don't print if stack is not alive - && (!LOCPLINT->curAction - || (LOCPLINT->curAction->stackNumber != ID //don't print if stack is currently taking an action - && (LOCPLINT->curAction->actionType != 6 || curStack.position != LOCPLINT->curAction->additionalInfo) //nor if it's an object of attack - && (LOCPLINT->curAction->destinationTile != curStack.position) //nor if it's on destination tile for current action + && (!curInt->curAction + || (curInt->curAction->stackNumber != ID //don't print if stack is currently taking an action + && (curInt->curAction->actionType != 6 || curStack.position != curInt->curAction->additionalInfo) //nor if it's an object of attack + && (curInt->curAction->destinationTile != curStack.position) //nor if it's on destination tile for current action ) ) && !curStack.hasFeatureOfType(StackFeature::SIEGE_WEAPON) //and not a war machine... @@ -2967,14 +2972,14 @@ void CBattleInterface::showPieceOfWall(SDL_Surface * to, int hex, const std::map void CBattleInterface::redrawBackgroundWithHexes(int activeStack) { - shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack, true); + shadedHexes = curInt->cb->battleGetAvailableHexes(activeStack, true); //preparating background graphic with hexes and shaded hexes blitAt(background, 0, 0, backgroundWithHexes); - if(LOCPLINT->sysOpts.printCellBorders) + if(curInt->sysOpts.printCellBorders) CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL); - if(LOCPLINT->sysOpts.printStackRange) + if(curInt->sysOpts.printStackRange) { for(size_t m=0; mcb->battleGetStackByID(IDby, false); - const CStack * defender = LOCPLINT->cb->battleGetStackByID(ID, false); + const CStack * attacker = curInt->cb->battleGetStackByID(IDby, false); + const CStack * defender = curInt->cb->battleGetStackByID(ID, false); int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker->amount > 1 ? 377 : 376].c_str(), (attacker->amount > 1 ? attacker->creature->namePl.c_str() : attacker->creature->nameSing.c_str()), dmg); @@ -3085,7 +3090,7 @@ void CBattleInterface::endAction(const BattleAction* action) void CBattleInterface::hideQueue() { - LOCPLINT->sysOpts.showQueue = false; + curInt->sysOpts.showQueue = false; queue->deactivate(); @@ -3098,7 +3103,7 @@ void CBattleInterface::hideQueue() void CBattleInterface::showQueue() { - LOCPLINT->sysOpts.showQueue = true; + curInt->sysOpts.showQueue = true; queue->activate(); @@ -3111,7 +3116,7 @@ void CBattleInterface::showQueue() void CBattleInterface::startAction(const BattleAction* action) { - const CStack *stack = LOCPLINT->cb->battleGetStackByID(action->stackNumber); + const CStack *stack = curInt->cb->battleGetStackByID(action->stackNumber); if(stack) { @@ -3274,7 +3279,7 @@ void CBattleHero::clickLeft(tribool down, bool previousState) if(myOwner->spellDestSelectMode) //we are casting a spell return; - if(!down && myHero && LOCPLINT->cb->battleCanCastSpell()) //check conditions + if(!down && myHero && myOwner->curInt->cb->battleCanCastSpell()) //check conditions { for(int it=0; itcurh->changeGraphic(0,0); - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero); + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt); GH.pushInt(spellWindow); } } @@ -3369,7 +3374,7 @@ Point CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const } } //returning - return ret + LOCPLINT->battleInt->pos; + return ret +CPlayerInterface::battleInt->pos; } void CBattleHex::activate() { @@ -3418,12 +3423,12 @@ void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) if(hovered && strictHovered) //print attacked creature to console { - if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 && - LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID && - LOCPLINT->cb->battleGetStackByPos(myNumber)->alive()) + if(myInterface->console->alterTxt.size() == 0 && myInterface->curInt->cb->battleGetStack(myNumber) != -1 && + myInterface->curInt->cb->battleGetStackByPos(myNumber)->owner != myInterface->curInt->playerID && + myInterface->curInt->cb->battleGetStackByPos(myNumber)->alive()) { char tabh[160]; - const CStack * attackedStack = LOCPLINT->cb->battleGetStackByPos(myNumber); + const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber); const std::string & attackedName = attackedStack->amount == 1 ? attackedStack->creature->nameSing : attackedStack->creature->namePl; sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); myInterface->console->alterTxt = std::string(tabh); @@ -3447,10 +3452,10 @@ void CBattleHex::clickLeft(tribool down, bool previousState) void CBattleHex::clickRight(tribool down, bool previousState) { - int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile + int stID = myInterface->curInt->cb->battleGetStack(myNumber); //id of stack being on this tile if(hovered && strictHovered && stID!=-1) { - const CStack & myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info + const CStack & myst = *myInterface->curInt->cb->battleGetStackByID(stID); //stack info if(!myst.alive()) return; StackState *pom = NULL; if(down) @@ -3562,11 +3567,12 @@ void CBattleConsole::scrollDown(unsigned int by) lastShown += by; } -CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner) +CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) +: owner(_owner) { this->pos = pos; background = BitmapHandler::loadBitmap("CPRESULT.BMP", true); - graphics->blueToPlayersAdv(background, LOCPLINT->playerID); + graphics->blueToPlayersAdv(background, owner->curInt->playerID); SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags); SDL_FreeSurface(background); background = pom; @@ -3660,7 +3666,7 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect } } //printing result description - bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner); + bool weAreAttacker = (owner->curInt->playerID == owner->attackingHeroInstance->tempOwner); switch(br.result) { case 0: //normal victory @@ -3727,7 +3733,7 @@ CBattleResultWindow::~CBattleResultWindow() void CBattleResultWindow::activate() { - LOCPLINT->showingDialog->set(true); + owner->curInt->showingDialog->set(true); exit->activate(); } @@ -3751,7 +3757,7 @@ void CBattleResultWindow::show(SDL_Surface *to) void CBattleResultWindow::bExitf() { GH.popInts(2); //first - we; second - battle interface - LOCPLINT->showingDialog->setn(false); + owner->curInt->showingDialog->setn(false); CGI->videoh->close(); } @@ -3759,18 +3765,18 @@ CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInt { pos = position; SDL_Surface *hhlp = BitmapHandler::loadBitmap("comopbck.bmp", true); - graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID); - background = SDL_ConvertSurface(hhlp,screen->format,0); - SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255)); + graphics->blueToPlayersAdv(hhlp, owner->curInt->playerID); + background = SDL_ConvertSurface(hhlp, screen->format, 0); + SDL_SetColorKey(background, SDL_SRCCOLORKEY, SDL_MapRGB(background->format,0,255,255)); SDL_FreeSurface(hhlp); viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false); - viewGrid->select(LOCPLINT->sysOpts.printCellBorders); + viewGrid->select(owner->curInt->sysOpts.printCellBorders); movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false); - movementShadow->select(LOCPLINT->sysOpts.printStackRange); + movementShadow->select(owner->curInt->sysOpts.printStackRange); mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false); - mouseShadow->select(LOCPLINT->sysOpts.printMouseShadow); + mouseShadow->select(owner->curInt->sysOpts.printMouseShadow); animSpeeds = new CHighlightableButtonsGroup(0); animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def",188, 309, 1); @@ -3995,15 +4001,15 @@ void CBattleInterface::SiegeHelper::printPartOfWall(SDL_Surface * to, int what) void CStackQueue::update() { stacksSorted.clear(); - LOCPLINT->cb->getStackQueue(stacksSorted, QUEUE_SIZE); + owner->curInt->cb->getStackQueue(stacksSorted, QUEUE_SIZE); for (int i = 0; i < QUEUE_SIZE ; i++) { stackBoxes[i]->setStack(stacksSorted[i]); } } -CStackQueue::CStackQueue(bool Embedded) -:embedded(Embedded) +CStackQueue::CStackQueue(bool Embedded, CBattleInterface * _owner) +:embedded(Embedded), owner(_owner) { OBJ_CONSTRUCTION_CAPTURING_ALL; if(embedded) diff --git a/client/CBattleInterface.h b/client/CBattleInterface.h index 517119a7a..3d3a7f397 100644 --- a/client/CBattleInterface.h +++ b/client/CBattleInterface.h @@ -300,8 +300,9 @@ class CBattleResultWindow : public CIntObject private: SDL_Surface * background; AdventureMapButton * exit; + CBattleInterface * owner; public: - CBattleResultWindow(const BattleResult & br, const SDL_Rect & pos, const CBattleInterface * owner); //c-tor + CBattleResultWindow(const BattleResult & br, const SDL_Rect & pos, CBattleInterface * _owner); //c-tor ~CBattleResultWindow(); //d-tor void bExitf(); //exit button callback @@ -362,9 +363,10 @@ public: SDL_Surface *box; SDL_Surface *bg; + CBattleInterface * owner; void showAll(SDL_Surface *to); - CStackQueue(bool Embedded); + CStackQueue(bool Embedded, CBattleInterface * _owner); ~CStackQueue(); void update(); void blitBg( SDL_Surface * to ); @@ -383,7 +385,7 @@ private: CCreatureSet * army1, * army2; //fighting armies CGHeroInstance * attackingHeroInstance, * defendingHeroInstance; std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID) - std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler) + std::map< int, CDefHandler * > idToProjectile; //projectiles of creatures (creatureID, defhandler) std::map< int, CDefHandler * > idToObstacle; //obstacles located on the battlefield std::map< int, bool > creDir; // unsigned char animCount; @@ -398,9 +400,9 @@ private: std::map standingFrame; //number of frame in standing animation by stack ID, helps in showing 'random moves' bool spellDestSelectMode; //if true, player is choosing destination for his spell - int spellSelMode; //0 - any location, 1 - any firendly creature, 2 - any hostile creature, 3 - any creature, 4 - obstacle,z -1 - no location + int spellSelMode; //0 - any location, 1 - any friendly creature, 2 - any hostile creature, 3 - any creature, 4 - obstacle,z -1 - no location BattleAction * spellToCast; //spell for which player is choosing destination - void endCastingSpell(); //ends casting spell (eg. when spell has been cast or cancelled) + void endCastingSpell(); //ends casting spell (eg. when spell has been cast or canceled) void showAliveStack(int ID, const std::map & stacks, SDL_Surface * to); //helper function for function show void showPieceOfWall(SDL_Surface * to, int hex, const std::map & stacks); //helper function for show @@ -410,7 +412,7 @@ private: std::list projectiles; //projectiles flying on battlefield void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1); - bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles + bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles bool blockedByObstacle(int hex) const; bool isCatapultAttackable(int hex) const; //returns true if given tile can be attacked by catapult @@ -434,13 +436,16 @@ private: friend class CBattleInterface; } * siegeH; + + CPlayerInterface * attackerInt, * defenderInt; //because LOCPLINT is not enough in hotSeat public: + CPlayerInterface * curInt; //current player interface std::list > pendingAnims; //currently displayed animations void addNewAnim(CBattleAnimation * anim); //adds new anim to pendingAnims unsigned int animIDhelper; //for giving IDs for animations static CondSh animsAreDisplayed; //for waiting with the end of battle for end of anims - CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect); //c-tor + CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen); //c-tor ~CBattleInterface(); //d-tor //std::vector timeinterested; //animation handling diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index de4d879f8..44448b86d 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -1069,7 +1069,7 @@ void CKingdomInterface::CHeroItem::CArtPlace::clickLeft(tribool down, bool previ { if(type == 0) { - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (screen->w - 620)/2, (screen->h - 595)/2), hero->hero); + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (screen->w - 620)/2, (screen->h - 595)/2), hero->hero, LOCPLINT); GH.pushInt(spellWindow); } else diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 24041d78f..b47caa93d 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -69,6 +69,9 @@ extern std::queue events; extern boost::mutex eventsM; CPlayerInterface * LOCPLINT; + +CBattleInterface * CPlayerInterface::battleInt; + enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE}; CondSh stillMoveHero; //used during hero movement @@ -530,11 +533,15 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, void CPlayerInterface::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side) //called by engine when battle starts; side=0 - left, side=1 - right { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + while(showingDialog->get()) SDL_Delay(20); boost::unique_lock un(*pim); - /*battleInt = */new CBattleInterface(army1, army2, hero1, hero2, genRect(600, 800, (conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2)); CGI->musich->playMusicFromSet(CGI->musich->battleMusics, -1); GH.pushInt(battleInt); } @@ -545,6 +552,11 @@ void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector > & healedStacks) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + for(int b=0; bbattleGetStackByID(healedStacks[b].first); @@ -558,12 +570,22 @@ void CPlayerInterface::battleStacksHealedRes(const std::vectornewStack(stackID); } void CPlayerInterface::battleObstaclesRemoved(const std::set & removedObstacles) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + for(std::set::const_iterator it = removedObstacles.begin(); it != removedObstacles.end(); ++it) { for(std::map< int, CDefHandler * >::iterator itBat = battleInt->idToObstacle.begin(); itBat != battleInt->idToObstacle.end(); ++itBat) @@ -581,11 +603,21 @@ void CPlayerInterface::battleObstaclesRemoved(const std::set & removedObst void CPlayerInterface::battleCatapultAttacked(const CatapultAttack & ca) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + battleInt->stackIsCatapulting(ca); } void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + for(std::set::const_iterator it = bsr.stackIDs.begin(); it != bsr.stackIDs.end(); ++it) //for each removed stack { battleInt->stackRemoved(*it); @@ -594,12 +626,22 @@ void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr) void CPlayerInterface::battleNewRound(int round) //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); battleInt->newRound(round); } void CPlayerInterface::actionStarted(const BattleAction* action) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); curAction = new BattleAction(*action); battleInt->startAction(action); @@ -607,6 +649,11 @@ void CPlayerInterface::actionStarted(const BattleAction* action) void CPlayerInterface::actionFinished(const BattleAction* action) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); delete curAction; curAction = NULL; @@ -615,6 +662,7 @@ void CPlayerInterface::actionFinished(const BattleAction* action) BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack { + CBattleInterface *b = battleInt; { boost::unique_lock un(*pim); @@ -646,27 +694,52 @@ BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn void CPlayerInterface::battleEnd(BattleResult *br) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); battleInt->battleFinished(*br); } void CPlayerInterface::battleStackMoved(int ID, int dest, int distance, bool end) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); battleInt->stackMoved(ID, dest, end, distance); } void CPlayerInterface::battleSpellCast(SpellCast *sc) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); battleInt->spellCast(sc); } void CPlayerInterface::battleStacksEffectsSet(SetStackEffect & sse) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + boost::unique_lock un(*pim); battleInt->battleStacksEffectsSet(sse); } void CPlayerInterface::battleStacksAttacked(std::set & bsa) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + tlog5 << "CPlayerInterface::battleStackAttacked - locking..."; boost::unique_lock un(*pim); tlog5 << "done!\n"; @@ -694,6 +767,11 @@ void CPlayerInterface::battleStacksAttacked(std::set & bsa) } void CPlayerInterface::battleAttack(BattleAttack *ba) { + if(LOCPLINT != this) + { //another local interface should do this + return; + } + tlog5 << "CPlayerInterface::battleAttack - locking..."; boost::unique_lock un(*pim); tlog5 << "done!\n"; diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 23cc57aef..641eee64d 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -123,7 +123,7 @@ public: CAdvMapInt * adventureInt; CCastleInterface * castleInt; //NULL if castle window isn't opened - CBattleInterface * battleInt; //NULL if no battle + static CBattleInterface * battleInt; //NULL if no battle FPSmanager * mainFPSmng; //to keep const framerate CInGameConsole * cingconsole; diff --git a/client/CSpellWindow.cpp b/client/CSpellWindow.cpp index dec21a78a..8ea212c05 100644 --- a/client/CSpellWindow.cpp +++ b/client/CSpellWindow.cpp @@ -30,13 +30,15 @@ extern SDL_Surface * screen; extern SDL_Color tytulowy, zwykly, darkTitle; -SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff) +SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, + const std::string & textR, boost::function funcHon, boost::function funcHoff, CPlayerInterface * _myInt) { pos = myRect; onLeft = funcL; textOnRclick = textR; onHoverOn = funcHon; onHoverOff = funcHoff; + myInt = _myInt; } void SpellbookInteractiveArea::clickLeft(tribool down, bool previousState) @@ -49,7 +51,7 @@ void SpellbookInteractiveArea::clickLeft(tribool down, bool previousState) void SpellbookInteractiveArea::clickRight(tribool down, bool previousState) { - LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this); + myInt->adventureInt->handleRightClick(textOnRclick, down, this); } void SpellbookInteractiveArea::hover(bool on) @@ -79,11 +81,12 @@ void SpellbookInteractiveArea::deactivate() deactivateHover(); } -CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, bool openOnBattleSpells): +CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells): battleSpellsOnly(openOnBattleSpells), selectedTab(4), spellSite(0), - myHero(_myHero) + myHero(_myHero), + myInt(_myInt) { //initializing castable spells for(ui32 v=0; vspellh->spells.size(); ++v) @@ -231,29 +234,29 @@ CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHe statusBar = new CStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp"); SDL_Rect temp_rect = genRect(45, 35, 479 + pos.x, 405 + pos.y); - exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar)); + exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(45, 35, 221 + pos.x, 405 + pos.y); - battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar)); + battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(45, 35, 355 + pos.x, 405 + pos.y); - adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar)); + adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(45, 35, 418 + pos.x, 405 + pos.y); - manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CStatusBar::clear, statusBar)); + manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(36, 56, 549 + pos.x, 94 + pos.y); - selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAb, this), CGI->generaltexth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar)); + selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAb, this), CGI->generaltexth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(36, 56, 549 + pos.x, 151 + pos.y); - selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsEb, this), CGI->generaltexth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar)); + selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsEb, this), CGI->generaltexth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(36, 56, 549 + pos.x, 210 + pos.y); - selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsFb, this), CGI->generaltexth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar)); + selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsFb, this), CGI->generaltexth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(36, 56, 549 + pos.x, 270 + pos.y); - selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsWb, this), CGI->generaltexth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar)); + selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsWb, this), CGI->generaltexth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y); - selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAllb, this), CGI->generaltexth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CStatusBar::clear, statusBar)); + selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAllb, this), CGI->generaltexth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(leftCorner->h, leftCorner->w, 97 + pos.x, 77 + pos.y); - lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar)); + lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); temp_rect = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y); - rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CStatusBar::clear, statusBar)); + rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); //areas for spells int xpos = 117 + pos.x, ypos = 90 + pos.y; @@ -464,7 +467,7 @@ void CSpellWindow::show(SDL_Surface *to) blitAt(schoolBorders[bestSchool]->ourImages[bestslvl].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to); SDL_Color firstLineColor, secondLineColor; - if(LOCPLINT->cb->getSpellCost(spell, myHero) > myHero->mana) //hero cannot cast this spell + if(myInt->cb->getSpellCost(spell, myHero) > myHero->mana) //hero cannot cast this spell { firstLineColor = zwykly; secondLineColor = darkTitle; @@ -480,7 +483,7 @@ void CSpellWindow::show(SDL_Surface *to) CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[171 + spell->level], spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 82, FONT_TINY, secondLineColor, to); //printing cost std::ostringstream ss; - ss<generaltexth->allTexts[387]<<": "<cb->getSpellCost(spell, myHero); + ss<generaltexth->allTexts[387]<<": "<cb->getSpellCost(spell, myHero); CSDL_Ext::printAtMiddle(ss.str(), spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 94, FONT_TINY, secondLineColor, to); } @@ -665,13 +668,13 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) { if(!down && mySpell!=-1) { - int spellCost = LOCPLINT->cb->getSpellCost(&CGI->spellh->spells[mySpell], owner->myHero); + int spellCost = owner->myInt->cb->getSpellCost(&CGI->spellh->spells[mySpell], owner->myHero); //we will cast a spell - if(LOCPLINT->battleInt && LOCPLINT->cb->battleCanCastSpell() && spellCost <= owner->myHero->mana) //if battle window is open + if(owner->myInt->battleInt && owner->myInt->cb->battleCanCastSpell() && spellCost <= owner->myHero->mana) //if battle window is open { int spell = mySpell; owner->fexitb(); - LOCPLINT->battleInt->castThisSpell(spell); + owner->myInt->battleInt->castThisSpell(spell); } else { @@ -681,7 +684,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState) std::vector comps; char msgBuf[500]; sprintf(msgBuf, CGI->generaltexth->allTexts[206].c_str(), spellCost, owner->myHero->mana); - LOCPLINT->showInfoDialog(std::string(msgBuf), comps); + owner->myInt->showInfoDialog(std::string(msgBuf), comps); } } } @@ -692,7 +695,7 @@ void CSpellWindow::SpellArea::clickRight(tribool down, bool previousState) if(down && mySpell != -1) { std::string dmgInfo; - int causedDmg = LOCPLINT->cb->estimateSpellDamage( &CGI->spellh->spells[mySpell] ); + int causedDmg = owner->myInt->cb->estimateSpellDamage( &CGI->spellh->spells[mySpell] ); if(causedDmg == 0) dmgInfo = ""; else @@ -702,7 +705,7 @@ void CSpellWindow::SpellArea::clickRight(tribool down, bool previousState) } SDL_Surface *spellBox = CMessage::drawBoxTextBitmapSub( - LOCPLINT->playerID, + owner->myInt->playerID, CGI->spellh->spells[mySpell].descriptions[0] + dmgInfo, this->owner->spells->ourImages[mySpell].bitmap, CGI->spellh->spells[mySpell].name,30,30); CInfoPopup *vinya = new CInfoPopup(spellBox, true); diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index 38809579a..b960a891d 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -29,6 +29,7 @@ private: std::string textOnRclick; boost::function onHoverOn; boost::function onHoverOff; + CPlayerInterface * myInt; public: void clickLeft(tribool down, bool previousState); void clickRight(tribool down, bool previousState); @@ -36,7 +37,8 @@ public: void activate(); void deactivate(); - SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff);//c-tor + SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, + boost::function funcHon, boost::function funcHoff, CPlayerInterface * _myInt);//c-tor }; class CSpellWindow : public CIntObject @@ -84,8 +86,11 @@ private: void turnPageLeft(); void turnPageRight(); + CPlayerInterface * myInt; + public: - CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, bool openOnBattleSpells = true); //c-tor + + CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true); //c-tor ~CSpellWindow(); //d-tor void fexitb(); diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index c5124fc1c..99eb1948a 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -3594,7 +3594,7 @@ void CArtPlace::clickLeft(tribool down, bool previousState) { if(ourArt->id == 0) { - CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ourOwner->curHero); + CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ourOwner->curHero, LOCPLINT); GH.pushInt(spellWindow); } } diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 751540296..3f0d2000c 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -19,6 +19,9 @@ #include #include #include +#include "CConfigHandler.h" +#include "SDL_Extensions.h" +#include "CBattleInterface.h" //macro to avoid code duplication - calls given method with given arguments if interface for specific player is present #define INTERFACE_CALL_IF_PRESENT(player,function,...) \ @@ -405,6 +408,20 @@ void GarrisonDialog::applyCl(CClient *cl) void BattleStart::applyCl( CClient *cl ) { + CPlayerInterface * att, * def; + if(vstd::contains(cl->playerint, info->side1) && cl->playerint[info->side1]->human) + att = static_cast( cl->playerint[info->side1] ); + else + att = NULL; + + if(vstd::contains(cl->playerint, info->side2) && cl->playerint[info->side2]->human) + def = static_cast( cl->playerint[info->side2] ); + else + def = NULL; + + + new CBattleInterface(&info->army1, &info->army2, info->heroes[0], info->heroes[1], genRect(600, 800, (conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2), att, def); + if(vstd::contains(cl->playerint,info->side1)) cl->playerint[info->side1]->battleStart(&info->army1, &info->army2, info->tile, info->heroes[0], info->heroes[1], 0);