1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +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;
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.x<CGI->mh->map->width-19+4)
if(scrollingRight)
{
position.x++;
updateScreen = true;
updateMinimap=true;
if(position.x<CGI->mh->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.y<CGI->mh->map->height-18+4)
if(scrollingDown)
{
position.y++;
updateScreen = true;
updateMinimap=true;
if(position.y<CGI->mh->map->height-18+4)
{
position.y++;
updateScreen = true;
updateMinimap=true;
}
}
}
if(updateScreen)

View File

@ -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)
{

View File

@ -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<boost::shared_mutex> 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;
}

View File

@ -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<CObstacle*> 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

View File

@ -212,6 +212,21 @@ std::vector<int> BattleInfo::getAccessibility(int stackID)
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)
{
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> 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<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

View File

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

View File

@ -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<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning

View File

@ -530,8 +530,15 @@ void CClient::process(int what)
BattleAttack ba;
*serv >> ba;
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);
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: