1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

* fixed blocked shooter behavior

* slowed map scrolling
* minor
This commit is contained in:
Michał W. Urbańczyk
2008-10-11 13:14:52 +00:00
parent 7104326563
commit 4af64f1b9f
9 changed files with 70 additions and 45 deletions

View File

@ -1200,40 +1200,43 @@ void CAdvMapInt::update()
} }
++heroAnim; ++heroAnim;
if(scrollingLeft) if(animValHitCount % 4)
{ {
if(position.x>-Woff) if(scrollingLeft)
{ {
position.x--; if(position.x>-Woff)
updateScreen = true; {
updateMinimap=true; position.x--;
updateScreen = true;
updateMinimap=true;
}
} }
} if(scrollingRight)
if(scrollingRight)
{
if(position.x<CGI->mh->map->width-19+4)
{ {
position.x++; if(position.x<CGI->mh->map->width-19+4)
updateScreen = true; {
updateMinimap=true; position.x++;
updateScreen = true;
updateMinimap=true;
}
} }
} if(scrollingUp)
if(scrollingUp)
{
if(position.y>-Hoff)
{ {
position.y--; if(position.y>-Hoff)
updateScreen = true; {
updateMinimap=true; position.y--;
updateScreen = true;
updateMinimap=true;
}
} }
} if(scrollingDown)
if(scrollingDown)
{
if(position.y<CGI->mh->map->height-18+4)
{ {
position.y++; if(position.y<CGI->mh->map->height-18+4)
updateScreen = true; {
updateMinimap=true; position.y++;
updateScreen = true;
updateMinimap=true;
}
} }
} }
if(updateScreen) if(updateScreen)

View File

@ -490,7 +490,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
{ {
if(shere->owner == LOCPLINT->playerID) //our stack if(shere->owner == LOCPLINT->playerID) //our stack
CGI->curh->changeGraphic(1,5); 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); CGI->curh->changeGraphic(1,3);
else if(isTileAttackable(myNumber)) //available enemy (melee attackable) else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
{ {

View File

@ -523,13 +523,16 @@ bool CCallback::battleIsStackMine(int ID)
} }
return false; 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<boost::shared_mutex> lock(*gs->mx); boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
if(battleGetStackByID(ID)->creature->isShooting() CStack *our=battleGetStackByID(ID), *dst=battleGetStackByPos(dest);
&& battleGetStack(dest) != -1 if(!our || !dst) return false;
&& battleGetStackByPos(dest)->owner != battleGetStackByID(ID)->owner if(vstd::contains(our->abilities,SHOOTER)//it's shooter
&& battleGetStackByPos(dest)->alive()) && our->owner != dst->owner
&& dst->alive()
&& !gs->curB->isStackBlocked(ID)
)
return true; return true;
return false; return false;
} }

View File

@ -21,6 +21,7 @@ class CCreatureSet;
class CArmedInstance; class CArmedInstance;
struct BattleResult; struct BattleResult;
struct BattleAttack; struct BattleAttack;
struct BattleStackAttacked;
class CObstacle class CObstacle
{ {
int ID; 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 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 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 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 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 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 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 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<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
//
}; };
class CAIHandler class CAIHandler
{ {
@ -93,7 +92,6 @@ public:
virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){}; virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){};
virtual void battleStackAttacking(int ID, int dest){}; virtual void battleStackAttacking(int ID, int dest){};
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){}; 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;}; virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
}; };
#endif //CGAMEINTERFACE_H #endif //CGAMEINTERFACE_H

View File

@ -212,6 +212,21 @@ std::vector<int> BattleInfo::getAccessibility(int stackID)
return ret; return ret;
} }
bool BattleInfo::isStackBlocked(int ID)
{
CStack *our = getStack(ID);
for(int i=0; i<stacks.size();i++)
{
if( !stacks[i]->alive()
|| 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) signed char BattleInfo::mutualPosition(int hex1, int hex2)
{ {
if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left

View File

@ -71,6 +71,7 @@ struct DLL_EXPORT BattleInfo
std::vector<int> getPath(int start, int dest, bool*accessibility); std::vector<int> getPath(int start, int dest, bool*accessibility);
std::vector<int> getAccessibility(int stackID); //returns vector of accessible tiles (taking into account the creature range) std::vector<int> 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 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<int> neighbouringTiles(int hex); static std::vector<int> 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 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

View File

@ -2025,7 +2025,7 @@ void CPlayerInterface::actionStarted(const BattleAction* action)
) )
{ {
static_cast<CBattleInterface*>(curint)->creAnims[action->stackNumber]->setType(20); static_cast<CBattleInterface*>(curint)->creAnims[action->stackNumber]->setType(20);
} }
} }
void CPlayerInterface::actionFinished(const BattleAction* action) void CPlayerInterface::actionFinished(const BattleAction* action)
@ -2088,10 +2088,10 @@ void CPlayerInterface::battleAttack(BattleAttack *ba)
else else
dynamic_cast<CBattleInterface*>(curint)->stackIsAttacked(ba->bsa.stackAttacked, ba->bsa.damageAmount, ba->bsa.killedAmount, ba->stackAttacking, ba->shot()); dynamic_cast<CBattleInterface*>(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) //void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
{ //{
dynamic_cast<CBattleInterface*>(curint)->stackKilled(ID, dmg, killed, IDby, byShooting); // dynamic_cast<CBattleInterface*>(curint)->stackKilled(ID, dmg, killed, IDby, byShooting);
} //}
//void CPlayerInterface::battleStackIsShooting(int ID, int dest) //void CPlayerInterface::battleStackIsShooting(int ID, int dest)
//{ //{

View File

@ -365,8 +365,6 @@ public:
void battleEnd(BattleResult *br); void battleEnd(BattleResult *br);
void battleResultQuited(); 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 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 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 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<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning

View File

@ -530,8 +530,15 @@ void CClient::process(int what)
BattleAttack ba; BattleAttack ba;
*serv >> ba; *serv >> ba;
tlog5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl; tlog5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl;
if(playerint.find(gs->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); 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; break;
} }
case 3007: case 3007: