Cube  Diff

Differences From Artifact [b3c4009ae5]:

To Artifact [e48df32f18]:


1
2
3
4

5
6
7
8
9
10
11
// world.cpp: core map management stuff

#include "cube.h"


#import "DynamicEntity.h"
#import "Entity.h"
#import "Monster.h"

extern OFString *entnames[]; // lookup from map entities above to strings

struct sqr *world = NULL;




>







1
2
3
4
5
6
7
8
9
10
11
12
// world.cpp: core map management stuff

#include "cube.h"

#import "Command.h"
#import "DynamicEntity.h"
#import "Entity.h"
#import "Monster.h"

extern OFString *entnames[]; // lookup from map entities above to strings

struct sqr *world = NULL;
87
88
89
90
91
92
93

94


95
96
97
98
99
100
101

	if (identexists(aliasname))
		execute(aliasname, true);

	if (type == 2)
		[Monster endSinglePlayerWithAllKilled:false];
}

COMMAND(trigger, ARG_2INT)



// main geometric mipmapping routine, recursively rebuild mipmaps within block
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
// defer to 0 if mipped cube is a perfect mip, i.e. can be rendered at this mip
// level indistinguishable from its constituent cubes (saves considerable
// rendering time if this is possible).








>
|
>
>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

	if (identexists(aliasname))
		execute(aliasname, true);

	if (type == 2)
		[Monster endSinglePlayerWithAllKilled:false];
}

COMMAND(trigger, ARG_2INT, ^(int tag, int type, bool savegame) {
	trigger(tag, type, savegame);
})

// main geometric mipmapping routine, recursively rebuild mipmaps within block
// b. tries to produce cube out of 4 lower level mips as well as possible, sets
// defer to 0 if mipped cube is a perfect mip, i.e. can be rendered at this mip
// level indistinguishable from its constituent cubes (saves considerable
// rendering time if this is possible).

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
			bdist = dist;
		}
	}];

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

void
entproperty(int prop, int amount)
{
	int e = closestent();
	if (e < 0)
		return;
	switch (prop) {
	case 0:
		ents[e].attr1 += amount;
		break;
	case 1:
		ents[e].attr2 += amount;
		break;
	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");
		return;
	}
	int t = ents[e].type;
	conoutf(@"%@ entity deleted", entnames[t]);
	ents[e].type = NOTUSED;
	addmsg(1, 10, SV_EDITENT, e, NOTUSED, 0, 0, 0, 0, 0, 0, 0);
	if (t == LIGHT)
		calclight();
}

int
findtype(OFString *what)
{
	for (int i = 0; i < MAXENTTYPES; i++)
		if ([what isEqual:entnames[i]])
			return i;







<
|
<

















|

<
|
<











|







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
			bdist = dist;
		}
	}];

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


COMMAND(entproperty, ARG_2INT, ^(int prop, int amount) {

	int e = closestent();
	if (e < 0)
		return;
	switch (prop) {
	case 0:
		ents[e].attr1 += amount;
		break;
	case 1:
		ents[e].attr2 += amount;
		break;
	case 2:
		ents[e].attr3 += amount;
		break;
	case 3:
		ents[e].attr4 += amount;
		break;
	}
})


COMMAND(delent, ARG_NONE, ^{

	int e = closestent();
	if (e < 0) {
		conoutf(@"no more entities");
		return;
	}
	int t = ents[e].type;
	conoutf(@"%@ entity deleted", entnames[t]);
	ents[e].type = NOTUSED;
	addmsg(1, 10, SV_EDITENT, e, NOTUSED, 0, 0, 0, 0, 0, 0, 0);
	if (t == LIGHT)
		calclight();
})

int
findtype(OFString *what)
{
	for (int i = 0; i < MAXENTTYPES; i++)
		if ([what isEqual:entnames[i]])
			return i;
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

	if (type == LIGHT)
		calclight();

	return e;
}

void
clearents(OFString *name)
{
	int type = findtype(name);

	if (noteditmode() || multiplayer())
		return;

	for (Entity *e in ents)
		if (e.type == type)
			e.type = NOTUSED;

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

static unsigned char
scalecomp(unsigned char c, int intens)
{
	int n = c * intens / 100;
	if (n > 255)
		n = 255;
	return n;
}

void
scalelights(int f, int intens)
{
	for (Entity *e in ents) {
		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) {
			e.attr2 = scalecomp(e.attr2, intens);
			e.attr3 = scalecomp(e.attr3, intens);
			e.attr4 = scalecomp(e.attr4, intens);
		}
	}

	calclight();
}
COMMAND(scalelights, ARG_2INT)

int
findentity(int type, int index)
{
	for (int i = index; i < ents.count; i++)
		if (ents[i].type == type)
			return i;







<
|
<











|
<










<
|
<


















|
<







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
441
442

443
444
445
446
447
448
449

	if (type == LIGHT)
		calclight();

	return e;
}


COMMAND(clearents, ARG_1STR, ^(OFString *name) {

	int type = findtype(name);

	if (noteditmode() || multiplayer())
		return;

	for (Entity *e in ents)
		if (e.type == type)
			e.type = NOTUSED;

	if (type == LIGHT)
		calclight();
})


static unsigned char
scalecomp(unsigned char c, int intens)
{
	int n = c * intens / 100;
	if (n > 255)
		n = 255;
	return n;
}


COMMAND(scalelights, ARG_2INT, ^(int f, int intens) {

	for (Entity *e in ents) {
		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) {
			e.attr2 = scalecomp(e.attr2, intens);
			e.attr3 = scalecomp(e.attr3, intens);
			e.attr4 = scalecomp(e.attr4, intens);
		}
	}

	calclight();
})


int
findentity(int type, int index)
{
	for (int i = index; i < ents.count; i++)
		if (ents[i].type == type)
			return i;
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

	if (oldworld) {
		OFFreeMemory(oldworld);
		toggleedit();
		execute(@"fullbright 1", true);
	}
}

void
mapenlarge()
{
	empty_world(-1, false);
}

void
newmap(int i)
{
	empty_world(i, false);
}

COMMAND(mapenlarge, ARG_NONE)
COMMAND(newmap, ARG_1INT)
COMMANDN(recalc, calclight, ARG_NONE)
COMMAND(delent, ARG_NONE)
COMMAND(entproperty, ARG_2INT)








<
|
<

|

<
|
<

|

|
<
|
<
<
>
541
542
543
544
545
546
547

548

549
550
551

552

553
554
555
556

557


558
	if (oldworld) {
		OFFreeMemory(oldworld);
		toggleedit();
		execute(@"fullbright 1", true);
	}
}


COMMAND(mapenlarge, ARG_NONE, ^{

	empty_world(-1, false);
})


COMMAND(newmap, ARG_1INT, ^(int i) {

	empty_world(i, false);
})

COMMAND(recalc, ARG_NONE, ^{

	calclight();


})