From 4af64f1b9f47a6483173a24f73b5df5b12ca4fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 11 Oct 2008 13:14:52 +0000 Subject: [PATCH] * fixed blocked shooter behavior * slowed map scrolling * minor --- CAdvmapInterface.cpp | 55 +++++++++++++++++++++++--------------------- CBattleInterface.cpp | 2 +- CCallback.cpp | 13 +++++++---- CGameInterface.h | 8 +++---- CGameState.cpp | 15 ++++++++++++ CGameState.h | 1 + CPlayerInterface.cpp | 10 ++++---- CPlayerInterface.h | 2 -- client/Client.cpp | 9 +++++++- 9 files changed, 70 insertions(+), 45 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 03521e2a1..3e1bce167 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -1200,40 +1200,43 @@ void CAdvMapInt::update() } ++heroAnim; - if(scrollingLeft) + if(animValHitCount % 4) { - if(position.x>-Woff) + if(scrollingLeft) { - position.x--; - updateScreen = true; - updateMinimap=true; + if(position.x>-Woff) + { + position.x--; + updateScreen = true; + updateMinimap=true; + } } - } - if(scrollingRight) - { - if(position.xmh->map->width-19+4) + if(scrollingRight) { - position.x++; - updateScreen = true; - updateMinimap=true; + if(position.xmh->map->width-19+4) + { + position.x++; + updateScreen = true; + updateMinimap=true; + } } - } - if(scrollingUp) - { - if(position.y>-Hoff) + if(scrollingUp) { - position.y--; - updateScreen = true; - updateMinimap=true; + if(position.y>-Hoff) + { + position.y--; + updateScreen = true; + updateMinimap=true; + } } - } - if(scrollingDown) - { - if(position.ymh->map->height-18+4) + if(scrollingDown) { - position.y++; - updateScreen = true; - updateMinimap=true; + if(position.ymh->map->height-18+4) + { + position.y++; + updateScreen = true; + updateMinimap=true; + } } } if(updateScreen) diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 74da61ae1..b13c83f2b 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -490,7 +490,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) { if(shere->owner == LOCPLINT->playerID) //our stack CGI->curh->changeGraphic(1,5); - else if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isShooting()) //we can shoot enemy + else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy CGI->curh->changeGraphic(1,3); else if(isTileAttackable(myNumber)) //available enemy (melee attackable) { diff --git a/CCallback.cpp b/CCallback.cpp index 201ca4269..753a89b01 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -523,13 +523,16 @@ bool CCallback::battleIsStackMine(int ID) } return false; } -bool CCallback::battleCanShoot(int ID, int dest) //TODO: finish +bool CCallback::battleCanShoot(int ID, int dest) //TODO: check arrows amount { boost::shared_lock lock(*gs->mx); - if(battleGetStackByID(ID)->creature->isShooting() - && battleGetStack(dest) != -1 - && battleGetStackByPos(dest)->owner != battleGetStackByID(ID)->owner - && battleGetStackByPos(dest)->alive()) + CStack *our=battleGetStackByID(ID), *dst=battleGetStackByPos(dest); + if(!our || !dst) return false; + if(vstd::contains(our->abilities,SHOOTER)//it's shooter + && our->owner != dst->owner + && dst->alive() + && !gs->curB->isStackBlocked(ID) + ) return true; return false; } diff --git a/CGameInterface.h b/CGameInterface.h index e90730a38..5ebf3cf75 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -21,6 +21,7 @@ class CCreatureSet; class CArmedInstance; struct BattleResult; struct BattleAttack; +struct BattleStackAttacked; class CObstacle { int ID; @@ -68,15 +69,13 @@ public: virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack - virtual void battleAttack(BattleAttack *ba){}; + virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack + virtual void battleStackAttacked(BattleStackAttacked * bsa){}; //called when stack receives damage (after battleAttack()) virtual void battleEnd(BattleResult *br){}; virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting){}; virtual void battleStackMoved(int ID, int dest){}; virtual void 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 virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles){}; //called when battlefield is prepared, prior the battle beginning - // - }; class CAIHandler { @@ -93,7 +92,6 @@ public: virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){}; virtual void battleStackAttacking(int ID, int dest){}; virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){}; - virtual void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting){}; virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;}; }; #endif //CGAMEINTERFACE_H diff --git a/CGameState.cpp b/CGameState.cpp index 1602ab1c3..4295ba1de 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -212,6 +212,21 @@ std::vector BattleInfo::getAccessibility(int stackID) return ret; } +bool BattleInfo::isStackBlocked(int ID) +{ + CStack *our = getStack(ID); + for(int i=0; ialive() + || stacks[i]->owner==our->owner + ) + continue; //we ommit dead and allied stacks + if( mutualPosition(stacks[i]->position,our->position) >= 0 ) + return true; + } + return false; +} + signed char BattleInfo::mutualPosition(int hex1, int hex2) { if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left diff --git a/CGameState.h b/CGameState.h index 1a69e6b11..120b8c1d1 100644 --- a/CGameState.h +++ b/CGameState.h @@ -71,6 +71,7 @@ struct DLL_EXPORT BattleInfo std::vector getPath(int start, int dest, bool*accessibility); std::vector getAccessibility(int stackID); //returns vector of accessible tiles (taking into account the creature range) + bool isStackBlocked(int ID); //returns true if there is neighbouring enemy stack static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) static std::vector neighbouringTiles(int hex); static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting); //TODO: add additional conditions and require necessary data diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index ebea59707..fca050ba6 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2025,7 +2025,7 @@ void CPlayerInterface::actionStarted(const BattleAction* action) ) { static_cast(curint)->creAnims[action->stackNumber]->setType(20); - } +} } void CPlayerInterface::actionFinished(const BattleAction* action) @@ -2088,10 +2088,10 @@ void CPlayerInterface::battleAttack(BattleAttack *ba) else dynamic_cast(curint)->stackIsAttacked(ba->bsa.stackAttacked, ba->bsa.damageAmount, ba->bsa.killedAmount, ba->stackAttacking, ba->shot()); } -void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting) -{ - dynamic_cast(curint)->stackKilled(ID, dmg, killed, IDby, byShooting); -} +//void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting) +//{ +// dynamic_cast(curint)->stackKilled(ID, dmg, killed, IDby, byShooting); +//} //void CPlayerInterface::battleStackIsShooting(int ID, int dest) //{ diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 6f3ad40d5..cf10d523f 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -365,8 +365,6 @@ public: void battleEnd(BattleResult *br); void battleResultQuited(); void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - //void battleStackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest - void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); void battleStackMoved(int ID, int dest); void 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 void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning diff --git a/client/Client.cpp b/client/Client.cpp index 125da48e7..5768c2a08 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -530,8 +530,15 @@ void CClient::process(int what) BattleAttack ba; *serv >> ba; tlog5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <curB->side1) != playerint.end()) + playerint[gs->curB->side1]->battleAttack(&ba); + if(playerint.find(gs->curB->side2) != playerint.end()) + playerint[gs->curB->side2]->battleAttack(&ba); gs->apply(&ba); - LOCPLINT->battleAttack(&ba); + if(playerint.find(gs->curB->side1) != playerint.end()) + playerint[gs->curB->side1]->battleStackAttacked(&ba.bsa); + if(playerint.find(gs->curB->side2) != playerint.end()) + playerint[gs->curB->side2]->battleStackAttacked(&ba.bsa); break; } case 3007: