1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-09 13:14:02 +02:00

* further fixes for sieges

* support for ballistics
This commit is contained in:
mateuszb 2009-09-06 09:13:16 +00:00
parent 05b0d82769
commit c5832fb9e8
3 changed files with 44 additions and 26 deletions

View File

@ -981,7 +981,7 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
creDir[number] = !creDir[number]; creDir[number] = !creDir[number];
const CStack * curs = LOCPLINT->cb->battleGetStackByID(number); const CStack * curs = LOCPLINT->cb->battleGetStackByID(number);
std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs); std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs, this);
creAnims[number]->pos.x = coords.first; creAnims[number]->pos.x = coords.first;
//creAnims[number]->pos.y = coords.second; //creAnims[number]->pos.y = coords.second;
@ -1114,31 +1114,15 @@ void CBattleInterface::newStack(int stackID)
{ {
const CStack * newStack = LOCPLINT->cb->battleGetStackByID(stackID); const CStack * newStack = LOCPLINT->cb->battleGetStackByID(stackID);
std::pair <int, int> coords; std::pair <int, int> coords = CBattleHex::getXYUnitAnim(newStack->position, newStack->owner == attackingHeroInstance->tempOwner, newStack, this);;
if(newStack->position < 0) //turret if(newStack->position < 0) //turret
{ {
const CCreature & turretCreature = CGI->creh->creatures[ CGI->creh->factionToTurretCreature[siegeH->town->town->typeID] ]; const CCreature & turretCreature = CGI->creh->creatures[ CGI->creh->factionToTurretCreature[siegeH->town->town->typeID] ];
int xShift = turretCreature.isDoubleWide() ? 44 : 0;
switch(newStack->position)
{
case -2: //keep
coords = std::make_pair(505 + xShift, -66);
break;
case -3: //lower turret
coords = std::make_pair(368 + xShift, 304);
break;
case -4: //upper turret
coords = std::make_pair(339 + xShift, -192);
break;
}
creAnims[stackID] = new CCreatureAnimation(turretCreature.animDefName); creAnims[stackID] = new CCreatureAnimation(turretCreature.animDefName);
} }
else else
{ {
coords = CBattleHex::getXYUnitAnim(newStack->position, newStack->owner == attackingHeroInstance->tempOwner, newStack);
creAnims[stackID] = new CCreatureAnimation(newStack->creature->animDefName); creAnims[stackID] = new CCreatureAnimation(newStack->creature->animDefName);
} }
creAnims[stackID]->setType(2); creAnims[stackID]->setType(2);
@ -1185,8 +1169,8 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving, int d
bool twoTiles = movedStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE); bool twoTiles = movedStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE);
std::pair<int, int> begPosition = CBattleHex::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack); std::pair<int, int> begPosition = CBattleHex::getXYUnitAnim(curStackPos, movedStack->attackerOwned, movedStack, this);
std::pair<int, int> endPosition = CBattleHex::getXYUnitAnim(destHex, movedStack->attackerOwned, movedStack); std::pair<int, int> endPosition = CBattleHex::getXYUnitAnim(destHex, movedStack->attackerOwned, movedStack, this);
if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier) if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier)
{ {
@ -1291,7 +1275,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving, int d
handleEndOfMove(number, destHex); handleEndOfMove(number, destHex);
} }
std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], movedStack); std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], movedStack, this);
creAnims[number]->pos.x = coords.first; creAnims[number]->pos.x = coords.first;
if(!endMoving && twoTiles && (movedStack->owner == attackingHeroInstance->tempOwner) && (creDir[number] != (movedStack->owner == attackingHeroInstance->tempOwner))) //big attacker creature is reversed if(!endMoving && twoTiles && (movedStack->owner == attackingHeroInstance->tempOwner) && (creDir[number] != (movedStack->owner == attackingHeroInstance->tempOwner))) //big attacker creature is reversed
creAnims[number]->pos.x -= 44; creAnims[number]->pos.x -= 44;
@ -1915,8 +1899,8 @@ void CBattleInterface::stackIsShooting(int ID, int dest)
spi.frameNum = 0; spi.frameNum = 0;
spi.spin = CGI->creh->idToProjectileSpin[spi.creID]; spi.spin = CGI->creh->idToProjectileSpin[spi.creID];
std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, LOCPLINT->cb->battleGetStackByID(ID)); std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, LOCPLINT->cb->battleGetStackByID(ID), this);
std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, LOCPLINT->cb->battleGetStackByID(ID)); std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, LOCPLINT->cb->battleGetStackByPos(dest), this);
destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot
if(projectileAngle > straightAngle) //upper shot if(projectileAngle > straightAngle) //upper shot
@ -2011,7 +1995,7 @@ void CBattleInterface::spellCast(SpellCast * sc)
//initial variables //initial variables
std::string animToDisplay; std::string animToDisplay;
std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60); std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60);
std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)); //position attacked by arrow std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile), this); //position attacked by arrow
destcoord.first += 250; destcoord.second += 240; destcoord.first += 250; destcoord.second += 240;
//animation angle //animation angle
@ -2809,8 +2793,27 @@ CBattleHero::~CBattleHero()
delete flag; delete flag;
} }
std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack) std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * stack, const CBattleInterface * cbi)
{ {
if(stack->position < 0) //creatures in turrets
{
const CCreature & turretCreature = CGI->creh->creatures[ CGI->creh->factionToTurretCreature[cbi->siegeH->town->town->typeID] ];
int xShift = turretCreature.isDoubleWide() ? 44 : 0;
switch(stack->position)
{
case -2: //keep
return std::make_pair(505 + xShift, -66);
break;
case -3: //lower turret
return std::make_pair(368 + xShift, 304);
break;
case -4: //upper turret
return std::make_pair(339 + xShift, -192);
break;
}
}
std::pair<int, int> ret = std::make_pair(-500, -500); //returned value std::pair<int, int> ret = std::make_pair(-500, -500); //returned value
ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y
//counting x //counting x

View File

@ -62,7 +62,7 @@ public:
//CStack * ourStack; //CStack * ourStack;
bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering) bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
CBattleInterface * myInterface; //interface that owns me CBattleInterface * myInterface; //interface that owns me
static std::pair<int, int> getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * creature); //returns (x, y) of left top corner of animation static std::pair<int, int> getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * creature, const CBattleInterface * cbi); //returns (x, y) of left top corner of animation
//for user interactions //for user interactions
void hover (bool on); void hover (bool on);
void activate(); void activate();

View File

@ -420,6 +420,21 @@ void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance
continue; continue;
} }
if(next->creature->idNumber == 145 && (!curOwner || curOwner->getSecSkillLevel(10) == 0)) //catapult, hero has no ballistics
{
BattleAction attack;
static const int wallHexes[] = {50, 183, 182, 130, 62, 29, 12, 95};
attack.destinationTile = wallHexes[ rand()%ARRAY_COUNT(wallHexes) ];
attack.actionType = 9;
attack.additionalInfo = 0;
attack.side = !next->attackerOwned;
attack.stackNumber = next->ID;
makeBattleAction(attack);
continue;
}
askInterfaceForMove: askInterfaceForMove:
//ask interface and wait for answer //ask interface and wait for answer
if(!battleResult.get()) if(!battleResult.get())