convert line ends
[canaan.git] / prj / cam / src / actreact / dumbprox.cpp
blobcb1079e43e80e07ae583336086fa14639a54fd11
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/actreact/dumbprox.cpp,v 1.2 1998/06/22 02:49:06 dc Exp $
7 // really dumb prox system for use for now
9 // this is a onedirectional model
10 // in which we assume that the number of objs in the world which might have
11 // prox info is very small compared to the number of objects in the world
12 // in general, such that it is faster/as fast to search all objects with
13 // the property, as opposed to scanning nearby space for objects which might
14 // have the property.
15 // clearly, as the effective prox distance drops, and the number of prox objects
16 // grows, this solution becomes a worse and worse fit to the actual problem
18 // as i see it, the real issue is quickly being able to create multiple prox
19 // properties, and that is the part that is bad about the current solution
21 #include <string.h>
23 #include <lg.h>
24 #include <dynarray.h>
25 #include <matrix.h>
27 #include <mprintf.h>
29 #include <objtype.h>
30 #include <objpos.h>
31 #include <wrtype.h>
33 #include <property.h>
34 #include <propface.h>
35 #include <propbase.h>
37 #include <dumbprox.h>
39 #include <dbmem.h>
41 #define PROX_PROP_IMPL kPropertyImplLlist
43 //static sPropertyDesc ProxPropDesc = { "Prox", 0, NULL, 0, 0, { "Prox", "Generic"} };
45 IBoolProperty *ProxBuildProp(char *prox_name)
47 sPropertyDesc *ProxPropDesc=new sPropertyDesc;
48 memset(ProxPropDesc,0,sizeof(sPropertyDesc));
49 strncpy(ProxPropDesc->name,prox_name,sizeof(ProxPropDesc->name));
50 ProxPropDesc->flags=kPropertyInstantiate;
51 char *tmp_cat=(char *)Malloc(sizeof("Prox")+1);
52 strcpy(tmp_cat,"Prox");
53 ProxPropDesc->ui.category=tmp_cat;
54 char *tmp_name=(char *)Malloc(strlen(prox_name)+1);
55 strcpy(tmp_name,prox_name);
56 ProxPropDesc->ui.friendly_name=tmp_name;
57 IBoolProperty *pProxProp=CreateBoolProperty(ProxPropDesc,PROX_PROP_IMPL);
58 delete ProxPropDesc;
59 return pProxProp;
62 BOOL ProxCheckLoc(IBoolProperty *pProx, mxs_vector *src_pos, float rad, cDynObjArray *objList, ProxCallback pCB)
64 sPropertyObjIter iter;
65 float rad_2=rad*rad;
66 BOOL found=FALSE, cur_val=FALSE;
67 ObjID obj;
69 if (src_pos==NULL) return FALSE;
70 pProx->IterStart(&iter);
71 while (pProx->IterNextValue(&iter,&obj,&cur_val))
72 if (cur_val&&(OBJ_IS_CONCRETE(obj)))
73 { // is obj in range
74 mxs_vector *iter_pos=&ObjPosGet(obj)->loc.vec;
75 float dist_2=mx_dist2_vec(src_pos,iter_pos);
76 if (dist_2<rad_2)
78 found=TRUE;
79 if (objList)
80 objList->Append(obj);
81 if (pCB)
82 if ((*pCB)(obj,dist_2)) // if callback returns true, abort out
83 break;
86 pProx->IterStop(&iter);
87 return found;
90 BOOL ProxCheckObj(IBoolProperty *pProx, ObjID src, float rad, cDynObjArray *objList, ProxCallback pCB)
92 mxs_vector *src_pos=ObjPosGetLocVector(src);
93 return ProxCheckLoc(pProx,src_pos,rad,objList,pCB);