2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
#include "QF/quakeio.h"
|
|
|
|
#include "QF/script.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "Map.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "TexturePalette.h"
|
|
|
|
#include "SetBrush.h"
|
|
|
|
#include "XYView.h"
|
|
|
|
#include "CameraView.h"
|
|
|
|
#include "QuakeEd.h"
|
|
|
|
#include "Things.h"
|
|
|
|
#include "InspectorControl.h"
|
|
|
|
#include "Project.h"
|
|
|
|
|
2010-09-12 07:25:25 +00:00
|
|
|
#define THING Map
|
|
|
|
#include "THING+NSArray.m"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
id map_i;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
@implementation Map
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
FILE METHODS
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
2010-09-12 07:25:25 +00:00
|
|
|
- init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
array = [[NSMutableArray alloc] init];
|
2003-03-18 19:48:24 +00:00
|
|
|
map_i = self;
|
|
|
|
minz = 0;
|
|
|
|
maxz = 80;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
oldselection =[[NSMutableArray alloc] init];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-saveSelected
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, c;
|
|
|
|
id o, w;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[oldselection removeAllObjects];
|
2010-09-11 10:03:41 +00:00
|
|
|
w =[self objectAtIndex:0];
|
|
|
|
c =[w count];
|
2003-03-18 19:48:24 +00:00
|
|
|
sb_newowner = oldselection;
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
o =[w objectAtIndex:0];
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([o selected])
|
|
|
|
[o moveToEntity];
|
2010-09-11 10:03:41 +00:00
|
|
|
else {
|
|
|
|
[w removeObjectAtIndex:0];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
o =[self objectAtIndex:0];
|
|
|
|
[self removeObjectAtIndex:0];
|
2010-09-09 11:46:38 +00:00
|
|
|
[o removeAllObjects];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-addSelected
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, c;
|
|
|
|
id n, w;
|
|
|
|
|
|
|
|
c =[oldselection count];
|
|
|
|
w =[self objectAtIndex:0]; // world object
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
sb_newowner = w;
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
n =[oldselection objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
[n moveToEntity];
|
|
|
|
i--;
|
|
|
|
c--;
|
|
|
|
}
|
|
|
|
[oldselection removeAllObjects];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-newMap
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id ent;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self saveSelected];
|
2010-09-11 10:03:41 +00:00
|
|
|
ent =[[Entity alloc] initClass:"worldspawn"];
|
|
|
|
[self addObject:ent];
|
2003-03-18 19:48:24 +00:00
|
|
|
currentEntity = NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
[self setCurrentEntity:ent];
|
2003-03-18 19:48:24 +00:00
|
|
|
[self addSelected];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-currentEntity
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
return currentEntity;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-setCurrentEntity:ent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id old;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
old = currentEntity;
|
|
|
|
currentEntity = ent;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (old != ent) {
|
2003-03-18 19:48:24 +00:00
|
|
|
[things_i newCurrentEntity]; // update inspector
|
2010-09-28 19:43:35 +00:00
|
|
|
[inspcontrol_i setCurrentInspector: i_things];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(float) currentMinZ
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
float grid;
|
|
|
|
|
|
|
|
grid =[xyview_i gridsize];
|
|
|
|
minz = grid * rint (minz / grid);
|
2003-03-18 19:48:24 +00:00
|
|
|
return minz;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-setCurrentMinZ:(float) m
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
if (m > -2048)
|
|
|
|
minz = m;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(float) currentMaxZ
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
float grid;
|
|
|
|
|
|
|
|
[self currentMinZ]; // grid align
|
|
|
|
|
|
|
|
grid =[xyview_i gridsize];
|
|
|
|
maxz = grid * rint (maxz / grid);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
if (maxz <= minz)
|
|
|
|
maxz = minz + grid;
|
|
|
|
return maxz;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-setCurrentMaxZ:(float) m
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
if (m < 2048)
|
|
|
|
maxz = m;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(void) removeObject:o
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
[super removeObject:o];
|
|
|
|
|
|
|
|
if (o == currentEntity) { // select the world
|
|
|
|
[self setCurrentEntity: [self objectAtIndex:0]];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-11 11:30:01 +00:00
|
|
|
#define FN_DEVLOG "/qcache/devlog"
|
2010-09-11 10:03:41 +00:00
|
|
|
-writeStats
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
extern int c_updateall;
|
|
|
|
struct timeval tp;
|
|
|
|
struct timezone tzp;
|
|
|
|
|
|
|
|
gettimeofday(&tp, &tzp);
|
|
|
|
|
|
|
|
f = fopen (FN_DEVLOG, "a");
|
|
|
|
fprintf (f,"%i %i\n", (int)tp.tv_sec, c_updateall);
|
|
|
|
c_updateall = 0;
|
|
|
|
fclose (f);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(int) numSelected
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, c;
|
|
|
|
int num;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
num = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
c =[currentEntity count];
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
if ([[currentEntity objectAtIndex:i] selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
num++;
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectedBrush
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, c;
|
|
|
|
int num;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
num = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
c =[currentEntity count];
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
if ([[currentEntity objectAtIndex:i] selected])
|
|
|
|
return[currentEntity objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
readMapFile
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-28 09:41:38 +00:00
|
|
|
-readMapFile:(const char *) fname
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-27 15:29:16 +00:00
|
|
|
char *dat;
|
|
|
|
const char *wad, *cl;
|
2010-09-11 10:03:41 +00:00
|
|
|
id new;
|
|
|
|
id ent;
|
|
|
|
int i, c;
|
|
|
|
vec3_t org;
|
|
|
|
float angle;
|
2010-09-09 11:46:38 +00:00
|
|
|
QFile *file;
|
|
|
|
script_t *script;
|
|
|
|
size_t size;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self saveSelected];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
Sys_Printf ("loading %s\n", fname);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
file = Qopen (fname, "rt");
|
2010-09-19 08:04:03 +00:00
|
|
|
if (!file)
|
|
|
|
return self;
|
2010-09-09 11:46:38 +00:00
|
|
|
size = Qfilesize (file);
|
|
|
|
dat = malloc (size + 1);
|
|
|
|
size = Qread (file, dat, size);
|
|
|
|
Qclose (file);
|
|
|
|
dat[size] = 0;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
script = Script_New ();
|
|
|
|
Script_Start (script, fname, dat);
|
|
|
|
|
|
|
|
do {
|
2010-09-11 10:03:41 +00:00
|
|
|
new =[[Entity alloc] initFromScript:script];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!new)
|
|
|
|
break;
|
2010-09-11 10:03:41 +00:00
|
|
|
[self addObject:new];
|
2003-03-18 19:48:24 +00:00
|
|
|
} while (1);
|
|
|
|
|
|
|
|
free (dat);
|
|
|
|
|
|
|
|
[self addSelected];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// load the apropriate texture wad
|
2010-09-27 15:29:16 +00:00
|
|
|
wad =[currentEntity valueForQKey:"wad"];
|
|
|
|
if (wad && wad[0]) {
|
|
|
|
if (wad[0] == '/') // remove old style fullpaths
|
2010-09-11 10:03:41 +00:00
|
|
|
[currentEntity removeKeyPair:"wad"];
|
|
|
|
else {
|
2010-09-27 15:29:16 +00:00
|
|
|
if (strcmp ([texturepalette_i currentWad], wad))
|
|
|
|
[project_i setTextureWad:wad];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-28 13:17:31 +00:00
|
|
|
|
|
|
|
[self setCurrentEntity: [self objectAtIndex:0]];
|
2003-03-18 19:48:24 +00:00
|
|
|
// center the camera and XY view on the playerstart
|
2010-09-11 10:03:41 +00:00
|
|
|
c =[self count];
|
|
|
|
for (i = 1; i < c; i++) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
cl =[ent valueForQKey:"classname"];
|
|
|
|
if (cl && !strcasecmp (cl, "info_player_start")) {
|
|
|
|
angle = atof ([ent valueForQKey:"angle"]);
|
|
|
|
angle = angle / 180 * M_PI;
|
|
|
|
[ent getVector: org forKey:"origin"];
|
2003-03-18 19:48:24 +00:00
|
|
|
[cameraview_i setOrigin: org angle:angle];
|
2010-09-11 10:03:41 +00:00
|
|
|
[xyview_i centerOn:org];
|
2003-03-18 19:48:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
writeMapFile
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-28 09:41:38 +00:00
|
|
|
-writeMapFile:(const char *)
|
2010-09-11 10:03:41 +00:00
|
|
|
fname useRegion:(BOOL) reg
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
FILE *f;
|
2010-09-27 18:01:07 +00:00
|
|
|
unsigned int i;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("writeMapFile: %s\n", fname);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
f = fopen (fname, "w");
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!f)
|
2010-09-09 11:46:38 +00:00
|
|
|
Sys_Error ("couldn't write %s", fname);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
for (i = 0; i <[self count]; i++)
|
|
|
|
[[self objectAtIndex: i] writeToFILE: f region:reg];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
fclose (f);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
DRAWING
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-28 19:43:35 +00:00
|
|
|
-(void)ZDrawSelf
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, count;
|
|
|
|
|
|
|
|
count =[self count];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
[[self objectAtIndex:i] ZDrawSelf];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 19:43:35 +00:00
|
|
|
-(void)RenderSelf:(void (*)(face_t *)) callback
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, count;
|
|
|
|
|
|
|
|
count =[self count];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
[[self objectAtIndex: i] RenderSelf:callback];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
entityConnect
|
|
|
|
|
|
|
|
A command-shift-click on an entity while an entity is selected will
|
|
|
|
make a target connection from the original entity.
|
|
|
|
===================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-entityConnect: (vec3_t) p1:(vec3_t) p2
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id oldent, ent;
|
|
|
|
|
|
|
|
oldent =[self currentEntity];
|
|
|
|
if (oldent ==[self objectAtIndex:0]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("Must have a non-world entity selected to connect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[self selectRay: p1: p2:YES];
|
|
|
|
ent =[self currentEntity];
|
|
|
|
if (ent == oldent) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("Must click on a different entity to connect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (ent ==[self objectAtIndex:0]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("Must click on a non-world entity to connect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[oldent setKey: "target" toValue:[ent targetname]];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
selectRay
|
|
|
|
|
|
|
|
If ef is true, any entity brush along the ray will be selected in preference
|
|
|
|
to intervening world brushes
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectRay: (vec3_t) p1: (vec3_t) p2:(BOOL) ef
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, bestent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face, bestface;
|
|
|
|
float time, besttime;
|
|
|
|
texturedef_t *td;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
bestent = nil;
|
|
|
|
bestface = -1;
|
|
|
|
bestbrush = nil;
|
|
|
|
besttime = 99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = c - 1; i >= 0; i--) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = 0; j < c2; j++) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
|
|
|
[brush hitByRay: p1: p2: &time:&face];
|
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
bestent = ent;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
bestface = face;
|
|
|
|
}
|
|
|
|
if (i == 1 && ef && bestbrush)
|
2010-09-11 10:03:41 +00:00
|
|
|
break; // found an entity, so don't check the
|
|
|
|
// world
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (besttime == 99999) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("trace missed\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
if ([bestbrush regioned]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("WANRING: clicked on regioned brush\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (bestent != currentEntity) {
|
|
|
|
[self makeSelectedPerform:@selector (deselect)];
|
|
|
|
[self setCurrentEntity:bestent];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i disableFlushWindow];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![bestbrush selected]) {
|
|
|
|
if ([map_i numSelected] == 0) { // don't grab texture if others are
|
|
|
|
// selected
|
|
|
|
td =[bestbrush texturedefForFace:bestface];
|
|
|
|
[texturepalette_i setTextureDef:td];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[bestbrush setSelected:YES];
|
2010-09-28 13:17:31 +00:00
|
|
|
Sys_Printf ("selected entity %i brush %i face %i\n",
|
|
|
|
(int)[self indexOfObject: bestent],
|
|
|
|
(int)[bestent indexOfObject:bestbrush], bestface);
|
2010-09-11 10:03:41 +00:00
|
|
|
} else {
|
|
|
|
[bestbrush setSelected:NO];
|
2010-09-28 13:17:31 +00:00
|
|
|
Sys_Printf ("deselected entity %i brush %i face %i\n",
|
|
|
|
(int)[self indexOfObject: bestent],
|
|
|
|
(int)[bestent indexOfObject:bestbrush], bestface);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[quakeed_i enableFlushWindow];
|
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
grabRay
|
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
checks only the selected brushes
|
2003-03-18 19:48:24 +00:00
|
|
|
Returns the brush hit, or nil if missed.
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-grabRay: (vec3_t) p1:(vec3_t) p2
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face;
|
|
|
|
float time, besttime;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
bestbrush = nil;
|
|
|
|
besttime = 99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = 0; j < c2; j++) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (![brush selected])
|
|
|
|
continue;
|
2010-09-11 10:03:41 +00:00
|
|
|
[brush hitByRay: p1: p2: &time:&face];
|
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (besttime == 99999)
|
|
|
|
return nil;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return bestbrush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
getTextureRay
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-getTextureRay: (vec3_t) p1:(vec3_t) p2
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, bestent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face, bestface;
|
|
|
|
float time, besttime;
|
|
|
|
texturedef_t *td;
|
|
|
|
vec3_t mins, maxs;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
bestbrush = nil;
|
|
|
|
bestent = nil;
|
|
|
|
besttime = 99999;
|
|
|
|
bestface = -1;
|
2010-09-11 10:03:41 +00:00
|
|
|
c =[self count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = 0; j < c2; j++) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
|
|
|
[brush hitByRay: p1: p2: &time:&face];
|
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
bestent = ent;
|
|
|
|
bestface = face;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (besttime == 99999)
|
|
|
|
return nil;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![bestent modifiable]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("can't modify spawned entities\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
td =[bestbrush texturedefForFace:bestface];
|
|
|
|
[texturepalette_i setTextureDef:td];
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("grabbed texturedef and sizes\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[bestbrush getMins: mins maxs:maxs];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
minz = mins[2];
|
|
|
|
maxz = maxs[2];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return bestbrush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
setTextureRay
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-setTextureRay: (vec3_t) p1: (vec3_t) p2:(BOOL) allsides;
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, bestent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face, bestface;
|
|
|
|
float time, besttime;
|
|
|
|
texturedef_t td;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
bestent = nil;
|
|
|
|
bestface = -1;
|
|
|
|
bestbrush = nil;
|
|
|
|
besttime = 99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = 0; j < c2; j++) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
|
|
|
[brush hitByRay: p1: p2: &time:&face];
|
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
bestent = ent;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
bestface = face;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (besttime == 99999) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("trace missed\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![bestent modifiable]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("can't modify spawned entities\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([bestbrush regioned]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("WANRING: clicked on regioned brush\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[texturepalette_i getTextureDef:&td];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i disableFlushWindow];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (allsides) {
|
|
|
|
[bestbrush setTexturedef:&td];
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("textured entity %i brush %i\n", (int)[self indexOfObject: bestent], (int)[bestent indexOfObject:bestbrush]);
|
2010-09-11 10:03:41 +00:00
|
|
|
} else {
|
|
|
|
[bestbrush setTexturedef: &td forFace:bestface];
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("deselected entity %i brush %i face %i\n", (int)[self indexOfObject: bestent], (int)[bestent indexOfObject:bestbrush], bestface);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
[quakeed_i enableFlushWindow];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
OPERATIONS ON SELECTIONS
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-makeSelectedPerform:(SEL) sel
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
|
|
|
int total;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
total = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
c =[self count];
|
|
|
|
for (i = c - 1; i >= 0; i--) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
|
|
|
if (![brush selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
if ([brush regioned])
|
|
|
|
continue;
|
|
|
|
total++;
|
2010-09-09 11:46:38 +00:00
|
|
|
[brush performSelector:sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
// if (!total)
|
2010-09-12 02:13:35 +00:00
|
|
|
// Sys_Printf ("nothing selected\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-makeUnselectedPerform:(SEL) sel
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = c - 1; i >= 0; i--) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
|
|
|
if ([brush selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
if ([brush regioned])
|
|
|
|
continue;
|
2010-09-09 11:46:38 +00:00
|
|
|
[brush performSelector:sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-makeAllPerform:(SEL) sel
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = c - 1; i >= 0; i--) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([brush regioned])
|
|
|
|
continue;
|
2010-09-09 11:46:38 +00:00
|
|
|
[brush performSelector:sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-makeGlobalPerform:(SEL) sel // in and out of region
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
|
|
|
|
|
|
|
c =[self count];
|
|
|
|
for (i = c - 1; i >= 0; i--) {
|
|
|
|
ent =[self objectAtIndex:i];
|
|
|
|
c2 =[ent count];
|
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
|
|
|
brush =[ent objectAtIndex:j];
|
2010-09-09 11:46:38 +00:00
|
|
|
[brush performSelector:sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
sel_identity (void)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
sel_x[0] = 1;
|
|
|
|
sel_x[1] = 0;
|
|
|
|
sel_x[2] = 0;
|
|
|
|
sel_y[0] = 0;
|
|
|
|
sel_y[1] = 1;
|
|
|
|
sel_y[2] = 0;
|
|
|
|
sel_z[0] = 0;
|
|
|
|
sel_z[1] = 0;
|
|
|
|
sel_z[2] = 1;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-transformSelection
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![currentEntity modifiable]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("can't modify spawned entities\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
// find an origin to apply the transformation to
|
|
|
|
sb_mins[0] = sb_mins[1] = sb_mins[2] = 99999;
|
|
|
|
sb_maxs[0] = sb_maxs[1] = sb_maxs[2] = -99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
[self makeSelectedPerform:@selector (addToBBox)];
|
|
|
|
sel_org[0] =[xyview_i snapToGrid:(sb_mins[0] + sb_maxs[0]) / 2];
|
|
|
|
sel_org[1] =[xyview_i snapToGrid:(sb_mins[1] + sb_maxs[1]) / 2];
|
|
|
|
sel_org[2] =[xyview_i snapToGrid:(sb_mins[2] + sb_maxs[2]) / 2];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// do it!
|
2010-09-11 10:03:41 +00:00
|
|
|
[self makeSelectedPerform:@selector (transform)];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
swapvectors (vec3_t a, vec3_t b)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
vec3_t temp;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (a, temp);
|
|
|
|
VectorCopy (b, a);
|
|
|
|
VectorSubtract (vec3_origin, temp, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
UI operations
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-rotate_x:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
2010-09-11 10:03:41 +00:00
|
|
|
swapvectors (sel_y, sel_z);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self transformSelection];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-rotate_y:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
2010-09-11 10:03:41 +00:00
|
|
|
swapvectors (sel_x, sel_z);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self transformSelection];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-rotate_z:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
2010-09-11 10:03:41 +00:00
|
|
|
swapvectors (sel_x, sel_y);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self transformSelection];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-flip_x:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
|
|
|
sel_x[0] = -1;
|
|
|
|
[self transformSelection];
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeSelectedPerform:@selector (flipNormals)];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-flip_y:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
|
|
|
sel_y[1] = -1;
|
|
|
|
[self transformSelection];
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeSelectedPerform:@selector (flipNormals)];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-flip_z:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
|
|
|
sel_z[2] = -1;
|
|
|
|
[self transformSelection];
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeSelectedPerform:@selector (flipNormals)];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-cloneSelection:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, originalElements;
|
|
|
|
id o, b;
|
|
|
|
id new;
|
|
|
|
|
|
|
|
sb_translate[0] = sb_translate[1] =[xyview_i gridsize];
|
2003-03-18 19:48:24 +00:00
|
|
|
sb_translate[2] = 0;
|
|
|
|
|
|
|
|
// copy individual brushes in the world entity
|
2010-09-11 10:03:41 +00:00
|
|
|
o =[self objectAtIndex:0];
|
|
|
|
c =[o count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
b =[o objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (![b selected])
|
|
|
|
continue;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
// copy the brush, then translate the original
|
|
|
|
new =[b copy];
|
|
|
|
[new setSelected:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[new translate];
|
2010-09-11 10:03:41 +00:00
|
|
|
[b setSelected:NO];
|
|
|
|
[o addObject:new];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// copy entire entities otherwise
|
2010-09-11 10:03:41 +00:00
|
|
|
originalElements =[self count]; // don't copy the new ones
|
|
|
|
for (i = 1; i < originalElements; i++) {
|
|
|
|
o =[self objectAtIndex:i];
|
|
|
|
if (![[o objectAtIndex:0] selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
new =[o copy];
|
|
|
|
[self addObject:new];
|
|
|
|
|
|
|
|
c =[o count];
|
|
|
|
for (j = 0; j < c; j++)
|
|
|
|
[[o objectAtIndex: j] setSelected:NO];
|
|
|
|
|
|
|
|
c =[new count];
|
|
|
|
for (j = 0; j < c; j++) {
|
|
|
|
b =[new objectAtIndex:j];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b translate];
|
2010-09-11 10:03:41 +00:00
|
|
|
[b setSelected:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectCompleteEntity:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id o;
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
o =[self selectedBrush];
|
|
|
|
if (!o) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("nothing selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
o =[o parent];
|
|
|
|
c =[o count];
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
[[o objectAtIndex: i] setSelected:YES];
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("%i brushes selected\n", c);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-makeEntity:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
if (currentEntity !=[self objectAtIndex:0]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("ERROR: can't makeEntity inside an entity\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
NSBeep ();
|
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([self numSelected] == 0) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("ERROR: must have a seed brush to make an entity\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
NSBeep ();
|
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
sb_newowner =[[Entity alloc] initClass:[things_i spawnName]];
|
|
|
|
|
|
|
|
if ([sb_newowner modifiable])
|
|
|
|
[self makeSelectedPerform:@selector (moveToEntity)];
|
|
|
|
else { // throw out seed brush and select
|
|
|
|
// entity fixed brush
|
|
|
|
[self makeSelectedPerform:@selector (remove)];
|
|
|
|
[[sb_newowner objectAtIndex: 0] setSelected:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[self addObject:sb_newowner];
|
|
|
|
[self setCurrentEntity:sb_newowner];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selbox:(SEL) selector
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id b;
|
|
|
|
|
|
|
|
if ([self numSelected] != 1) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("must have a single brush selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
b =[self selectedBrush];
|
|
|
|
[b getMins: select_min maxs:select_max];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b remove];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[self makeUnselectedPerform:selector];
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("identified contents\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectCompletelyInside:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
return[self selbox:@selector (selectComplete)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectPartiallyInside:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
return[self selbox:@selector (selectPartial)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-tallBrush:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id b;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
texturedef_t td;
|
|
|
|
|
|
|
|
if ([self numSelected] != 1) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("must have a single brush selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
b =[self selectedBrush];
|
2003-03-18 19:48:24 +00:00
|
|
|
td = *[b texturedef];
|
2010-09-11 10:03:41 +00:00
|
|
|
[b getMins: mins maxs:maxs];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b remove];
|
|
|
|
|
|
|
|
mins[2] = -2048;
|
|
|
|
maxs[2] = 2048;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
b =[[SetBrush alloc] initOwner: [map_i objectAtIndex: 0] mins: mins maxs: maxs texture:&td];
|
|
|
|
[[map_i objectAtIndex: 0] addObject:b];
|
|
|
|
[b setSelected:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-shortBrush:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id b;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
texturedef_t td;
|
|
|
|
|
|
|
|
if ([self numSelected] != 1) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("must have a single brush selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
b =[self selectedBrush];
|
2003-03-18 19:48:24 +00:00
|
|
|
td = *[b texturedef];
|
2010-09-11 10:03:41 +00:00
|
|
|
[b getMins: mins maxs:maxs];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b remove];
|
|
|
|
|
|
|
|
mins[2] = 0;
|
|
|
|
maxs[2] = 16;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
b =[[SetBrush alloc] initOwner: [map_i objectAtIndex: 0] mins: mins maxs: maxs texture:&td];
|
|
|
|
[[map_i objectAtIndex: 0] addObject:b];
|
|
|
|
[b setSelected:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
subtractSelection
|
|
|
|
==================
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-subtractSelection:semder
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id o, o2;
|
|
|
|
id sellist, sourcelist;
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("performing brush subtraction...\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
sourcelist =[[NSMutableArray alloc] init];
|
|
|
|
sellist =[[NSMutableArray alloc] init];
|
|
|
|
carve_in =[[NSMutableArray alloc] init];
|
|
|
|
carve_out =[[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
c =[currentEntity count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
o =[currentEntity objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([o selected])
|
2010-09-11 10:03:41 +00:00
|
|
|
[sellist addObject:o];
|
2003-03-18 19:48:24 +00:00
|
|
|
else
|
2010-09-11 10:03:41 +00:00
|
|
|
[sourcelist addObject:o];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
c =[sellist count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
o =[sellist objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
[o setCarveVars];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
c2 =[sourcelist count];
|
|
|
|
for (j = 0; j < c2; j++) {
|
|
|
|
o2 =[sourcelist objectAtIndex:j];
|
2003-03-18 19:48:24 +00:00
|
|
|
[o2 carve];
|
2010-09-09 11:46:38 +00:00
|
|
|
[carve_in removeAllObjects];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[sourcelist release]; // the individual have been moved/freed
|
2003-03-18 19:48:24 +00:00
|
|
|
sourcelist = carve_out;
|
2010-09-11 10:03:41 +00:00
|
|
|
carve_out =[[NSMutableArray alloc] init];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add the selection back to the remnants
|
|
|
|
[currentEntity removeAllObjects];
|
2010-09-11 10:03:41 +00:00
|
|
|
[currentEntity addObjectsFromArray:sourcelist];
|
|
|
|
[currentEntity addObjectsFromArray:sellist];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[sourcelist release];
|
|
|
|
[sellist release];
|
|
|
|
[carve_in release];
|
|
|
|
[carve_out release];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (![currentEntity count]) {
|
2003-03-18 19:48:24 +00:00
|
|
|
o = currentEntity;
|
2010-09-11 10:03:41 +00:00
|
|
|
[self removeObject:o];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("subtracted selection\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|