Cube  Diff

Differences From Artifact [95d4c13f64]:

To Artifact [775d6c79ad]:


11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26
11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26







-
-
+
+







#import "MapModelInfo.h"
#import "Monster.h"
#import "Player.h"
#import "Variable.h"

// collide with player or monster
static bool
plcollide(
    DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi, float *lo)
plcollide(DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi,
    float *lo)
{
	if (o.state != CS_ALIVE)
		return true;

	const float r = o.radius + d.radius;
	if (fabs(o.origin.x - d.origin.x) < r &&
	    fabs(o.origin.y - d.origin.y) < r) {
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
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







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







-
-
+
+
-



-
-
+
+
-







			float floor = s->floor;

			switch (s->type) {
			case SOLID:
				return false;
			case CORNER: {
				int bx = x, by = y, bs = 1;
				if ((x == x1 && y == y1 &&
				if ((x == x1 && y == y1 && cornertest(0, x, y,
				        cornertest(
				            0, x, y, -1, -1, &bx, &by, &bs) &&
				    -1, -1, &bx, &by, &bs) && fx1 - bx + fy1 -
				        fx1 - bx + fy1 - by <= bs) ||
				    (x == x2 && y == y1 &&
				    by <= bs) || (x == x2 && y == y1 &&
				        cornertest(
				            0, x, y, 1, -1, &bx, &by, &bs) &&
				        fx2 - bx >= fy1 - by) ||
				    cornertest(0, x, y, 1, -1, &bx, &by, &bs) &&
				    fx2 - bx >= fy1 - by) || (x == x1 && y ==
				    (x == x1 && y == y2 &&
				        cornertest(
				            0, x, y, -1, 1, &bx, &by, &bs) &&
				        fx1 - bx <= fy2 - by) ||
				    y2 && cornertest(0, x, y, -1, 1, &bx, &by,
				    &bs) && fx1 - bx <= fy2 - by) || (x == x2 &&
				    (x == x2 && y == y2 &&
				        cornertest(
				            0, x, y, 1, 1, &bx, &by, &bs) &&
				        fx2 - bx + fy2 - by >= bs))
				    y == y2 && cornertest(0, x, y, 1, 1, &bx,
				    &by, &bs) && fx2 - bx + fy2 - by >= bs))
					return false;
				break;
			}
			// FIXME: too simplistic collision with slopes, makes
			// it feels like tiny stairs
			case FHF:
				floor -= (s->vdelta + S(x + 1, y)->vdelta +
				             S(x, y + 1)->vdelta +
				             S(x + 1, y + 1)->vdelta) /
				    S(x, y + 1)->vdelta +
				    S(x + 1, y + 1)->vdelta) / 16.0f;
				    16.0f;
				break;
			case CHF:
				ceil += (s->vdelta + S(x + 1, y)->vdelta +
				            S(x, y + 1)->vdelta +
				            S(x + 1, y + 1)->vdelta) /
				    S(x, y + 1)->vdelta +
				    S(x + 1, y + 1)->vdelta) / 16.0f;
				    16.0f;
			}

			if (ceil < hi)
				hi = ceil;
			if (floor > lo)
				lo = floor;
			if (floor < minfloor)
210
211
212
213
214
215
216
217

218
219

220
221
222
223
224
225
226
201
202
203
204
205
206
207

208


209
210
211
212
213
214
215
216







-
+
-
-
+







				// rise thru stair
				d.origin = OFAddVectors3D(
				    d.origin, OFMakeVector3D(0, 0, rise));
			else
				return false;
		} else
			// gravity
			d.origin = OFSubtractVectors3D(d.origin,
			d.origin = OFSubtractVectors3D(d.origin, OFMakeVector3D(
			    OFMakeVector3D(
			        0, 0, min(min(drop, space), headspace)));
			    0, 0, min(min(drop, space), headspace)));

		const float space2 = hi - (d.origin.z + d.aboveEye);
		if (space2 < 0) {
			if (space2 < -0.1)
				return false; // hack alert!
			// glue to ceiling
			d.origin = OFMakeVector3D(
403
404
405
406
407
408
409
410

411
412
413
414



415
416
417
418
419
420
421
393
394
395
396
397
398
399

400




401
402
403
404
405
406
407
408
409
410







-
+
-
-
-
-
+
+
+







	// mostly

	if (pl.origin.x < 0 || pl.origin.x >= ssize || pl.origin.y < 0 ||
	    pl.origin.y > ssize)
		pl.outsideMap = true;
	else {
		struct sqr *s = S((int)pl.origin.x, (int)pl.origin.y);
		pl.outsideMap = SOLID(s) ||
		pl.outsideMap = (SOLID(s) || pl.origin.z < s->floor -
		    pl.origin.z <
		        s->floor - (s->type == FHF ? s->vdelta / 4 : 0) ||
		    pl.origin.z >
		        s->ceil + (s->type == CHF ? s->vdelta / 4 : 0);
		    (s->type == FHF ? s->vdelta / 4 : 0) ||
		    pl.origin.z > s->ceil + (s->type == CHF
		    ? s->vdelta / 4 : 0));
	}

	// automatically apply smooth roll when strafing

	if (pl.strafe == 0)
		pl.roll = pl.roll / (1 + (float)sqrt((float)curtime) / 25);
	else {
439
440
441
442
443
444
445
446

447
448
449

450
428
429
430
431
432
433
434

435



436
437







-
+
-
-
-
+

	pl.inWater = water;
}

void
moveplayer(DynamicEntity *pl, int moveres, bool local)
{
	for (int i = 0; i < physicsrepeat; i++)
		moveplayer4(pl, moveres, local,
		moveplayer4(pl, moveres, local, i ? curtime / physicsrepeat
		    i ? curtime / physicsrepeat
		      : curtime -
		            curtime / physicsrepeat * (physicsrepeat - 1));
		    : curtime - curtime / physicsrepeat * (physicsrepeat - 1));
}