root/deus/GetGregOps.cpp

Revision 8, 7.8 kB (checked in by pantley2, 4 years ago)

added old DEUS project to SVN

Line 
1
2 #include "structures.h"
3
4 #include<list>
5 #include<vector>
6 #include<sstream>
7 #include<string>
8
9 using std::list;
10 using std::vector;
11 using std::string;
12
13
14 //  ignoring the or's at this point
15 //  need function getnpcattribute(npc x, string y) returns x.y;
16 //  assume value of first npc is 101, second npc is 102
17 //              so to say NPC has height > NPC 1, "height 0 > 101"
18
19 list<Operator>* GetGregOperators(World* W)
20 {
21   std::list<Operator>::iterator It;        // iterates through the list of possible operators
22   list <Operator> *Returner = new list<Operator>();        // returns the list of operators
23   vector<vector<GameObject *> > Obs;  // Temporary vector used to find bindings
24   string ** Conds;                            // Temporary vector of the preconditions for an operator
25   vector<GameObject *> TempV;         // temporary vector of possibilities for each case in a binding
26   Operator TempO;                     // temp Operator
27   Condition TempC;                    // temp condition
28   int i,satisfy;
29
30   for(It=Ops.begin(); It != Ops.end(); It++)
31   {
32     TempO=*It;
33     TempC=TempO.PreConds;
34     Conds= (string **)TempC.conditions;
35     satisfy=1;         
36        
37         Obs=GetList(Conds,W);
38         if(Obs.size()==0)
39                 satisfy=0;
40        
41         for(i=1; (i<10 && satisfy!=0); i++)
42         {
43                 Obs=BindList(Obs, W, Conds, i);
44                 if(Obs.size==0)
45                         satisfy=0;
46         }
47        
48         //if(satisfy==0)
49         //      break;
50         //else
51         //{
52                 TempC.vars=Obs;
53                 TempO.PreConds=TempC;
54                 Returner->push_back(TempO);
55         //}
56   }
57   return Returner;
58 }
59
60 vector<vector<GameObject *> > BindList(vector<vector<GameObject*> > Obs, World* W, string** conds, int level)
61 {
62         // turn one vector into many many vectors, using trickery
63         vector<vector<GameObject *> > Vec;
64         vector<GameObject *> TempV;
65         int i,j,k,npcvalue, num, groupval, value_int;
66         string attrib, ineq, groupname;
67
68         vector<int> IsIn(((*W).NPCs).size(),0);
69         vector<int> Passed;
70
71         for(i=0; i<10; i++)
72         {
73                 vector<int> IsIn(((*W).NPCs).size(),0);
74                 if(conds[i][0]=="npc")
75                 {
76                         // iterate through each piece of each condition
77                         for(j=1; j<NUM_COND; j++)
78                         {
79                                
80                                 if(conds[i][j]=="")
81                                         break;
82                                 std::istringstream iss(conds[i][j]);
83                                 // npc stuff here;
84                                 // ******(**)******
85                                 iss>>attrib;
86                                 iss>>num; //assume n=0 for now
87                                 for(int a=0; a<num+1; a++)
88                                 {
89                                         if(attrib=="rel")
90                                         {
91                                                 iss>>groupname;
92                                                 iss>>groupval;
93                                         }
94                                         iss>>ineq;
95                                         iss>>value_int;
96                                         if(j==1)
97                                         {
98                                                 for(k=0; k<((*W).NPCs).size(); k++)
99                                                 {
100                                                         TempV.clear();
101                                                         TempV=Obs[i];
102                                                         // call GetAttrib function here
103                                                         if(attrib=="rel")
104                                                                 npcvalue=((*W).NPCs)[k].relationships[std::pair<string,int>(groupname,groupval)];
105                                                         else
106                                                                 npcvalue=(((*W).NPCs)[k]).attributes[attrib];     
107                                                         if(ineq=="=="){
108                                                                 if(npcvalue==value_int && IsIn[k]==0){
109                                                                         TempV.push_back(&((*W).NPCs[k]));
110                                                                         IsIn[k]=1;}}
111                                                         else if(ineq=="!=") {
112                                                                 if(npcvalue != value_int && IsIn[k]==0){
113                                                                         TempV.push_back(&((*W).NPCs[k]));
114                                                                         IsIn[k]=1;}}
115                                                         else if(ineq=="<=") {
116                                                                 if(npcvalue <= value_int && IsIn[k]==0) {
117                                                                         TempV.push_back(&((*W).NPCs[k]));
118                                                                         IsIn[k]=1;}}
119                                                         else if(ineq==">=") {
120                                                                 if(npcvalue >= value_int && IsIn[k]==0){
121                                                                         TempV.push_back(&((*W).NPCs[k]));
122                                                                         IsIn[k]=1;}}
123                                                         else if(ineq=="<") {
124                                                                 if(npcvalue < value_int && IsIn[k]==0){
125                                                                         TempV.push_back(&((*W).NPCs[k]));
126                                                                         IsIn[k]=1;}}
127                                                         else if(ineq==">"){
128                                                                 if(npcvalue > value_int && IsIn[k]==0){
129                                                                         TempV.push_back(&((*W).NPCs[k]));
130                                                                         IsIn[k]=1;}}
131                                                         if(TempV.size()==level+1)
132                                                                 Vec.push_back(TempV);
133                                                         vector<int> temp(Vec.size(),0);
134                                                         Passed=temp;
135                                                 }
136                                         }
137                                         else
138                                         {
139                                                 for(int ind=0; ind<Vec.size(); ind++)
140                                                 {
141                                                         // go through current list of stuff //******(**)******
142                                                         // call GetAttrib function here
143                                                         if(attrib=="rel")
144                                                                 npcvalue=(((NPC*)(Vec[ind][level])))->relationships[std::pair<string,int>(groupname,groupval)];
145                                                         else
146                                                                 npcvalue=((NPC*)(Vec[ind][level]))->attributes[attrib];
147                                                         if(ineq=="==")
148                                                                 if(npcvalue == value_int)
149                                                                         Passed[ind]=1;
150                                                         else if(ineq=="!=")
151                                                                 if(npcvalue != value_int)
152                                                                         Passed[ind]=1;
153                                                         else if(ineq=="<=")
154                                                                 if(npcvalue <= value_int)
155                                                                         Passed[ind]=1;
156                                                         else if(ineq==">=")
157                                                                 if(npcvalue >= value_int)
158                                                                         Passed[ind]=1;
159                                                         else if(ineq=="<")
160                                                                 if(npcvalue < value_int)
161                                                                         Passed[ind]=1;
162                                                         else if(ineq==">")
163                                                                 if(npcvalue > value_int)
164                                                                         Passed[ind]=1;
165                                                 }
166                                         }
167                                 }
168                                 int ind=0;
169                                 for(std::vector<vector<GameObject*> >::iterator Iter=Vec.begin(); Iter!=Vec.end(); Iter++)
170                                 {
171                                         if(Passed[ind]==0)
172                                                 Vec.erase(Iter);
173                                         ind++;
174                                 }       
175                         }// end iterate through each condition
176                 } //end npc list
177         }
178         return Vec;
179 }
180
181 vector<vector<GameObject *> > GetList(string** conds, World* W)
182 {
183         vector<vector<GameObject *> > Vec;
184         vector<GameObject *> TempV;
185         int j,k,npcvalue,num, groupval, value_int;
186         string attrib, ineq;
187         string groupname;
188         vector<int> IsIn(((*W).NPCs).size(),0);
189         vector<int> Passed;
190         if(conds[0][0]=="npc")
191     {
192                 // iterate through each piece of each condition
193                 for(j=1; j<10; j++)
194                 {
195                         if(conds[0][j]=="")
196                                 break;
197                         std::istringstream iss(conds[0][j]);
198                         // npc stuff here;
199                         // ******(**)******
200                         iss>>attrib;
201                         iss>>num; //assume n=0 for now                 
202                         for(int a=0; a<num+1; a++)
203                         {
204                                 if(attrib=="rel")
205                                 {
206                                         iss>>groupname;
207                                         iss>>groupval;
208                                 }
209                                 iss>>ineq;
210                                 iss>> value_int;
211                                 if(j==1)
212                                 {
213                                         for(k=0; k<((*W).NPCs).size(); k++)
214                                         {
215                                        
216                                         TempV.clear();
217                                         if(attrib=="rel")
218                                                 npcvalue=((((*W).NPCs)[k]).relationships)[std::pair<string,int>(groupname,groupval)];     
219                                         else
220                                                 npcvalue=((((*W).NPCs)[k])).attributes[attrib];
221                                         if(ineq=="=="){
222                                                   if(npcvalue==value_int && IsIn[k]==0){
223                                                           TempV.push_back(&(((*W).NPCs)[k]));
224                                                           IsIn[k]=1;                                            }}
225                                         else if(ineq=="!=") {
226                                                   if(npcvalue != value_int && IsIn[k]==0){
227                                                           TempV.push_back(&((*W).NPCs[k]));
228                                                       IsIn[k]=1;                                                }}
229                                         else if(ineq=="<=") {
230                                                   if(npcvalue <= value_int && IsIn[k]==0) {
231                                                           TempV.push_back(&((*W).NPCs[k]));
232                                                       IsIn[k]=1;                                                }}
233                                         else if(ineq==">=") {
234                                                   if(npcvalue >= value_int && IsIn[k]==0){
235                                                           TempV.push_back(&((*W).NPCs[k]));
236                                                       IsIn[k]=1;                                                }}
237                                         else if(ineq=="<") {
238                                                   if(npcvalue < value_int && IsIn[k]==0){
239                                                       TempV.push_back(&((*W).NPCs[k]));
240                                                       IsIn[k]=1;                                                }}
241                                         else if(ineq==">"){
242                                                   if(npcvalue > value_int && IsIn[k]==0){
243                                                           TempV.push_back(&((*W).NPCs[k]));
244                                                           IsIn[k]=1;                                            }}
245                                         if(TempV.size!=0)
246                                           Vec.push_back(TempV);
247                                         }
248                                         vector<int> temp(Vec.size(),0);
249                                         Passed=temp;
250                                 }
251                                 else
252                                 { 
253                                         for(int ind=0; ind<Vec.size(); ind++)
254                                         {
255                                                 // go through current list of stuff //******(**)******
256                                                 // call GetAttrib function here
257                                                 if(attrib=="rel")
258                                                         npcvalue=(((NPC*)Vec[ind][0])->relationships)[std::pair<string, int>(groupname, groupval)];
259                                                 else
260                                                         npcvalue=(((NPC*)Vec[ind][0])->attributes)[attrib];     
261                                                 if(ineq=="==")
262                                                         if(npcvalue==value_int)
263                                                                 Passed[ind]=1;
264                                                 else if(ineq=="!=")
265                                                         if(npcvalue != value_int)
266                                                                 Passed[ind]=1;
267                                                 else if(ineq=="<=")
268                                                         if(npcvalue <= value_int)
269                                                                 Passed[ind]=1;
270                                                 else if(ineq==">=")
271                                                         if(npcvalue >= value_int)
272                                                                 Passed[ind]=1;
273                                                 else if(ineq=="<")
274                                                         if(npcvalue < value_int)
275                                                                 Passed[ind]=1;
276                                                 else if(ineq==">")
277                                                         if(npcvalue > value_int)
278                                                                 Passed[ind]=1;
279                                         }
280                                 }
281                         }
282                         int ind=0;
283                         for(std::vector<vector<GameObject*> >::iterator Iter=Vec.begin(); Iter!=Vec.end(); Iter++)
284                         {
285                                 if(Passed[ind]==0)
286                                         Vec.erase(Iter);
287                                 ind++;
288                         }                       
289                 }
290         }// end iterate through each condition 
291         return Vec;
292 }
Note: See TracBrowser for help on using the browser.