2 ===================================================================
3 --- radiant/map.cpp (revision 304)
4 +++ radiant/map.cpp (working copy)
9 +void Map_DoTargetFix(entity_t *e, const char *target, int num_ents, CPtrArray *ents, GPtrArray *new_ents)
13 + char newtarget[128];
16 + qboolean targetnameFound = FALSE;
17 + qboolean targetFound = FALSE;
18 + qboolean colliding = FALSE;
25 + target = g_strdup(target);
27 + // check the current map entities for an actual collision
28 + for (e_target = entities.next; e_target != &entities; e_target = e_target->next)
31 + !strcmp(target, ValueForKey(e_target, "target"))
33 + !strcmp(target, ValueForKey(e_target, "killtarget"))
36 + // make sure the collision is not between two imported entities
37 + for(j=0; j<(int)new_ents->len; j++)
39 + if(e_target == g_ptr_array_index(new_ents, j))
42 + goto no_collision_yet_1;
50 + !strcmp(target, ValueForKey(e_target, "targetname"))
53 + // make sure the collision is not between two imported entities
54 + for(j=0; j<(int)new_ents->len; j++)
56 + if(e_target == g_ptr_array_index(new_ents, j))
58 + targetnameFound = true;
59 + goto no_collision_yet_2;
68 + // find the matching targeted entity(s)
69 + if(colliding && targetFound && targetnameFound)
71 + // We got a collision
72 + // first look for a non-conflicting target name
73 + id = GetUniqueTargetId(1);
74 + sprintf(newtarget, "t%i", id);
76 + for(j=num_ents-1; j>0; j--)
78 + e_target = (entity_t*)ents->GetAt(j);
79 + if(e_target != NULL)
81 + const char *targetname = ValueForKey(e_target, "targetname");
82 + if( (targetname != NULL) && (strcmp(target, targetname) == 0) )
84 + SetKeyValue(e_target, "targetname", newtarget);
86 + targetname = ValueForKey(e_target, "target");
87 + if( (targetname != NULL) && (strcmp(target, targetname) == 0) )
89 + SetKeyValue(e_target, "target", newtarget);
91 + targetname = ValueForKey(e_target, "killtarget");
92 + if( (targetname != NULL) && (strcmp(target, targetname) == 0) )
94 + SetKeyValue(e_target, "killtarget", newtarget);
103 /*!\todo Possibly make the import Undo-friendly by calling Undo_End for new brushes and ents */
104 void Map_ImportEntities(CPtrArray *ents, bool bAddSelected = false)
106 @@ -466,60 +560,27 @@
110 - // fix target/targetname collisions
111 - if ((g_PrefsDlg.m_bDoTargetFix) && (strcmp(ValueForKey(e, "target"), "") != 0))
113 - GPtrArray *t_ents = g_ptr_array_new();
114 - entity_t *e_target;
115 - const char *target = ValueForKey(e, "target");
116 - qboolean bCollision=FALSE;
117 + // keep a list of ents added to avoid testing collisions against them
118 + g_ptr_array_add(new_ents, (gpointer)e);
120 - // check the current map entities for an actual collision
121 - for (e_target = entities.next; e_target != &entities; e_target = e_target->next)
123 - if(!strcmp(target, ValueForKey(e_target, "target")))
126 - // make sure the collision is not between two imported entities
127 - for(j=0; j<(int)new_ents->len; j++)
129 - if(e_target == g_ptr_array_index(new_ents, j))
130 - bCollision = FALSE;
135 - // find the matching targeted entity(s)
138 - for(j=num_ents-1; j>0; j--)
140 - e_target = (entity_t*)ents->GetAt(j);
141 - if(e_target != NULL && e_target != e)
143 - const char *targetname = ValueForKey(e_target, "targetname");
144 - if( (targetname != NULL) && (strcmp(target, targetname) == 0) )
145 - g_ptr_array_add(t_ents, (gpointer)e_target);
148 - if(t_ents->len > 0)
150 - // link the first to get a unique target/targetname
151 - Entity_Connect(e, (entity_t*)g_ptr_array_index(t_ents,0));
152 - // set the targetname of the rest of them manually
153 - for(j = 1; j < (int)t_ents->len; j++)
154 - SetKeyValue( (entity_t*)g_ptr_array_index(t_ents, j), "targetname", ValueForKey(e, "target") );
156 - g_ptr_array_free(t_ents, FALSE);
160 // add the entity to the end of the entity list
161 Entity_AddToList(e, &entities);
162 g_qeglobals.d_num_entities++;
164 - // keep a list of ents added to avoid testing collisions against them
165 - g_ptr_array_add(new_ents, (gpointer)e);
166 + // fix target/targetname collisions
167 + if (g_PrefsDlg.m_bDoTargetFix)
169 + const char *target;
171 + target = ValueForKey(e, "target");
172 + Map_DoTargetFix(e, target, num_ents, ents, new_ents);
174 + target = ValueForKey(e, "killtarget");
175 + Map_DoTargetFix(e, target, num_ents, ents, new_ents);
177 + target = ValueForKey(e, "targetname");
178 + Map_DoTargetFix(e, target, num_ents, ents, new_ents);
182 g_ptr_array_free(new_ents, FALSE);
183 Index: radiant/drag.cpp
184 ===================================================================
185 --- radiant/drag.cpp (revision 304)
186 +++ radiant/drag.cpp (working copy)
191 -void UpdateTarget(vec3_t origin, vec3_t dir)
198 - t = Test_Ray (origin, dir, 0);
203 - pe = t.brush->owner;
208 - // is this the first?
209 - if (peLink != NULL)
212 - // Get the target id from out current target
213 - // if there is no id, make one
215 - i = IntForKey(pe, "target");
218 - i = GetUniqueTargetId(1);
219 - sprintf(sz, "%d", i);
221 - SetKeyValue(pe, "target", sz);
224 - // set the target # into our src
226 - sprintf(sz, "%d", i);
227 - SetKeyValue(peLink, "targetname", sz);
229 - Sys_UpdateWindows(W_ENTITY);
233 - // promote the target to the src
242 Index: radiant/xywindow.cpp
243 ===================================================================
244 --- radiant/xywindow.cpp (revision 304)
245 +++ radiant/xywindow.cpp (working copy)
246 @@ -270,16 +270,17 @@
247 void DrawPathLines (void)
251 + vec3_t mid, mid1, v;
255 - vec3_t dir, s1, s2;
256 + vec3_t dir, s1, s2, dirortho;
260 const char *ent_target[MAX_MAP_ENTITIES];
261 entity_t *ent_entity[MAX_MAP_ENTITIES];
264 if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_PATHS)
267 ent_entity[num_entities] = te;
270 + ent_target[num_entities] = ValueForKey (te, "killtarget");
271 + if (ent_target[num_entities][0])
273 + ent_entity[num_entities] = te;
278 for (se = entities.next ; se != &entities ; se = se->next)
280 if (sb == &se->brushes)
283 + for (i=0 ; i<3 ; i++)
284 + mid[i] = (sb->mins[i] + sb->maxs[i])*0.5;
286 for (k=0 ; k<num_entities ; k++)
288 if (strcmp (ent_target[k], psz))
289 @@ -318,14 +328,20 @@
290 if (tb == &te->brushes)
293 - for (i=0 ; i<3 ; i++)
294 - mid[i] = (sb->mins[i] + sb->maxs[i])*0.5;
296 + if(!strcmp(ValueForKey(te, "target"), psz))
298 + if(!strcmp(ValueForKey(te, "killtarget"), psz))
301 for (i=0 ; i<3 ; i++)
302 mid1[i] = (tb->mins[i] + tb->maxs[i])*0.5;
304 VectorSubtract (mid1, mid, dir);
305 len = VectorNormalize (dir, dir);
306 + dirortho[0] = -dir[1];
307 + dirortho[1] = dir[0];
309 s1[0] = -dir[1]*8 + dir[0]*8;
310 s2[0] = dir[1]*8 + dir[0]*8;
311 s1[1] = dir[0]*8 + dir[1]*8;
313 qglColor3f (se->eclass->color[0], se->eclass->color[1], se->eclass->color[2]);
317 - qglVertex3fv(mid1);
318 + for(i = -lines + 1; i < lines; i += 2)
320 + VectorMA(mid, i, dirortho, v);
322 + VectorMA(mid1, i, dirortho, v);
326 arrows = (int)(len / 256) + 1;
328 Index: radiant/targetname.cpp
329 ===================================================================
330 --- radiant/targetname.cpp (revision 304)
331 +++ radiant/targetname.cpp (working copy)
334 connects two entities creating a unique target/targetname value
336 -void Entity_Connect(entity_t *e1, entity_t *e2)
337 +void Entity_Connect(entity_t *e1, entity_t *e2, bool kill)
339 const char *maptarget;
341 - int maxtarget=0; // highest t# value in the map
342 + int id=0; // highest t# value in the map
343 entity_t *e; // map entities
350 - for (e=entities.next ; e != &entities ; e=e->next)
352 - maptarget = ValueForKey (e, "target");
353 - if (maptarget && maptarget[0])
355 - int targetnum = atoi(maptarget+1);
356 - if (targetnum > maxtarget)
357 - maxtarget = targetnum;
360 - sprintf (newtarget, "t%i", maxtarget+1);
361 + id = GetUniqueTargetId(1);
362 + sprintf (newtarget, "t%i", id);
365 Sys_Printf("Connecting entities with new target/targetname: %s\n", newtarget);
368 - SetKeyValue (e1, "target", newtarget);
370 + SetKeyValue (e1, "killtarget", newtarget);
372 + SetKeyValue (e1, "target", newtarget);
373 SetKeyValue (e2, "targetname", newtarget);
376 +static int TargetIdForKey(entity_t *pe, const char *key)
378 + const char *p = ValueForKey(pe, key);
383 + return atoi(p + 1);
386 int GetUniqueTargetId(int iHint)
398 for (; pe != NULL && pe != &entities ; pe = pe->next)
400 - i = IntForKey(pe, "target");
403 - iMin = MIN(i, iMin);
404 - iMax = MAX(i, iMax);
408 + i = TargetIdForKey(pe, "target");
409 + iMax = MAX(i, iMax);
412 + i = TargetIdForKey(pe, "targetname");
413 + iMax = MAX(i, iMax);
416 + i = TargetIdForKey(pe, "killtarget");
417 + iMax = MAX(i, iMax);
423 Index: radiant/qe3.cpp
424 ===================================================================
425 --- radiant/qe3.cpp (revision 304)
426 +++ radiant/qe3.cpp (working copy)
428 from the first selected to the secon
431 -void ConnectEntities (void)
432 +void ConnectEntities (bool kill)
440 - target = ValueForKey (e1, "target");
441 + target = ValueForKey (e1, kill ? "killtarget" : "target");
442 if (target && target[0])
443 newtarg = g_strdup(target);
445 @@ -743,12 +743,12 @@
446 if(target && target[0])
447 newtarg = g_strdup(target);
449 - Entity_Connect(e1, e2);
450 + Entity_Connect(e1, e2, kill);
455 - SetKeyValue(e1, "target", newtarg);
456 + SetKeyValue(e1, kill ? "killtarget" : "target", newtarg);
457 SetKeyValue(e2, "targetname", newtarg);
461 ===================================================================
462 --- radiant/qe3.h (revision 304)
463 +++ radiant/qe3.h (working copy)
465 void SelectEdgeByRay (vec3_t org, vec3_t dir);
466 void SelectVertexByRay (vec3_t org, vec3_t dir);
468 -void ConnectEntities (void);
469 +void ConnectEntities (bool kill = false);
471 extern int update_bits;
477 -void Entity_Connect(entity_t *e1, entity_t *e2);
478 +void Entity_Connect(entity_t *e1, entity_t *e2, bool kill = false);
479 int GetUniqueTargetId(int iHint);