1 // Untahris (Common Playground)
2 // copyright (C) 2006 longuens@users.sourceforge.net
3 // Released under GNU General Public License (see the file COPYING)
4 // --------------------------------------------------------------
5 // Xunux
6 
7 struct OXunux : TPlayObject {
8   public:
9   int32 x;
10   int32 y;
11   int32 dir;
12   bool stopped;
13 
OXunuxOXunux14   OXunux(int _owner, int _x, int _y, int _dir) : x(_x), y(_y), dir(_dir) {
15     owner = _owner;
16     g.mapSet(x,y, cXunux, owner);
17     stopped = true;
18     time = g.time;
19     g.objects.push_back(this);
20     }
OXunuxOXunux21   OXunux(TBuffer &b) {
22     b.get(owner);
23     b.get(x); b.get(y); b.get(time); b.get(dir); b.get(stopped);
24     }
saveOXunux25   void save(TBuffer &b) {
26     b.putChar(13);
27     b.put(owner); b.put(x); b.put(y); b.put(time); b.put(dir); b.put(stopped);
28     }
goOXunux29   void go() {
30     if(g.map[y][x] != cXunux) {
31       // it seems something killed us...
32       d.playSoundAt(d.sndDeath, x, y);
33       killedBy(ow()->killer);
34       return;
35       }
36     int sx=x, sy=y;
37     if(stopped) {
38       time += spd();
39       return;
40       }
41     x += kx[dir];
42     y += ky[dir];
43     CellType m = bigType(x,y);
44     if(m != cFree && m != cCannonA && m != cCannonF) {
45       if(m == cBonusScore) {
46         d.playSoundAt(d.sndGreen, x, y);
47         ow()->score += scoreGain() * 2;
48         }
49       if(m == cBonusLevel) {
50         d.playSoundAt(d.sndBlue, x, y);
51         ow()->score += scoreGain() * 10;
52         int ospd = spd();
53         ow()->level++;
54         }
55       if(m == cBonusAmmo) {
56         d.playSoundAt(d.sndRed, x, y);
57         ow()->score += scoreGain();
58         ow()->gainAmmo();
59         }
60       placeBigRandomly(m, 0);
61       clearBig(x, y, cFree, 0);
62       }
63     if(g.map[y][x] == cXunux) {
64       int oo = g.owner[y][x];
65       if(gc.xunuxAttacksXunux) destroyAt(x, y, owner, 0);
66       if(gc.xunuxKillsXunux) destroyAt(sx, sy, oo, 0);
67       time += spd();
68       x=sx; y=sy;
69       }
70     else if(g.map[y][x] == cFree) {
71       g.mapSet(x,y, cXunux, owner);
72       time += spd();
73       }
74     else if(g.map[y][x] == cPermaWall) {
75       x = sx; y = sy;
76       stabilize(x, y);
77       g.map[sy][sx] = cXunux;
78       time += spd();
79       }
80     else if(isXunuxStabilizer(g.map[y][x])) {
81       stabilize(sx, sy);
82       g.mapSet(x,y, cXunux, owner);
83       time += spd();
84       return;
85       }
86     else {
87       killedBy(g.owner[y][x]);
88       destroyAt(sx, sy, owner, 0);
89       }
90     }
reactToKeyOXunux91   void reactToKey(PlayerKey pk, bool pressed) {
92     if(!pressed) {
93       if(int(pk) < 4 && dir == int(pk)) stopped = true;
94       return;
95       }
96     if(int(pk)<4 && (stopped || int(pk) != (dir^2))) dir = int(pk), stopped = false;
97     if((pk == keyFire || pk == keyEarth || pk == keyAir || pk == keyWater) && ow()->useAmmo()) {
98       d.playSoundAt(d.sndShoot, x, y);
99       new OBullet(owner, Ctr(x) + kx[dir] * 2048, Ctr(y) + ky[dir] * 2048, kx[dir] * bulletSpeed(), ky[dir] * bulletSpeed());
100       }
101     }
102   };
103