MCPcopy Create free account
hub / github.com/SimHacker/micropolis / doTrainSprite

Method doTrainSprite

MicropolisCore/src/MicropolisEngine/src/sprite.cpp:618–683  ·  view source on GitHub ↗

* Move train sprite. * @param sprite Train sprite. * @todo Remove local magic constants and document the code. */

Source from the content-addressed store, hash-verified

616 * @todo Remove local magic constants and document the code.
617 */
618void Micropolis::doTrainSprite(SimSprite *sprite)
619{
620 /* Offset in pixels of sprite x and y to map tile */
621 static const short Cx[4] = { 0, 16, 0, -16 };
622 static const short Cy[4] = { -16, 0, 16, 0 };
623 /* X and Y movement of the sprite in pixels */
624 static const short Dx[5] = { 0, 4, 0, -4, 0 };
625 static const short Dy[5] = { -4, 0, 4, 0, 0 };
626
627 static const short TrainPic2[5] = { 1, 2, 1, 2, 5 };
628 short z, dir, dir2;
629 short c;
630
631 if (sprite->frame == 3 || sprite->frame == 4) {
632 sprite->frame = TrainPic2[sprite->dir];
633 }
634
635 sprite->x += Dx[sprite->dir];
636 sprite->y += Dy[sprite->dir];
637
638 if ((spriteCycle & 3) == 0) {
639
640 dir = getRandom16() & 3;
641 for (z = dir; z < dir + 4; z++) {
642 dir2 = z & 3;
643
644 if (sprite->dir != 4) {
645 if (dir2 == ((sprite->dir + 2) & 3)) {
646 continue;
647 }
648 }
649
650 c = getChar(sprite->x + Cx[dir2] + 48, sprite->y + Cy[dir2]);
651
652 if ((c >= RAILBASE && c <= LASTRAIL) /* track? */
653 || c == RAILVPOWERH || c == RAILHPOWERV) {
654
655 if (sprite->dir != dir2 && sprite->dir != 4) {
656
657 if (sprite->dir + dir2 == 3) {
658 sprite->frame = 3;
659 } else {
660 sprite->frame = 4;
661 }
662
663 } else {
664 sprite->frame = TrainPic2[dir2];
665 }
666
667 if (c == HRAIL || c == VRAIL) {
668 sprite->frame = 5;
669 }
670
671 sprite->dir = dir2;
672 return;
673 }
674 }
675

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected