* Move airplane sprite. * @param sprite Airplane sprite. * @todo Remove local magic constants and document the code. * @todo absDist gets updated by Micropolis::getDir(), which is not always * called before reading it (or worse, we just turned towards the old * destination). */
| 793 | * destination). |
| 794 | */ |
| 795 | void Micropolis::doAirplaneSprite( |
| 796 | SimSprite *sprite) |
| 797 | { |
| 798 | static const short CDx[12] = { 0, 0, 6, 8, 6, 0, -6, -8, -6, 8, 8, 8 }; |
| 799 | static const short CDy[12] = { 0, -8, -6, 0, 6, 8, 6, 0, -6, 0, 0, 0 }; |
| 800 | |
| 801 | short z = sprite->frame; |
| 802 | |
| 803 | if ((spriteCycle % 5) == 0) { |
| 804 | |
| 805 | if (z > 8) { /* TakeOff */ |
| 806 | z--; |
| 807 | if (z < 9) { |
| 808 | z = 3; |
| 809 | } |
| 810 | sprite->frame = z; |
| 811 | } else { /* goto destination */ |
| 812 | short d = getDir(sprite->x, sprite->y, sprite->destX, sprite->destY); |
| 813 | z = turnTo(z, d); |
| 814 | sprite->frame = z; |
| 815 | } |
| 816 | |
| 817 | } |
| 818 | |
| 819 | if (absDist < 50) { /* at destination */ |
| 820 | sprite->destX = getRandom((WORLD_W * 16) + 100) - 50; |
| 821 | sprite->destY = getRandom((WORLD_H * 16) + 100) - 50; |
| 822 | } |
| 823 | |
| 824 | /* deh added test for enableDisasters */ |
| 825 | if (enableDisasters) { |
| 826 | SimSprite *s; |
| 827 | bool explode = false; |
| 828 | |
| 829 | /* Check whether another sprite is near enough to collide with */ |
| 830 | for (s = spriteList; s != NULL; s = s->next) { |
| 831 | if (s->frame == 0 || s == sprite) { |
| 832 | /* Non-active sprite, or self: skip */ |
| 833 | continue; |
| 834 | } |
| 835 | |
| 836 | if ((s->type == SPRITE_HELICOPTER || s->type == SPRITE_AIRPLANE) |
| 837 | && checkSpriteCollision(sprite, s)) { |
| 838 | explodeSprite(s); |
| 839 | explode = true; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | if (explode) { |
| 844 | explodeSprite(sprite); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | sprite->x += CDx[z]; |
| 849 | sprite->y += CDy[z]; |
| 850 | |
| 851 | if (spriteNotInBounds(sprite)) { |
| 852 | sprite->frame = 0; |
nothing calls this directly
no outgoing calls
no test coverage detected