Skip to content

Commit da3855b

Browse files
committed
- Added basic item throwing action (no trajectory calculation yet).
- Rightclick to abort walking works again.
1 parent 2de82b6 commit da3855b

5 files changed

Lines changed: 115 additions & 38 deletions

File tree

‎src/Battlescape/BattlescapeState.cpp‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,14 @@ void BattlescapeState::btnActionMenuItemClick(Action *action)
750750
{
751751
_autoShot = 1;
752752
}
753-
_map->setCursorType(CT_AIM);
753+
if (_selectedAction == BA_THROW)
754+
{
755+
_map->setCursorType(CT_THROW);
756+
}
757+
else
758+
{
759+
_map->setCursorType(CT_AIM);
760+
}
754761
_targeting = true;
755762
hidePopup();
756763
}
@@ -768,10 +775,15 @@ void BattlescapeState::hidePopup()
768775
{
769776
_map->setCursorType(CT_NORMAL);
770777
}
778+
else if (_selectedAction == BA_THROW)
779+
{
780+
_map->setCursorType(CT_THROW);
781+
}
771782
else
772783
{
773784
_map->setCursorType(CT_AIM);
774785
}
786+
775787
}
776788

777789
/**
@@ -1083,6 +1095,10 @@ void BattlescapeState::popState()
10831095
{
10841096
_map->setCursorType(CT_NORMAL);
10851097
}
1098+
else if (_selectedAction == BA_THROW)
1099+
{
1100+
_map->setCursorType(CT_THROW);
1101+
}
10861102
else
10871103
{
10881104
_map->setCursorType(CT_AIM);
@@ -1131,7 +1147,7 @@ void BattlescapeState::debug(const std::wstring message)
11311147
*/
11321148
void BattlescapeState::handle(Action *action)
11331149
{
1134-
if (_game->getCursor()->getVisible())
1150+
if (_game->getCursor()->getVisible() || action->getDetails()->button.button == SDL_BUTTON_RIGHT)
11351151
{
11361152
State::handle(action);
11371153

‎src/Battlescape/Map.cpp‎

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void Map::drawTerrain(Surface *surface)
318318
{
319319
if (_viewHeight == itZ)
320320
{
321-
if (_cursorType == CT_NORMAL)
321+
if (_cursorType == CT_NORMAL || _cursorType == CT_THROW)
322322
{
323323
if (unit)
324324
frameNumber = 1; // yellow box
@@ -400,42 +400,63 @@ void Map::drawTerrain(Surface *surface)
400400
// check if we got bullet
401401
if (_projectile)
402402
{
403+
Surface *item = 0;
404+
if (_projectile->getItem())
405+
item = _res->getSurfaceSet("FLOOROB.PCK")->getFrame(_projectile->getItem()->getRules()->getFloorSprite());
403406
// draw bullet on the correct tile
404407
if (itX >= bulletLowX && itX <= bulletHighX && itY >= bulletLowY && itY <= bulletHighY)
405408
{
406409
if (itZ == 0)
407410
{
408411
// draw shadow on the floor
409-
for (int i = 1; i <= _projectile->getParticle(0); i++)
412+
if (item)
410413
{
411-
if (_projectile->getParticle(i) != 0xFF)
414+
void();
415+
}
416+
else
417+
{
418+
for (int i = 1; i <= _projectile->getParticle(0); i++)
412419
{
413-
Position voxelPos = _projectile->getPosition(1-i);
414-
voxelPos.z = 0;
415-
if (voxelPos.x / 16 == mapPosition.x &&
416-
voxelPos.y / 16 == mapPosition.y)
420+
if (_projectile->getParticle(i) != 0xFF)
417421
{
418-
convertVoxelToScreen(voxelPos, &bulletPositionScreen);
419-
_bulletShadow[_projectile->getParticle(i)]->setX(bulletPositionScreen.x);
420-
_bulletShadow[_projectile->getParticle(i)]->setY(bulletPositionScreen.y);
421-
_bulletShadow[_projectile->getParticle(i)]->blit(surface);
422+
Position voxelPos = _projectile->getPosition(1-i);
423+
voxelPos.z = 0;
424+
if (voxelPos.x / 16 == mapPosition.x &&
425+
voxelPos.y / 16 == mapPosition.y)
426+
{
427+
convertVoxelToScreen(voxelPos, &bulletPositionScreen);
428+
_bulletShadow[_projectile->getParticle(i)]->setX(bulletPositionScreen.x);
429+
_bulletShadow[_projectile->getParticle(i)]->setY(bulletPositionScreen.y);
430+
_bulletShadow[_projectile->getParticle(i)]->blit(surface);
431+
}
422432
}
423433
}
424434
}
425435
}
426436

427-
for (int i = 1; i <= _projectile->getParticle(0); i++)
437+
if (item)
428438
{
429-
if (_projectile->getParticle(i) != 0xFF)
439+
Position voxelPos = _projectile->getPosition();
440+
convertVoxelToScreen(voxelPos, &bulletPositionScreen);
441+
item->setX(bulletPositionScreen.x - item->getWidth()/2);
442+
item->setY(bulletPositionScreen.y - item->getHeight()/2);
443+
item->blit(surface);
444+
}
445+
else
446+
{
447+
for (int i = 1; i <= _projectile->getParticle(0); i++)
430448
{
431-
Position voxelPos = _projectile->getPosition(1-i);
432-
if (voxelPos.x / 16 == mapPosition.x &&
433-
voxelPos.y / 16 == mapPosition.y )
449+
if (_projectile->getParticle(i) != 0xFF)
434450
{
435-
convertVoxelToScreen(voxelPos, &bulletPositionScreen);
436-
_bullet[_projectile->getParticle(i)]->setX(bulletPositionScreen.x);
437-
_bullet[_projectile->getParticle(i)]->setY(bulletPositionScreen.y);
438-
_bullet[_projectile->getParticle(i)]->blit(surface);
451+
Position voxelPos = _projectile->getPosition(1-i);
452+
if (voxelPos.x / 16 == mapPosition.x &&
453+
voxelPos.y / 16 == mapPosition.y )
454+
{
455+
convertVoxelToScreen(voxelPos, &bulletPositionScreen);
456+
_bullet[_projectile->getParticle(i)]->setX(bulletPositionScreen.x);
457+
_bullet[_projectile->getParticle(i)]->setY(bulletPositionScreen.y);
458+
_bullet[_projectile->getParticle(i)]->blit(surface);
459+
}
439460
}
440461
}
441462
}
@@ -461,7 +482,7 @@ void Map::drawTerrain(Surface *surface)
461482
{
462483
if (_viewHeight == itZ)
463484
{
464-
if (_cursorType == CT_NORMAL)
485+
if (_cursorType == CT_NORMAL || _cursorType == CT_THROW)
465486
{
466487
if (unit)
467488
frameNumber = 4; // yellow box
@@ -484,6 +505,13 @@ void Map::drawTerrain(Surface *surface)
484505
frame->setX(screenPosition.x);
485506
frame->setY(screenPosition.y);
486507
frame->blit(surface);
508+
if (_cursorType == CT_THROW)
509+
{
510+
frame = _res->getSurfaceSet("CURSOR.PCK")->getFrame(15 + (_animFrame / 4));
511+
frame->setX(screenPosition.x);
512+
frame->setY(screenPosition.y);
513+
frame->blit(surface);
514+
}
487515
}
488516

489517
tile = _save->getTile(mapPosition);

‎src/Battlescape/Projectile.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const int Projectile::_trail[11][36] = {
6161
* @param target Projectile's target position in tile x/y/z.
6262
* @param bulletType A number that corresponds to the type of bullet this is.
6363
*/
64-
Projectile::Projectile(ResourcePack *res, SavedBattleGame *save, Position origin, Position target, int bulletType) : _res(res), _save(save), _origin(origin), _target(target), _position(0), _bulletType(bulletType)
64+
Projectile::Projectile(ResourcePack *res, SavedBattleGame *save, Position origin, Position target, int bulletType, BattleItem *item) : _res(res), _save(save), _origin(origin), _target(target), _position(0), _bulletType(bulletType), _item(item)
6565
{
6666

6767
}
@@ -231,4 +231,9 @@ int Projectile::getParticle(int i)
231231
return _trail[_bulletType][i];
232232
}
233233

234+
BattleItem *Projectile::getItem() const
235+
{
236+
return _item;
237+
}
238+
234239
}

‎src/Battlescape/Projectile.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Projectile
4747
void applyAccuracy(const Position& origin, Position *target, double accuracy);
4848
public:
4949
/// Creates a new Projectile.
50-
Projectile(ResourcePack *res, SavedBattleGame *save, Position _origin, Position _target, int bulletType);
50+
Projectile(ResourcePack *res, SavedBattleGame *save, Position origin, Position target, int bulletType, BattleItem *item);
5151
/// Cleans up the Projectile.
5252
~Projectile();
5353
/// Calculates the trajectory.
@@ -58,6 +58,8 @@ class Projectile
5858
Position getPosition(int offset = 0) const;
5959
/// Get a particle from the particle array.
6060
int getParticle(int i);
61+
/// Get the item
62+
BattleItem *getItem() const;
6163
};
6264

6365
}

‎src/Battlescape/ProjectileFlyBState.cpp‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ProjectileFlyBState::~ProjectileFlyBState()
5959
void ProjectileFlyBState::init()
6060
{
6161
int baseAcc;
62+
BattleItem *item = 0;
6263

6364
_parent->setStateInterval(DEFAULT_BULLET_SPEED);
6465
_unit = _parent->getGame()->getSavedGame()->getBattleGame()->getSelectedUnit();
@@ -80,6 +81,9 @@ void ProjectileFlyBState::init()
8081
case BA_AIMEDSHOT:
8182
baseAcc = _parent->getSelectedItem()->getRules()->getAccuracyAimed();
8283
break;
84+
case BA_THROW:
85+
baseAcc = (int)(_unit->getThrowingAccuracy()*100.0);
86+
item = _parent->getSelectedItem();
8387
default:
8488
baseAcc = 0;
8589
}
@@ -89,18 +93,29 @@ void ProjectileFlyBState::init()
8993
_parent->getGame()->getSavedGame()->getBattleGame(),
9094
_unit->getPosition(),
9195
_parent->getTarget(),
92-
_parent->getSelectedItem()->getRules()->getBulletSprite()
96+
_parent->getSelectedItem()->getRules()->getBulletSprite(),
97+
item
9398
);
9499
// add the projectile on the map
95100
_parent->getMap()->setProjectile(projectile);
96101
// let it calculate a trajectory
97102
if (projectile->calculateTrajectory(_unit->getFiringAccuracy(baseAcc)))
98103
{
99-
// set the soldier in an aiming position
100-
_unit->aim(true);
101-
_parent->getMap()->cacheUnits();
102-
// and we have a lift-off
103-
_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(_parent->getSelectedItem()->getRules()->getFireSound())->play();
104+
if (_parent->getSelectedAction() == BA_THROW)
105+
{
106+
item->setOwner(0);
107+
_unit->setCached(false);
108+
_parent->getMap()->cacheUnits();
109+
_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(39)->play();
110+
}
111+
else
112+
{
113+
// set the soldier in an aiming position
114+
_unit->aim(true);
115+
_parent->getMap()->cacheUnits();
116+
// and we have a lift-off
117+
_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(_parent->getSelectedItem()->getRules()->getFireSound())->play();
118+
}
104119
}
105120
else
106121
{
@@ -122,15 +137,26 @@ void ProjectileFlyBState::think()
122137
if(!_parent->getMap()->getProjectile()->move())
123138
{
124139
// impact !
125-
int offset = 0;
126-
// explosions impact not inside the voxel but one step back
127-
if (_parent->getSelectedItem()->getAmmoItem() && (
128-
_parent->getSelectedItem()->getAmmoItem()->getRules()->getDamageType() == DT_HE ||
129-
_parent->getSelectedItem()->getAmmoItem()->getRules()->getDamageType() == DT_IN))
140+
if (_parent->getSelectedAction() == BA_THROW)
141+
{
142+
Position pos = _parent->getMap()->getProjectile()->getPosition();
143+
pos.x /= 16;
144+
pos.y /= 16;
145+
pos.z /= 24;
146+
_parent->getGame()->getSavedGame()->getBattleGame()->getTerrainModifier()->spawnItem(pos, _parent->getMap()->getProjectile()->getItem());
147+
}
148+
else
130149
{
131-
offset = -1;
150+
int offset = 0;
151+
// explosions impact not inside the voxel but one step back
152+
if (_parent->getSelectedItem()->getAmmoItem() && (
153+
_parent->getSelectedItem()->getAmmoItem()->getRules()->getDamageType() == DT_HE ||
154+
_parent->getSelectedItem()->getAmmoItem()->getRules()->getDamageType() == DT_IN))
155+
{
156+
offset = -1;
157+
}
158+
_parent->statePushNext(new ExplosionBState(_parent, _parent->getMap()->getProjectile()->getPosition(offset), _parent->getSelectedItem()));
132159
}
133-
_parent->statePushNext(new ExplosionBState(_parent, _parent->getMap()->getProjectile()->getPosition(offset), _parent->getSelectedItem()));
134160

135161
delete _parent->getMap()->getProjectile();
136162
_parent->getMap()->setProjectile(0);

0 commit comments

Comments
 (0)