Cube  Diff

Differences From Artifact [cee211ba17]:

To Artifact [50f4e28f8c]:


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
			if (y > maxy)
				maxy = y;
			if (x < minx)
				minx = x;
			if (y < miny)
				miny = y;
		};
	};

	block b = {minx, miny, maxx - minx + 1, maxy - miny + 1};
	if (maxx)
		remip(b); // remip minimal area of changed geometry
};


void
resettagareas()
{
	settag(0, 0);
}; // reset for editing or map saving
void
settagareas()
{
	settag(0, 1);
	loopv(ents) if (ents[i].type == CARROT) setspawn(i, true);
}; // set for playing

void
trigger(int tag, int type, bool savegame)
{
	if (!tag)
		return;








<
>



<
>





|





|







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
			if (y > maxy)
				maxy = y;
			if (x < minx)
				minx = x;
			if (y < miny)
				miny = y;
		};

	}
	block b = {minx, miny, maxx - minx + 1, maxy - miny + 1};
	if (maxx)
		remip(b); // remip minimal area of changed geometry

}

void
resettagareas()
{
	settag(0, 0);
} // reset for editing or map saving
void
settagareas()
{
	settag(0, 1);
	loopv(ents) if (ents[i].type == CARROT) setspawn(i, true);
} // set for playing

void
trigger(int tag, int type, bool savegame)
{
	if (!tag)
		return;

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
				{
					num++;
					int fh = o[i]->floor;
					int ch = o[i]->ceil;
					if (r->type == SEMISOLID) {
						if (o[i]->type == FHF)
							fh -= o[i]->vdelta / 4 +
							      2; // crap hack,
							         // needed for
							         // rendering
							         // large mips
							         // next to hfs
						if (o[i]->type == CHF)
							ch +=
							    o[i]->vdelta / 4 +
							    2; // FIXME: needs
							       // to somehow
							       // take into
							       // account middle
							       // vertices on
							       // higher mips
					};
					if (fh < floor)
						floor =
						    fh; // take lowest floor and
						        // highest ceil, so we
						        // never have to see
						        // missing lower/upper
						        // from the side
					if (ch > ceil)
						ceil = ch;
				};

				r->floor = floor;
				r->ceil = ceil;
			};
			if (r->type == CORNER)
				goto mip; // special case: don't ever split even
				          // if textures etc are different
			r->defer = 1;
			if (SOLID(r)) {
				loopi(3)
				{
					if (o[i]->wtex != o[3]->wtex)
						goto c; // on an all solid cube,
						        // only thing that needs
						        // to be equal for a
						        // perfect mip is the
						        // wall texture
				};

			} else {
				loopi(3)
				{
					if (o[i]->type != o[3]->type ||
					    o[i]->floor != o[3]->floor ||
					    o[i]->ceil != o[3]->ceil ||
					    o[i]->ftex != o[3]->ftex ||
					    o[i]->ctex != o[3]->ctex ||
					    abs(o[i + 1]->r - o[0]->r) >
					        lighterr // perfect mip even if
					                 // light is not exactly
					                 // equal
					    || abs(o[i + 1]->g - o[0]->g) >
					           lighterr ||
					    abs(o[i + 1]->b - o[0]->b) >
					        lighterr ||
					    o[i]->utex != o[3]->utex ||
					    o[i]->wtex != o[3]->wtex)
						goto c;
				};

				if (r->type == CHF ||
				    r->type ==
				        FHF) // can make a perfect mip out of a
				             // hf if slopes lie on one line
				{
					if (o[0]->vdelta - o[1]->vdelta !=
					        o[1]->vdelta -







|
|
|
|
|

<
|
















<
>
















<
>













|





<
>







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
				{
					num++;
					int fh = o[i]->floor;
					int ch = o[i]->ceil;
					if (r->type == SEMISOLID) {
						if (o[i]->type == FHF)
							fh -= o[i]->vdelta / 4 +
							    2; // crap hack,
							       // needed for
							       // rendering
							       // large mips
							       // next to hfs
						if (o[i]->type == CHF)

							ch += o[i]->vdelta / 4 +
							    2; // FIXME: needs
							       // to somehow
							       // take into
							       // account middle
							       // vertices on
							       // higher mips
					};
					if (fh < floor)
						floor =
						    fh; // take lowest floor and
						        // highest ceil, so we
						        // never have to see
						        // missing lower/upper
						        // from the side
					if (ch > ceil)
						ceil = ch;

				}
				r->floor = floor;
				r->ceil = ceil;
			};
			if (r->type == CORNER)
				goto mip; // special case: don't ever split even
				          // if textures etc are different
			r->defer = 1;
			if (SOLID(r)) {
				loopi(3)
				{
					if (o[i]->wtex != o[3]->wtex)
						goto c; // on an all solid cube,
						        // only thing that needs
						        // to be equal for a
						        // perfect mip is the
						        // wall texture

				}
			} else {
				loopi(3)
				{
					if (o[i]->type != o[3]->type ||
					    o[i]->floor != o[3]->floor ||
					    o[i]->ceil != o[3]->ceil ||
					    o[i]->ftex != o[3]->ftex ||
					    o[i]->ctex != o[3]->ctex ||
					    abs(o[i + 1]->r - o[0]->r) >
					        lighterr // perfect mip even if
					                 // light is not exactly
					                 // equal
					    || abs(o[i + 1]->g - o[0]->g) >
					        lighterr ||
					    abs(o[i + 1]->b - o[0]->b) >
					        lighterr ||
					    o[i]->utex != o[3]->utex ||
					    o[i]->wtex != o[3]->wtex)
						goto c;

				}
				if (r->type == CHF ||
				    r->type ==
				        FHF) // can make a perfect mip out of a
				             // hf if slopes lie on one line
				{
					if (o[0]->vdelta - o[1]->vdelta !=
					        o[1]->vdelta -
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
		c:;
		};
	s.x /= 2;
	s.y /= 2;
	s.xs /= 2;
	s.ys /= 2;
	remip(s, level + 1);
};


void
remipmore(block &b, int level)
{
	block bb = b;
	if (bb.x > 1)
		bb.x--;
	if (bb.y > 1)
		bb.y--;
	if (bb.xs < ssize - 3)
		bb.xs++;
	if (bb.ys < ssize - 3)
		bb.ys++;
	remip(bb, level);
};


int
closestent() // used for delent and edit mode ent display
{
	if (noteditmode())
		return -1;
	int best;
	float bdist = 99999;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == NOTUSED)
			continue;
		OFVector3D v = OFMakeVector3D(e.x, e.y, e.z);
		vdist(dist, t, player1->o, v);
		if (dist < bdist) {
			best = i;
			bdist = dist;
		};
	};

	return bdist == 99999 ? -1 : best;
};


void
entproperty(int prop, int amount)
{
	int e = closestent();
	if (e < 0)
		return;







<
>














<
>



















<
>

<
>







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
		c:;
		};
	s.x /= 2;
	s.y /= 2;
	s.xs /= 2;
	s.ys /= 2;
	remip(s, level + 1);

}

void
remipmore(block &b, int level)
{
	block bb = b;
	if (bb.x > 1)
		bb.x--;
	if (bb.y > 1)
		bb.y--;
	if (bb.xs < ssize - 3)
		bb.xs++;
	if (bb.ys < ssize - 3)
		bb.ys++;
	remip(bb, level);

}

int
closestent() // used for delent and edit mode ent display
{
	if (noteditmode())
		return -1;
	int best;
	float bdist = 99999;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == NOTUSED)
			continue;
		OFVector3D v = OFMakeVector3D(e.x, e.y, e.z);
		vdist(dist, t, player1->o, v);
		if (dist < bdist) {
			best = i;
			bdist = dist;
		};

	}
	return bdist == 99999 ? -1 : best;

}

void
entproperty(int prop, int amount)
{
	int e = closestent();
	if (e < 0)
		return;
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
	case 2:
		ents[e].attr3 += amount;
		break;
	case 3:
		ents[e].attr4 += amount;
		break;
	};
};


void
delent()
{
	int e = closestent();
	if (e < 0) {
		conoutf(@"no more entities");







<
>







288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
	case 2:
		ents[e].attr3 += amount;
		break;
	case 3:
		ents[e].attr4 += amount;
		break;
	};

}

void
delent()
{
	int e = closestent();
	if (e < 0) {
		conoutf(@"no more entities");
351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433


434
435
436
437
438
439
440
	};
	addmsg(1, 10, SV_EDITENT, ents.length(), type, e.x, e.y, e.z, e.attr1,
	    e.attr2, e.attr3, e.attr4);
	ents.add(*((entity *)&e)); // unsafe!
	if (type == LIGHT)
		calclight();
	return &ents.last();
};


void
clearents(OFString *name)
{
	int type = findtype(name);
	if (noteditmode() || multiplayer())
		return;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == type)
			e.type = NOTUSED;
	};

	if (type == LIGHT)
		calclight();
}
COMMAND(clearents, ARG_1STR)

void
scalecomp(uchar &c, int intens)
{
	int n = c * intens / 100;
	if (n > 255)
		n = 255;
	c = n;
};


void
scalelights(int f, int intens)
{
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type != LIGHT)
			continue;
		e.attr1 = e.attr1 * f / 100;
		if (e.attr1 < 2)
			e.attr1 = 2;
		if (e.attr1 > 32)
			e.attr1 = 32;
		if (intens) {
			scalecomp(e.attr2, intens);
			scalecomp(e.attr3, intens);
			scalecomp(e.attr4, intens);
		};
	};

	calclight();
}
COMMAND(scalelights, ARG_2INT)

int
findentity(int type, int index)
{
	for (int i = index; i < ents.length(); i++)
		if (ents[i].type == type)
			return i;
	loopj(index) if (ents[j].type == type) return j;
	return -1;
};


sqr *wmip[LARGEST_FACTOR * 2];

void
setupworld(int factor)
{
	ssize = 1 << (sfactor = factor);
	cubicsize = ssize * ssize;
	mipsize = cubicsize * 134 / 100;
	sqr *w = world = (sqr *)alloc(mipsize * sizeof(sqr));
	loopi(LARGEST_FACTOR * 2)
	{
		wmip[i] = w;
		w += cubicsize >> (i * 2);
	};
};



void
empty_world(
    int factor, bool force) // main empty world creation routine, if passed
                            // factor -1 will enlarge old world by 1
{
	if (!force && noteditmode())







<
>












<
>












<
>



















<
>












<
>














<
<
>
>







350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430


431
432
433
434
435
436
437
438
439
	};
	addmsg(1, 10, SV_EDITENT, ents.length(), type, e.x, e.y, e.z, e.attr1,
	    e.attr2, e.attr3, e.attr4);
	ents.add(*((entity *)&e)); // unsafe!
	if (type == LIGHT)
		calclight();
	return &ents.last();

}

void
clearents(OFString *name)
{
	int type = findtype(name);
	if (noteditmode() || multiplayer())
		return;
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type == type)
			e.type = NOTUSED;

	}
	if (type == LIGHT)
		calclight();
}
COMMAND(clearents, ARG_1STR)

void
scalecomp(uchar &c, int intens)
{
	int n = c * intens / 100;
	if (n > 255)
		n = 255;
	c = n;

}

void
scalelights(int f, int intens)
{
	loopv(ents)
	{
		entity &e = ents[i];
		if (e.type != LIGHT)
			continue;
		e.attr1 = e.attr1 * f / 100;
		if (e.attr1 < 2)
			e.attr1 = 2;
		if (e.attr1 > 32)
			e.attr1 = 32;
		if (intens) {
			scalecomp(e.attr2, intens);
			scalecomp(e.attr3, intens);
			scalecomp(e.attr4, intens);
		};

	}
	calclight();
}
COMMAND(scalelights, ARG_2INT)

int
findentity(int type, int index)
{
	for (int i = index; i < ents.length(); i++)
		if (ents[i].type == type)
			return i;
	loopj(index) if (ents[j].type == type) return j;
	return -1;

}

sqr *wmip[LARGEST_FACTOR * 2];

void
setupworld(int factor)
{
	ssize = 1 << (sfactor = factor);
	cubicsize = ssize * ssize;
	mipsize = cubicsize * 134 / 100;
	sqr *w = world = (sqr *)alloc(mipsize * sizeof(sqr));
	loopi(LARGEST_FACTOR * 2)
	{
		wmip[i] = w;
		w += cubicsize >> (i * 2);


	}
}

void
empty_world(
    int factor, bool force) // main empty world creation routine, if passed
                            // factor -1 will enlarge old world by 1
{
	if (!force && noteditmode())