Skip to content

Commit 1126683

Browse files
committed
- Fixed collision bug.
- Added firing sound, hit sound and bullet sprites.
1 parent 3173f49 commit 1126683

10 files changed

Lines changed: 160 additions & 73 deletions

File tree

src/Battlescape/BattleAction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "../Engine/RNG.h"
3030
#include "../Engine/SoundSet.h"
3131
#include "../Engine/Sound.h"
32+
#include "../Ruleset/RuleItem.h"
3233

3334

3435
namespace OpenXcom
@@ -78,10 +79,11 @@ void BattleAction::start()
7879
else if (_type == SNAP_SHOT)
7980
{
8081
_save->getSelectedUnit()->aim(true);
81-
_projectile = new Projectile(_res, _save, _save->getSelectedUnit()->getPosition(), _target);
82+
_projectile = new Projectile(_res, _save, _save->getSelectedUnit()->getPosition(), _target, _item->getRules()->getBulletSprite());
8283
if (_projectile->calculateTrajectory())
8384
{
8485
_status = INPROGRESS;
86+
_res->getSoundSet("BATTLE.CAT")->getSound(_item->getRules()->getFireSound())->play();
8587
}
8688
else
8789
{
@@ -135,6 +137,7 @@ void BattleAction::moveBullet()
135137
if(!_projectile->move())
136138
{
137139
// impact !
140+
_res->getSoundSet("BATTLE.CAT")->getSound(_item->getRules()->getHitSound())->play();
138141
_position = _projectile->getPosition(-1);
139142
delete _projectile;
140143
_projectile = 0;

src/Battlescape/Map.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -329,33 +329,6 @@ void Map::drawTerrain(Surface *surface)
329329

330330
// Draw items
331331

332-
// check if we got bullet
333-
if (_action && _action->getProjectileType() > 0 && bulletPosition == mapPosition)
334-
{
335-
for (int i=1;i<_action->getProjectileParticle(0);i++)
336-
{
337-
if (_action->getProjectileParticle(i) != 0xFF)
338-
{
339-
Position voxelPos = _action->getPosition(1-i);
340-
convertVoxelToScreen(voxelPos, &bulletPosition);
341-
_bullet[i]->setX(bulletPosition.x);
342-
_bullet[i]->setY(bulletPosition.y);
343-
_bullet[i]->blit(surface);
344-
}
345-
}
346-
}
347-
// check if we got impact
348-
if (_action && _action->getType()==HIT && bulletPosition == mapPosition)
349-
{
350-
Position voxelPos = _action->getPosition();
351-
convertVoxelToScreen(voxelPos, &bulletPosition);
352-
frame = _res->getSurfaceSet("SMOKE.PCK")->getFrame(26+_action->getAnimFrame());
353-
frame->setX(bulletPosition.x - (_spriteWidth / 2));
354-
frame->setY(bulletPosition.y - (_spriteHeight / 2));
355-
frame->blit(surface);
356-
}
357-
358-
359332
// Draw soldier
360333
if (unit)
361334
{
@@ -397,6 +370,32 @@ void Map::drawTerrain(Surface *surface)
397370
}
398371
}
399372

373+
// check if we got bullet
374+
if (_action && _action->getProjectileType() > 0 && bulletPosition == mapPosition)
375+
{
376+
for (int i=1;i<_action->getProjectileParticle(0);i++)
377+
{
378+
if (_action->getProjectileParticle(i) != 0xFF)
379+
{
380+
Position voxelPos = _action->getPosition(1-i);
381+
convertVoxelToScreen(voxelPos, &bulletPosition);
382+
_bullet[i]->setX(bulletPosition.x);
383+
_bullet[i]->setY(bulletPosition.y);
384+
_bullet[i]->blit(surface);
385+
}
386+
}
387+
}
388+
// check if we got impact
389+
if (_action && _action->getType()==HIT && bulletPosition == mapPosition)
390+
{
391+
Position voxelPos = _action->getPosition();
392+
convertVoxelToScreen(voxelPos, &bulletPosition);
393+
frame = _res->getSurfaceSet("SMOKE.PCK")->getFrame(26 + _action->getAnimFrame());
394+
frame->setX(bulletPosition.x - (_spriteWidth / 2));
395+
frame->setY(bulletPosition.y - (_spriteHeight / 2));
396+
frame->blit(surface);
397+
}
398+
400399
// Draw cursor front
401400
if (_selectorX == itY && _selectorY == itX && _cursorType != CT_NONE)
402401
{

src/Battlescape/Projectile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ const int Projectile::_trail[11][36] = {
5757
* @param save Pointer to battlesavegame.
5858
* @param origin Projectile's start position in tile x/y/z.
5959
* @param target Projectile's target position in tile x/y/z.
60+
* @param bulletType
6061
*/
61-
Projectile::Projectile(ResourcePack *res, SavedBattleGame *save, Position origin, Position target) : _res(res), _save(save), _origin(origin), _target(target), _position(0)
62+
Projectile::Projectile(ResourcePack *res, SavedBattleGame *save, Position origin, Position target, int bulletType) : _res(res), _save(save), _origin(origin), _target(target), _position(0), _bulletType(bulletType)
6263
{
63-
_bulletType=4; // test
64+
6465
}
6566

6667
/**

src/Battlescape/Projectile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Projectile
4949
int voxelCheck(const Position& voxel);
5050
public:
5151
/// Creates a new Projectile.
52-
Projectile(ResourcePack *res, SavedBattleGame *save, Position _origin, Position _target);
52+
Projectile(ResourcePack *res, SavedBattleGame *save, Position _origin, Position _target, int bulletType);
5353
/// Cleans up the Projectile.
5454
~Projectile();
5555
/// Calculates the trajectory.

src/Ruleset/MapDataSet.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ void MapDataSet::load(ResourcePack *res)
176176
to->setFlammable((int)mcd.Flammable);
177177
to->setFuel((int)mcd.Fuel);
178178

179-
180-
181179
// build the 3D voxel model for this object using the loft references
182180
model = new MapModel();
183181
for (int layer = 0; layer < 12; layer++)
@@ -197,14 +195,15 @@ void MapDataSet::load(ResourcePack *res)
197195
{
198196
delete model;
199197
model = 0;
200-
to->setModel(*i);
198+
to->setModel((MapModel*)(*i));
201199
found = true;
202200
}
203201
}
204202
if (!found)
205203
{
206204
_models.push_back(model);
207205
to->setModel(model);
206+
model = 0;
208207
}
209208
}
210209

src/Ruleset/MapModel.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ int MapModel::getHeight() const
109109
void MapModel::set16Voxels(Uint16 voxels, int y, int z)
110110
{
111111
_voxels[z * _length + y] = voxels;
112-
// recalculate checksum each time?
113-
_checksum = fletcher32(_voxels, (_width/16) * _length * _height);
114112
}
115113

116114
/**
@@ -128,39 +126,18 @@ bool MapModel::getVoxel(int x, int y, int z) const
128126
}
129127

130128
/**
131-
* The equals function. Compares two checksums of mapmodel objects with their checksum.
129+
* The equals function.
132130
* @param mapModel
133131
* @return bool
134132
*/
135-
bool MapModel::equals (const MapModel *mapModel) const
133+
bool MapModel::equals (const MapModel *mapModel)
136134
{
137-
return _checksum == mapModel->_checksum;
138-
}
139-
140-
/**
141-
* Calculates a checksum. Used to compare two models.
142-
* @param data Pointer to the data.
143-
* @param len Length of the data.
144-
* @return Uint32 a 32bit checksum.
145-
*/
146-
Uint32 MapModel::fletcher32( Uint16 *data, size_t len )
147-
{
148-
Uint32 sum1 = 0xffff, sum2 = 0xffff;
149-
150-
while (len) {
151-
unsigned tlen = len > 360 ? 360 : len;
152-
len -= tlen;
153-
do {
154-
sum1 += *data++;
155-
sum2 += sum1;
156-
} while (--tlen);
157-
sum1 = (sum1 & 0xffff) + (sum1 >> 16);
158-
sum2 = (sum2 & 0xffff) + (sum2 >> 16);
159-
}
160-
/* Second reduction step to reduce sums to 16 bits */
161-
sum1 = (sum1 & 0xffff) + (sum1 >> 16);
162-
sum2 = (sum2 & 0xffff) + (sum2 >> 16);
163-
return sum2 << 16 | sum1;
135+
for (int i=0; i < (_width/16) * _length * _height; i++)
136+
{
137+
if (this->_voxels[i] != mapModel->_voxels[i])
138+
return false;
139+
}
140+
return true;
164141
}
165142

166143
}

src/Ruleset/MapModel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class MapModel
3737
private:
3838
int _width, _length, _height;
3939
Uint16 *_voxels;
40-
Uint32 fletcher32( Uint16 *data, size_t len );
41-
Uint32 _checksum;
4240
public:
4341
MapModel(int width = 16, int length = 16, int height = 24);
4442
~MapModel();
@@ -55,7 +53,7 @@ class MapModel
5553
/// Get a single voxel.
5654
bool getVoxel(int x, int y, int z) const;
5755
/// Equals function.
58-
bool equals (const MapModel *mapModel) const;
56+
bool equals (const MapModel *mapModel);
5957

6058
};
6159

src/Ruleset/RuleItem.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,77 @@ void RuleItem::setTwoHanded(bool flag)
197197
{
198198
_twoHanded = flag;
199199
}
200+
201+
/**
202+
* Returns the item's bullet sprite reference.
203+
* @return Sprite reference.
204+
*/
205+
int RuleItem::getBulletSprite() const
206+
{
207+
return _bulletSprite;
208+
}
209+
210+
/**
211+
* Changes the item's bulet sprite reference.
212+
* @param sprite Sprite reference.
213+
*/
214+
void RuleItem::setBulletSprite(int sprite)
215+
{
216+
_bulletSprite = sprite;
217+
}
218+
219+
/**
220+
* Returns the item's fire sound.
221+
* @return Sprite reference.
222+
*/
223+
int RuleItem::getFireSound() const
224+
{
225+
return _fireSound;
226+
}
227+
228+
/**
229+
* Changes the item's fire sound..
230+
* @param sprite Sprite reference.
231+
*/
232+
void RuleItem::setFireSound(int sound)
233+
{
234+
_fireSound = sound;
235+
}
236+
237+
/**
238+
* Returns the item's hit sound.
239+
* @return Sprite reference.
240+
*/
241+
int RuleItem::getHitSound() const
242+
{
243+
return _hitSound;
244+
}
245+
246+
/**
247+
* Changes the item's fire sound..
248+
* @param sprite Sprite reference.
249+
*/
250+
void RuleItem::setHitSound(int sound)
251+
{
252+
_hitSound = sound;
253+
}
254+
255+
/**
256+
* Returns the item's hit sound.
257+
* @return Sprite reference.
258+
*/
259+
int RuleItem::getHitAnimation() const
260+
{
261+
return _hitAnimation;
262+
}
263+
264+
/**
265+
* Changes the item's fire sound..
266+
* @param sprite Sprite reference.
267+
*/
268+
void RuleItem::setHitAnimation(int animation)
269+
{
270+
_hitAnimation = animation;
271+
}
272+
200273
}

src/Ruleset/RuleItem.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class RuleItem
3737
float _size;
3838
int _cost, _time;
3939
bool _equip, _twoHanded;
40-
int _bigSprite, _floorSprite, _handSprite;
40+
int _bigSprite, _floorSprite, _handSprite, _bulletSprite;
41+
int _fireSound, _hitSound, _hitAnimation;
4142
public:
4243
/// Creates a blank item ruleset.
4344
RuleItem(std::string type);
@@ -64,19 +65,35 @@ class RuleItem
6465
/// Gets the item's reference in BIGOBS.PCK for use in inventory.
6566
int getBigSprite() const;
6667
/// Sets the item's reference in BIGOBS.PCK for use in inventory.
67-
void setBigSprite(int value);
68+
void setBigSprite(int sprite);
6869
/// Gets the item's reference in FLOOROB.PCK for use in inventory.
6970
int getFloorSprite() const;
7071
/// Sets the item's reference in FLOOROB.PCK for use in inventory.
71-
void setFloorSprite(int value);
72+
void setFloorSprite(int sprite);
7273
/// Gets the item's reference in HANDOB.PCK for use in inventory.
7374
int getHandSprite() const;
7475
/// Sets the item's reference in HANDOB.PCK for use in inventory.
75-
void setHandSprite(int value);
76+
void setHandSprite(int sprite);
7677
/// Gets if the item is two-handed.
7778
bool getTwoHanded() const;
7879
/// Sets if the item is two-handed.
7980
void setTwoHanded(bool flag);
81+
/// Gets the item's bullet sprite reference.
82+
int getBulletSprite() const;
83+
/// Sets the item's bulet sprite reference.
84+
void setBulletSprite(int sprite);
85+
/// Gets the item's fire sound.
86+
int getFireSound() const;
87+
/// Sets the item's fire sound.
88+
void setFireSound(int sound);
89+
/// Gets the item's hit sound.
90+
int getHitSound() const;
91+
/// Sets the item's hit sound.
92+
void setHitSound(int sound);
93+
/// Gets the item's hit animation.
94+
int getHitAnimation() const;
95+
/// Sets the item's hit animation.
96+
void setHitAnimation(int animation);
8097

8198
};
8299

0 commit comments

Comments
 (0)