Skip to content

Commit ad1a5ab

Browse files
committed
make unit sprites double wide
just internally, mind you. this allows for slightly larger sized weapons, like the drills. it's not perfect, tho. i'd like to flip the sprites for itemB horizontally, but that can wait. also fixes SOME small rendering bugs with large and/or burning units
1 parent 08da18c commit ad1a5ab

2 files changed

Lines changed: 83 additions & 74 deletions

File tree

‎src/Battlescape/Map.cpp‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void Map::drawTerrain(Surface *surface)
486486
// draw unit
487487
Position offset;
488488
calculateWalkingOffset(bu, &offset);
489-
tmpSurface->blitNShade(surface, screenPosition.x + offset.x + tileOffset.x, screenPosition.y + offset.y + tileOffset.y, tileNorthShade);
489+
tmpSurface->blitNShade(surface, screenPosition.x + offset.x + tileOffset.x - _spriteWidth / 2, screenPosition.y + offset.y + tileOffset.y, tileNorthShade);
490490
// draw fire
491491
if (bu->getFire() > 0)
492492
{
@@ -627,7 +627,7 @@ void Map::drawTerrain(Surface *surface)
627627
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x, screenPosition.y + tileWest->getTerrainLevel() + tileOffset.y, tileWestShade, true);
628628
}
629629
// Draw soldier
630-
if (westUnit && westUnit->getStatus() != STATUS_WALKING && (!tileWest->getMapData(O_OBJECT) || tileWest->getMapData(O_OBJECT)->getBigWall() < 6 || tileWest->getMapData(O_OBJECT)->getBigWall() == 9) && (westUnit->getVisible() || _save->getDebugMode()))
630+
if (westUnit && (!tileWest->getMapData(O_OBJECT) || tileWest->getMapData(O_OBJECT)->getBigWall() < 6 || tileWest->getMapData(O_OBJECT)->getBigWall() == 9) && (westUnit->getVisible() || _save->getDebugMode()))
631631
{
632632
// the part is 0 for small units, large units have parts 1,2 & 3 depending on the relative x/y position of this tile vs the actual unit position.
633633
int part = 0;
@@ -636,12 +636,14 @@ void Map::drawTerrain(Surface *surface)
636636
tmpSurface = westUnit->getCache(&invalid, part);
637637
if (tmpSurface)
638638
{
639-
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x, screenPosition.y + tileOffset.y + getTerrainLevel(westUnit->getPosition(), westUnit->getArmor()->getSize()), tileWestShade, true);
639+
Position offset;
640+
calculateWalkingOffset(westUnit, &offset);
641+
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x + offset.x - _spriteWidth / 2, screenPosition.y + tileOffset.y + offset.y + getTerrainLevel(westUnit->getPosition(), westUnit->getArmor()->getSize()), tileWestShade, true);
640642
if (westUnit->getFire() > 0)
641643
{
642644
frameNumber = 4 + (_animFrame / 2);
643645
tmpSurface = _game->getMod()->getSurfaceSet("SMOKE.PCK")->getFrame(frameNumber);
644-
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x, screenPosition.y + tileOffset.y + getTerrainLevel(westUnit->getPosition(), westUnit->getArmor()->getSize()), 0, true);
646+
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x + offset.x, screenPosition.y + tileOffset.y + offset.y + getTerrainLevel(westUnit->getPosition(), westUnit->getArmor()->getSize()), 0, true);
645647
}
646648
}
647649
}
@@ -836,7 +838,7 @@ void Map::drawTerrain(Surface *surface)
836838
{
837839
Position offset;
838840
calculateWalkingOffset(unit, &offset);
839-
tmpSurface->blitNShade(surface, screenPosition.x + offset.x, screenPosition.y + offset.y, tileShade);
841+
tmpSurface->blitNShade(surface, screenPosition.x + offset.x - _spriteWidth / 2, screenPosition.y + offset.y, tileShade);
840842
if (unit->getFire() > 0)
841843
{
842844
frameNumber = 4 + (_animFrame / 2);
@@ -846,12 +848,6 @@ void Map::drawTerrain(Surface *surface)
846848
if (unit->getBreathFrame() > 0)
847849
{
848850
tmpSurface = _game->getMod()->getSurfaceSet("BREATH-1.PCK")->getFrame(unit->getBreathFrame() - 1);
849-
// we enlarge the unit sprite when aiming to accommodate the weapon. so adjust as necessary.
850-
if (unit->getStatus() == STATUS_AIMING)
851-
{
852-
offset.x = 0;
853-
}
854-
855851
// lower the bubbles for shorter or kneeling units.
856852
offset.y += (22 - unit->getHeight());
857853
if (tmpSurface)
@@ -1464,14 +1460,6 @@ void Map::calculateWalkingOffset(BattleUnit *unit, Position *offset)
14641460
else
14651461
{
14661462
offset->y += getTerrainLevel(unit->getPosition(), size);
1467-
1468-
if (unit->getArmor()->getCanHoldWeapon())
1469-
{
1470-
if (unit->getStatus() == STATUS_AIMING)
1471-
{
1472-
offset->x = -16;
1473-
}
1474-
}
14751463
if (_save->getDepth() > 0)
14761464
{
14771465
unit->setFloorAbove(false);
@@ -1490,7 +1478,6 @@ void Map::calculateWalkingOffset(BattleUnit *unit, Position *offset)
14901478
}
14911479
}
14921480
}
1493-
14941481
}
14951482

14961483

@@ -1557,7 +1544,7 @@ void Map::cacheUnits()
15571544
*/
15581545
void Map::cacheUnit(BattleUnit *unit)
15591546
{
1560-
UnitSprite *unitSprite = new UnitSprite(unit->getStatus() == STATUS_AIMING ? _spriteWidth * 2: _spriteWidth, _spriteHeight, 0, 0, _save->getDepth() != 0);
1547+
UnitSprite *unitSprite = new UnitSprite(_spriteWidth * 2, _spriteHeight, 0, 0, _save->getDepth() != 0);
15611548
unitSprite->setPalette(this->getPalette());
15621549
bool invalid, dummy;
15631550
int numOfParts = unit->getArmor()->getSize() * unit->getArmor()->getSize();
@@ -1571,12 +1558,10 @@ void Map::cacheUnit(BattleUnit *unit)
15711558
Surface *cache = unit->getCache(&dummy, i);
15721559
if (!cache) // no cache created yet
15731560
{
1574-
cache = new Surface(_spriteWidth, _spriteHeight);
1561+
cache = new Surface(_spriteWidth * 2, _spriteHeight);
15751562
cache->setPalette(this->getPalette());
15761563
}
1577-
1578-
cache->setWidth(unitSprite->getWidth());
1579-
1564+
15801565
unitSprite->setBattleUnit(unit, i);
15811566

15821567
BattleItem *rhandItem = unit->getItem("STR_RIGHT_HAND");

‎src/Battlescape/UnitSprite.cpp‎

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -529,20 +529,21 @@ void UnitSprite::drawRoutine0()
529529
itemB->setY(itemB->getY() + (22 - _unit->getStandHeight()));
530530
}
531531

532-
if (_unit->getStatus() == STATUS_AIMING)
533-
{
534-
torso->setX(offXAiming);
535-
legs->setX(offXAiming);
536-
leftArm->setX(offXAiming);
537-
rightArm->setX(offXAiming);
538-
if (itemA)
539-
itemA->setX(itemA->getX() + offXAiming);
540-
if (itemB)
541-
itemB->setX(itemB->getX() + offXAiming);
542-
}
543-
else if (!itemA && _drawingRoutine == 10 && _unit->getStatus() == STATUS_WALKING && unitDir == 2)
532+
// offset everything to the left by 16 pixels.
533+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
534+
torso->setX(16);
535+
legs->setX(16);
536+
leftArm->setX(16);
537+
rightArm->setX(16);
538+
if (itemA)
539+
itemA->setX(itemA->getX() + 16);
540+
if (itemB)
541+
itemB->setX(itemB->getX() + 16);
542+
543+
// fix the errant muton arm.
544+
if (!itemA && _drawingRoutine == 10 && _unit->getStatus() == STATUS_WALKING && unitDir == 2)
544545
{
545-
rightArm->setX(-6);
546+
rightArm->setX(10);
546547
}
547548

548549
// blit order depends on unit direction, and whether we are holding a 2 handed weapon.
@@ -722,16 +723,17 @@ void UnitSprite::drawRoutine1()
722723
rightArm->setY(0);
723724
torso->setY(0);
724725
}
725-
if (_unit->getStatus() == STATUS_AIMING)
726-
{
727-
torso->setX(offXAiming);
728-
leftArm->setX(offXAiming);
729-
rightArm->setX(offXAiming);
730-
if (itemA)
731-
itemA->setX(itemA->getX() + offXAiming);
732-
if (itemB)
733-
itemB->setX(itemB->getX() + offXAiming);
734-
}
726+
727+
// offset everything to the left by 16 pixels.
728+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
729+
torso->setX(16);
730+
leftArm->setX(16);
731+
rightArm->setX(16);
732+
if (itemA)
733+
itemA->setX(itemA->getX() + 16);
734+
if (itemB)
735+
itemB->setX(itemB->getX() + 16);
736+
735737
// blit order depends on unit direction.
736738
switch (unitDir)
737739
{
@@ -781,6 +783,7 @@ void UnitSprite::drawRoutine2()
781783

782784
// draw the tank itself
783785
s = _unitSurface->getFrame(hoverTank + (_part * 8) + _unit->getDirection());
786+
s->setX(16);
784787
drawRecolored(s);
785788

786789
// draw the turret, together with the last part
@@ -791,7 +794,7 @@ void UnitSprite::drawRoutine2()
791794
int turretOffsetY = -4;
792795
if (hoverTank)
793796
{
794-
turretOffsetX += offX[_unit->getDirection()];
797+
turretOffsetX += offX[_unit->getDirection()] + 16;
795798
turretOffsetY += offy[_unit->getDirection()];
796799
}
797800
s->setX(turretOffsetX);
@@ -822,6 +825,10 @@ void UnitSprite::drawRoutine3()
822825
}
823826

824827
s = _unitSurface->getFrame((_part * 8) + _unit->getDirection());
828+
829+
// offset everything to the left by 16 pixels.
830+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
831+
s->setX(16);
825832

826833
drawRecolored(s);
827834
}
@@ -941,15 +948,15 @@ void UnitSprite::drawRoutine4()
941948
itemB->setY(offY3[unitDir]);
942949
}
943950
}
951+
952+
// offset everything to the right by 16 pixels.
953+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
954+
s->setX(16);
955+
if (itemA)
956+
itemA->setX(itemA->getX() + 16);
957+
if (itemB)
958+
itemB->setX(itemB->getX() + 16);
944959

945-
if (_unit->getStatus() == STATUS_AIMING)
946-
{
947-
s->setX(offXAiming);
948-
if (itemA)
949-
itemA->setX(itemA->getX() + offXAiming);
950-
if (itemB)
951-
itemB->setX(itemB->getX() + offXAiming);
952-
}
953960
switch (unitDir)
954961
{
955962
case 0: itemB?itemB->blit(this):void(); itemA?itemA->blit(this):void(); drawRecolored(s); break;
@@ -989,7 +996,10 @@ void UnitSprite::drawRoutine5()
989996
{
990997
s = _unitSurface->getFrame((_part * 8) + _unit->getDirection());
991998
}
992-
999+
1000+
// offset everything to the right by 16 pixels.
1001+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
1002+
s->setX(16);
9931003
drawRecolored(s);
9941004
}
9951005

@@ -1155,17 +1165,16 @@ void UnitSprite::drawRoutine6()
11551165
rightArm->setY(0);
11561166
torso->setY(0);
11571167
}
1158-
if (_unit->getStatus() == STATUS_AIMING)
1159-
{
1160-
torso->setX(offXAiming);
1161-
legs->setX(offXAiming);
1162-
leftArm->setX(offXAiming);
1163-
rightArm->setX(offXAiming);
1164-
if (itemA)
1165-
itemA->setX(itemA->getX() + offXAiming);
1166-
if (itemB)
1167-
itemB->setX(itemB->getX() + offXAiming);
1168-
}
1168+
// offset everything to the right by 16 pixels.
1169+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
1170+
torso->setX(16);
1171+
legs->setX(16);
1172+
leftArm->setX(16);
1173+
rightArm->setX(16);
1174+
if (itemA)
1175+
itemA->setX(itemA->getX() + 16);
1176+
if (itemB)
1177+
itemB->setX(itemB->getX() + 16);
11691178

11701179
// blit order depends on unit direction.
11711180
switch (unitDir)
@@ -1241,6 +1250,12 @@ void UnitSprite::drawRoutine7()
12411250
rightArm->setY(0);
12421251
torso->setY(0);
12431252
}
1253+
// offset everything to the right by 16 pixels.
1254+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
1255+
torso->setX(16);
1256+
legs->setX(16);
1257+
leftArm->setX(16);
1258+
rightArm->setX(16);
12441259

12451260
// blit order depends on unit direction
12461261
switch (unitDir)
@@ -1280,6 +1295,10 @@ void UnitSprite::drawRoutine8()
12801295

12811296
if (_unit->getStatus() == STATUS_AIMING)
12821297
legs = _unitSurface->getFrame(aim);
1298+
1299+
// offset everything to the right by 16 pixels.
1300+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
1301+
legs->setX(16);
12831302

12841303
drawRecolored(legs);
12851304
}
@@ -1304,6 +1323,10 @@ void UnitSprite::drawRoutine9()
13041323

13051324
if (_unit->getStatus() == STATUS_COLLAPSING)
13061325
torso = _unitSurface->getFrame(die + _unit->getFallingPhase());
1326+
1327+
// offset everything to the right by 16 pixels.
1328+
// this is because we draw the sprites double wide, to accomodate weapons in-hand
1329+
torso->setX(16);
13071330

13081331
drawRecolored(torso);
13091332
}
@@ -1333,14 +1356,15 @@ void UnitSprite::drawRoutine11()
13331356

13341357
Surface *s = _unitSurface->getFrame(body + (_part * 4) + 16 * _unit->getDirection() + animFrame);
13351358
s->setY(4);
1359+
s->setX(16);
13361360
drawRecolored(s);
13371361

13381362
int turret = _unit->getTurretType();
13391363
// draw the turret, overlapping all 4 parts
13401364
if ((_part == 3 || _part == 0) && turret != -1 && !_unit->getFloorAbove())
13411365
{
13421366
s = _unitSurface->getFrame(256 + (turret * 8) + _unit->getTurretDirection());
1343-
s->setX(offTurretX[_unit->getDirection()]);
1367+
s->setX(offTurretX[_unit->getDirection()] + 16);
13441368
if (_part == 3)
13451369
s->setY(offTurretYBelow[_unit->getDirection()]);
13461370
else
@@ -1374,7 +1398,7 @@ void UnitSprite::drawRoutine12()
13741398
drawRecolored(s);
13751399
return;
13761400
}
1377-
1401+
s->setX(16);
13781402
drawRecolored(s);
13791403
}
13801404

@@ -1408,7 +1432,7 @@ void UnitSprite::drawRoutine19()
14081432
{
14091433
s = _unitSurface->getFrame(stand + _unit->getDirection());
14101434
}
1411-
1435+
s->setX(16);
14121436
drawRecolored(s);
14131437
}
14141438

@@ -1433,7 +1457,7 @@ void UnitSprite::drawRoutine20()
14331457
{
14341458
s = _unitSurface->getFrame(5 * (_part + 4 * _unit->getDirection()));
14351459
}
1436-
1460+
s->setX(16);
14371461
drawRecolored(s);
14381462
}
14391463

@@ -1452,7 +1476,7 @@ void UnitSprite::drawRoutine21()
14521476

14531477
s = _unitSurface->getFrame((_part * 4) + (_unit->getDirection() * 16) + (_animationFrame % 4));
14541478
_redraw = true;
1455-
1479+
s->setX(16);
14561480
drawRecolored(s);
14571481
}
14581482

0 commit comments

Comments
 (0)