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

Method doShipSprite

MicropolisCore/src/MicropolisEngine/src/sprite.cpp:862–974  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

860 * @todo Remove local magic constants and document the code.
861 */
862void Micropolis::doShipSprite(SimSprite *sprite)
863{
864 static const short BDx[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 };
865 static const short BDy[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 };
866 static const short BPx[9] = { 0, 0, 2, 2, 2, 0, -2, -2, -2 };
867 static const short BPy[9] = { 0, -2, -2, 0, 2, 2, 2, 0, -2 };
868 static const short BtClrTab[8] = { RIVER, CHANNEL, POWERBASE, POWERBASE + 1,
869 RAILBASE, RAILBASE + 1, BRWH, BRWV };
870 short x, y, z, t = RIVER;
871 short tem, pem;
872
873 if (sprite->soundCount > 0) {
874 sprite->soundCount--;
875 }
876
877 if (!sprite->soundCount) {
878
879 if ((getRandom16() & 3) == 1) {
880
881 // Convert sprite coordinates to tile coordinates.
882 int shipX = sprite->x >>4;
883 int shipY = sprite->y >>4;
884
885 if (scenario == SC_SAN_FRANCISCO && getRandom(10) < 5) {
886 makeSound("city", "FogHornLow", shipX, shipY);
887 } else {
888 makeSound("city", "HonkHonkLow", shipX, shipY);
889 }
890
891 }
892
893 sprite->soundCount = 200;
894 }
895
896 if (sprite->count > 0) {
897 sprite->count--;
898 }
899
900 if (sprite->count == 0) {
901
902 sprite->count = 9;
903
904 if (sprite->frame != sprite->newDir) {
905 sprite->frame = turnTo(sprite->frame, sprite->newDir);
906 return;
907 }
908
909 tem = getRandom16() & 7;
910
911 for (pem = tem; pem < (tem + 8); pem++) {
912
913 z = (pem & 7) + 1;
914
915 if (z == sprite->dir) {
916 continue;
917 }
918
919 x = ((sprite->x + (48 - 1)) >>4) + BDx[z];

Callers

nothing calls this directly

Calls 1

testBoundsFunction · 0.85

Tested by

no test coverage detected