Cube  Diff

Differences From Artifact [adb5f670f2]:

To Artifact [7b928c8e1c]:


1
2
3
4
5
6
7

8
9
10










11
12
13
14

15


16
17


18
19

20

21

22
23
24
25
26





27
28
29
30




31
32




33
34
35



36
37
38
39
40
41











42
43
44
45
46
47
48
49
50





























51
52
53
54
55
56
57



58
59
60

61
62
63
64
65
66
67
68
69
70





























71
72



73


74
75
76
77

78

79
80
81
82
83
84






85
86

87

88
89

90
91
92
93
94
95
96


















97
98
99
100
101




102
103
104
105
106




107
108
109
110
111
112





113
114
115
116

117

118

119
120
121
122
123







124
125

126

127
128
129


130
131
132
133
134








135
136
137
138
139
140
141
142
143
144
145
146











147
148

149

150
151
152
153
154
155






156
157
158
159
160
161
162


















163
164
165
166
167
168






169
170
171
172



173
174
175
176
177
178
179
180
181
182










183
184

185
186
187
188
189
190
191
192
193









194
195
196
197
198
199
200
201
202
203
204












205
206

207

208
209
210
211
212
213
214
215
216
217
218
219
















220
221

222

223
224

225
226
227
228
229




230
231

232

233
234
235
236
237
238






239
240



241
242








1
2
3
4
5
6

7



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25

26
27
28
29
30

31
32
33





34
35
36
37
38




39
40
41
42


43
44
45
46



47
48
49






50
51
52
53
54
55
56
57
58
59
60

61
62
63





64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93






94
95
96
97
98

99










100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140

141
142





143
144
145
146
147
148
149
150
151

152
153

154







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173




174
175
176
177
178




179
180
181
182
183





184
185
186
187
188
189
190
191
192
193

194
195
196





197
198
199
200
201
202
203
204
205
206

207
208


209
210





211
212
213
214
215
216
217
218












219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234





235
236
237
238
239
240







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259





260
261
262
263
264
265
266



267
268
269
270









271
272
273
274
275
276
277
278
279
280
281

282









283
284
285
286
287
288
289
290
291











292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308











309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329

330





331
332
333
334
335
336
337

338
339





340
341
342
343
344
345
346
347
348
349
350


351
352
353
354
355
356
357
358






-
+
-
-
-
+
+
+
+
+
+
+
+
+
+




+
-
+
+

-
+
+


+
-
+

+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-



-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+


-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
-
+
+




+
-
+

-
-
-
-
-
+
+
+
+
+
+


+
-
+

-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+
+




+
-
+

+
-
-
-
-
-
+
+
+
+
+
+
+


+
-
+

-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


+
-
+

-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


+
-
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
-
+

-
+
-
-
-
-
-
+
+
+
+


+
-
+

-
-
-
-
-
+
+
+
+
+
+


+
+
+
-
-
+
+
+
+
+
+
+
+
// entities.cpp: map entity related functions (pickup etc.)

#include "cube.h"

vector<entity> ents;

char *entmdlnames[] = 
char *entmdlnames[] = {
{
	"shells", "bullets", "rockets", "rrounds", "health", "boost",
	"g_armour", "y_armour", "quad",	"teleporter",     
    "shells",
    "bullets",
    "rockets",
    "rrounds",
    "health",
    "boost",
    "g_armour",
    "y_armour",
    "quad",
    "teleporter",
};

int triggertime = 0;

void
void renderent(entity &e, char *mdlname, float z, float yaw, int frame = 0, int numf = 1, int basetime = 0, float speed = 10.0f)
renderent(entity &e, char *mdlname, float z, float yaw, int frame = 0,
    int numf = 1, int basetime = 0, float speed = 10.0f)
{
	rendermodel(mdlname, frame, numf, 0, 1.1f, e.x, z+S(e.x, e.y)->floor, e.y, yaw, 0, false, 1.0f, speed, 0, basetime);
	rendermodel(mdlname, frame, numf, 0, 1.1f, e.x, z + S(e.x, e.y)->floor,
	    e.y, yaw, 0, false, 1.0f, speed, 0, basetime);
};

void
void renderentities()
renderentities()
{
	if (lastmillis > triggertime + 1000)
	if(lastmillis>triggertime+1000) triggertime = 0;
    loopv(ents)
    {
        entity &e = ents[i];
        if(e.type==MAPMODEL)
		triggertime = 0;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == MAPMODEL) {
        {
            mapmodelinfo &mmi = getmminfo(e.attr2);
            if(!&mmi) continue;
			rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad, e.x, (float)S(e.x, e.y)->floor+mmi.zoff+e.attr3, e.y, (float)((e.attr1+7)-(e.attr1+7)%15), 0, false, 1.0f, 10.0f, mmi.snap);
			mapmodelinfo &mmi = getmminfo(e.attr2);
			if (!&mmi)
				continue;
			rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad,
        }
        else
			    e.x, (float)S(e.x, e.y)->floor + mmi.zoff + e.attr3,
			    e.y, (float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0,
			    false, 1.0f, 10.0f, mmi.snap);
		} else {
        {
            if(OUTBORD(e.x, e.y)) continue;
            if(e.type!=CARROT)
			if (OUTBORD(e.x, e.y))
				continue;
			if (e.type != CARROT) {
            {
				if(!e.spawned && e.type!=TELEPORT) continue;
				if(e.type<I_SHELLS || e.type>TELEPORT) continue;
				renderent(e, entmdlnames[e.type-I_SHELLS], (float)(1+sin(lastmillis/100.0+e.x+e.y)/20), lastmillis/10.0f);
            }
			else switch(e.attr2)
				if (!e.spawned && e.type != TELEPORT)
					continue;
				if (e.type < I_SHELLS || e.type > TELEPORT)
					continue;
				renderent(e, entmdlnames[e.type - I_SHELLS],
				    (float)(1 + sin(lastmillis / 100.0 + e.x +
				                    e.y) /
				                    20),
				    lastmillis / 10.0f);
			} else
				switch (e.attr2) {
            {			
				case 1:
				case 3:
					continue;
					
                case 2: 
                case 0:
					if(!e.spawned) continue;
					renderent(e, "carrot", (float)(1+sin(lastmillis/100.0+e.x+e.y)/20), lastmillis/(e.attr2 ? 1.0f : 10.0f));

				case 2:
				case 0:
					if (!e.spawned)
						continue;
					renderent(e, "carrot",
					    (float)(1 + sin(lastmillis / 100.0 +
					                    e.x + e.y) /
					                    20),
					    lastmillis /
					        (e.attr2 ? 1.0f : 10.0f));
					break;

				case 4:
					renderent(e, "switch2", 3,
					    (float)e.attr3 * 90,
					    (!e.spawned && !triggertime) ? 1
					                                 : 0,
					    (e.spawned || !triggertime) ? 1 : 2,
					    triggertime, 1050.0f);
					break;
				case 5:
					renderent(e, "switch1", -0.15f,
					    (float)e.attr3 * 90,
					    (!e.spawned && !triggertime) ? 30
					                                 : 0,
					    (e.spawned || !triggertime) ? 1
					                                : 30,
					    triggertime, 35.0f);
					break;
					
                case 4: renderent(e, "switch2", 3,      (float)e.attr3*90, (!e.spawned && !triggertime) ? 1  : 0, (e.spawned || !triggertime) ? 1 : 2,  triggertime, 1050.0f);  break;
                case 5: renderent(e, "switch1", -0.15f, (float)e.attr3*90, (!e.spawned && !triggertime) ? 30 : 0, (e.spawned || !triggertime) ? 1 : 30, triggertime, 35.0f); break;
            }; 
        };
    };
				};
		};
	};
};

struct itemstat { int add, max, sound; } itemstats[] =
struct itemstat {
{
     10,    50, S_ITEMAMMO,
     20,   100, S_ITEMAMMO,
      5,    25, S_ITEMAMMO,
      5,    25, S_ITEMAMMO,
     25,   100, S_ITEMHEALTH,
     50,   200, S_ITEMHEALTH,
    100,   100, S_ITEMARMOUR,
    150,   150, S_ITEMARMOUR,
  20000, 30000, S_ITEMPUP,
	int add, max, sound;
} itemstats[] = {
    10,
    50,
    S_ITEMAMMO,
    20,
    100,
    S_ITEMAMMO,
    5,
    25,
    S_ITEMAMMO,
    5,
    25,
    S_ITEMAMMO,
    25,
    100,
    S_ITEMHEALTH,
    50,
    200,
    S_ITEMHEALTH,
    100,
    100,
    S_ITEMARMOUR,
    150,
    150,
    S_ITEMARMOUR,
    20000,
    30000,
    S_ITEMPUP,
};

void
baseammo(int gun)
{
void baseammo(int gun) { player1->ammo[gun] = itemstats[gun-1].add*2; };
	player1->ammo[gun] = itemstats[gun - 1].add * 2;
};

// these two functions are called when the server acknowledges that you really
// picked up the item (in multiplayer someone may grab it before you).

void
void radditem(int i, int &v)
radditem(int i, int &v)
{
    itemstat &is = itemstats[ents[i].type-I_SHELLS];
    ents[i].spawned = false;
    v += is.add;
    if(v>is.max) v = is.max;
    playsoundc(is.sound);
	itemstat &is = itemstats[ents[i].type - I_SHELLS];
	ents[i].spawned = false;
	v += is.add;
	if (v > is.max)
		v = is.max;
	playsoundc(is.sound);
};

void
void realpickup(int n, dynent *d)
realpickup(int n, dynent *d)
{
    switch(ents[n].type)
	switch (ents[n].type) {
    {
        case I_SHELLS:  radditem(n, d->ammo[1]); break;
        case I_BULLETS: radditem(n, d->ammo[2]); break;
        case I_ROCKETS: radditem(n, d->ammo[3]); break;
        case I_ROUNDS:  radditem(n, d->ammo[4]); break;
        case I_HEALTH:  radditem(n, d->health);  break;
        case I_BOOST:   radditem(n, d->health);  break;
	case I_SHELLS:
		radditem(n, d->ammo[1]);
		break;
	case I_BULLETS:
		radditem(n, d->ammo[2]);
		break;
	case I_ROCKETS:
		radditem(n, d->ammo[3]);
		break;
	case I_ROUNDS:
		radditem(n, d->ammo[4]);
		break;
	case I_HEALTH:
		radditem(n, d->health);
		break;
	case I_BOOST:
		radditem(n, d->health);
		break;

        case I_GREENARMOUR:
            radditem(n, d->armour);
            d->armourtype = A_GREEN;
            break;
	case I_GREENARMOUR:
		radditem(n, d->armour);
		d->armourtype = A_GREEN;
		break;

        case I_YELLOWARMOUR:
            radditem(n, d->armour);
            d->armourtype = A_YELLOW;
            break;
	case I_YELLOWARMOUR:
		radditem(n, d->armour);
		d->armourtype = A_YELLOW;
		break;

        case I_QUAD:
            radditem(n, d->quadmillis);
            conoutf("you got the quad!");
            break;
    };
	case I_QUAD:
		radditem(n, d->quadmillis);
		conoutf("you got the quad!");
		break;
	};
};

// these functions are called when the client touches the item

void
void additem(int i, int &v, int spawnsec)
additem(int i, int &v, int spawnsec)
{
	if (v < itemstats[ents[i].type - I_SHELLS]
    if(v<itemstats[ents[i].type-I_SHELLS].max)                              // don't pick up if not needed
    {
        addmsg(1, 3, SV_ITEMPICKUP, i, m_classicsp ? 100000 : spawnsec);    // first ask the server for an ack
        ents[i].spawned = false;                                            // even if someone else gets it first
    };
	            .max) // don't pick up if not needed
	{
		addmsg(1, 3, SV_ITEMPICKUP, i,
		    m_classicsp ? 100000
		                : spawnsec); // first ask the server for an ack
		ents[i].spawned = false; // even if someone else gets it first
	};
};

void
void teleport(int n, dynent *d)     // also used by monsters
teleport(int n, dynent *d) // also used by monsters
{
    int e = -1, tag = ents[n].attr1, beenhere = -1;
    for(;;)
	int e = -1, tag = ents[n].attr1, beenhere = -1;
	for (;;) {
    {
        e = findentity(TELEDEST, e+1);
        if(e==beenhere || e<0) { conoutf("no teleport destination for tag %d", tag); return; };
        if(beenhere<0) beenhere = e;
        if(ents[e].attr2==tag)
		e = findentity(TELEDEST, e + 1);
		if (e == beenhere || e < 0) {
			conoutf("no teleport destination for tag %d", tag);
			return;
		};
		if (beenhere < 0)
			beenhere = e;
		if (ents[e].attr2 == tag) {
        {
            d->o.x = ents[e].x;
            d->o.y = ents[e].y;
            d->o.z = ents[e].z;
            d->yaw = ents[e].attr1;
            d->pitch = 0;
            d->vel.x = d->vel.y = d->vel.z = 0;
            entinmap(d);
            playsoundc(S_TELEPORT);
            break;
        };
    };
			d->o.x = ents[e].x;
			d->o.y = ents[e].y;
			d->o.z = ents[e].z;
			d->yaw = ents[e].attr1;
			d->pitch = 0;
			d->vel.x = d->vel.y = d->vel.z = 0;
			entinmap(d);
			playsoundc(S_TELEPORT);
			break;
		};
	};
};

void
void pickup(int n, dynent *d)
pickup(int n, dynent *d)
{
    int np = 1;
    loopv(players) if(players[i]) np++;
    np = np<3 ? 4 : (np>4 ? 2 : 3);         // spawn times are dependent on number of players
    int ammo = np*2;
    switch(ents[n].type)
	int np = 1;
	loopv(players) if (players[i]) np++;
	np = np < 3 ? 4 : (np > 4 ? 2 : 3); // spawn times are dependent on
	                                    // number of players
	int ammo = np * 2;
	switch (ents[n].type) {
    {
        case I_SHELLS:  additem(n, d->ammo[1], ammo); break;
        case I_BULLETS: additem(n, d->ammo[2], ammo); break;
        case I_ROCKETS: additem(n, d->ammo[3], ammo); break;
        case I_ROUNDS:  additem(n, d->ammo[4], ammo); break;
        case I_HEALTH:  additem(n, d->health,  np*5); break;
        case I_BOOST:   additem(n, d->health,  60);   break;
	case I_SHELLS:
		additem(n, d->ammo[1], ammo);
		break;
	case I_BULLETS:
		additem(n, d->ammo[2], ammo);
		break;
	case I_ROCKETS:
		additem(n, d->ammo[3], ammo);
		break;
	case I_ROUNDS:
		additem(n, d->ammo[4], ammo);
		break;
	case I_HEALTH:
		additem(n, d->health, np * 5);
		break;
	case I_BOOST:
		additem(n, d->health, 60);
		break;

        case I_GREENARMOUR:
            // (100h/100g only absorbs 166 damage)
            if(d->armourtype==A_YELLOW && d->armour>66) break;
            additem(n, d->armour, 20);
            break;
	case I_GREENARMOUR:
		// (100h/100g only absorbs 166 damage)
		if (d->armourtype == A_YELLOW && d->armour > 66)
			break;
		additem(n, d->armour, 20);
		break;

        case I_YELLOWARMOUR:
            additem(n, d->armour, 20);
            break;
	case I_YELLOWARMOUR:
		additem(n, d->armour, 20);
		break;

        case I_QUAD:
            additem(n, d->quadmillis, 60);
            break;
            
        case CARROT:
            ents[n].spawned = false;
            triggertime = lastmillis;
            trigger(ents[n].attr1, ents[n].attr2, false);  // needs to go over server for multiplayer
            break;
	case I_QUAD:
		additem(n, d->quadmillis, 60);
		break;

	case CARROT:
		ents[n].spawned = false;
		triggertime = lastmillis;
		trigger(ents[n].attr1, ents[n].attr2,
		    false); // needs to go over server for multiplayer
		break;

        case TELEPORT:
	case TELEPORT: {
        {
            static int lastteleport = 0;
            if(lastmillis-lastteleport<500) break;
            lastteleport = lastmillis;
            teleport(n, d);
            break;
        };
        
        case JUMPPAD:
		static int lastteleport = 0;
		if (lastmillis - lastteleport < 500)
			break;
		lastteleport = lastmillis;
		teleport(n, d);
		break;
	};

	case JUMPPAD: {
        {
            static int lastjumppad = 0;
            if(lastmillis-lastjumppad<300) break;
            lastjumppad = lastmillis;
            vec v = { (int)(char)ents[n].attr3/10.0f, (int)(char)ents[n].attr2/10.0f, ents[n].attr1/10.0f };
            player1->vel.z = 0;
			vadd(player1->vel, v);
            playsoundc(S_JUMPPAD);
            break;
        };
    };
		static int lastjumppad = 0;
		if (lastmillis - lastjumppad < 300)
			break;
		lastjumppad = lastmillis;
		vec v = {(int)(char)ents[n].attr3 / 10.0f,
		    (int)(char)ents[n].attr2 / 10.0f, ents[n].attr1 / 10.0f};
		player1->vel.z = 0;
		vadd(player1->vel, v);
		playsoundc(S_JUMPPAD);
		break;
	};
	};
};

void
void checkitems()
checkitems()
{
    if(editmode) return;
    loopv(ents)
    {
        entity &e = ents[i];
        if(e.type==NOTUSED) continue;
        if(!ents[i].spawned && e.type!=TELEPORT && e.type!=JUMPPAD) continue;
        if(OUTBORD(e.x, e.y)) continue;
        vec v = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight };
        vdist(dist, t, player1->o, v);
        if(dist<(e.type==TELEPORT ? 4 : 2.5)) pickup(i, player1);
    };
	if (editmode)
		return;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == NOTUSED)
			continue;
		if (!ents[i].spawned && e.type != TELEPORT && e.type != JUMPPAD)
			continue;
		if (OUTBORD(e.x, e.y))
			continue;
		vec v = {e.x, e.y, S(e.x, e.y)->floor + player1->eyeheight};
		vdist(dist, t, player1->o, v);
		if (dist < (e.type == TELEPORT ? 4 : 2.5))
			pickup(i, player1);
	};
};

void
void checkquad(int time)
checkquad(int time)
{
    if(player1->quadmillis && (player1->quadmillis -= time)<0)
	if (player1->quadmillis && (player1->quadmillis -= time) < 0) {
    {
        player1->quadmillis = 0;
        playsoundc(S_PUPOUT);
        conoutf("quad damage is over");
    };
		player1->quadmillis = 0;
		playsoundc(S_PUPOUT);
		conoutf("quad damage is over");
	};
};

void
void putitems(uchar *&p)            // puts items in network stream and also spawns them locally
putitems(uchar *&p) // puts items in network stream and also spawns them locally
{
    loopv(ents) if((ents[i].type>=I_SHELLS && ents[i].type<=I_QUAD) || ents[i].type==CARROT)
    {
        putint(p, i);
        ents[i].spawned = true;
    };
	loopv(ents) if ((ents[i].type >= I_SHELLS && ents[i].type <= I_QUAD) ||
	                ents[i].type == CARROT)
	{
		putint(p, i);
		ents[i].spawned = true;
	};
};

void
resetspawns()
{
void resetspawns() { loopv(ents) ents[i].spawned = false; };
void setspawn(uint i, bool on) { if(i<(uint)ents.length()) ents[i].spawned = on; };
	loopv(ents) ents[i].spawned = false;
};
void
setspawn(uint i, bool on)
{
	if (i < (uint)ents.length())
		ents[i].spawned = on;
};