root/deus/CheckWorldStates.cpp
| Revision 8, 12.3 kB (checked in by pantley2, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | /* part of get operators |
| 2 | condition CheckPartWorldState(World State&, condition) |
| 3 | { |
| 4 | if none of the nodes are met return NULL; |
| 5 | return the partial vectors of Game Objects |
| 6 | V1 V2 V3 |
| 7 | }*/ |
| 8 | |
| 9 | // Check the World to see if it fulfills this condition |
| 10 | // Return bindings that fulfill this condition |
| 11 | // If the there are none, return partial bindings |
| 12 | |
| 13 | |
| 14 | #include "structures.h" |
| 15 | #include <sstream> |
| 16 | #include <iostream> |
| 17 | |
| 18 | |
| 19 | vector<vector<GameObject *> > NullList |
| 20 | (vector<vector<GameObject*> > Obs, World* W, string** conds, int level); |
| 21 | |
| 22 | |
| 23 | Condition CheckWorldState(World* W, Condition C) |
| 24 | { |
| 25 | vector<vector<GameObject *> > Obs; |
| 26 | string ** Conds; |
| 27 | vector<GameObject *> TempV; |
| 28 | int HasNoNulls=0; |
| 29 | int i; |
| 30 | |
| 31 | Conds = (string**)C.conditions; |
| 32 | |
| 33 | Obs=GetList(Conds,W); |
| 34 | TempV.push_back(NULL); |
| 35 | //Obs.push_back(TempV); |
| 36 | for(i=0; i<10; i++) ///> changed 1 to 0 |
| 37 | { |
| 38 | Obs=NullList(Obs, W, Conds, i); |
| 39 | |
| 40 | } |
| 41 | /*for(std::vector<vector<GameObject *> >::iterator It1=Obs.begin(); |
| 42 | (It1<Obs.end() && HasNoNulls==0); It1++) |
| 43 | { |
| 44 | TempV=*It1; |
| 45 | for(i=0; i<TempV.size(); i++) |
| 46 | { |
| 47 | if(TempV[i]==NULL) |
| 48 | break; |
| 49 | } |
| 50 | if(i==TempV.size()) |
| 51 | HasNoNulls=1; |
| 52 | } |
| 53 | if(HasNoNulls) |
| 54 | { // If there are complete bindings, gets rid of all incomplete bindings |
| 55 | for(std::vector<vector<GameObject *> >::iterator It1=Obs.begin(); |
| 56 | (It1!=Obs.end() && HasNoNulls==0); ) |
| 57 | { |
| 58 | TempV=*It1; |
| 59 | for(i=0; i<TempV.size(); i++) |
| 60 | { |
| 61 | if(TempV[i]==NULL) |
| 62 | { |
| 63 | i=TempV.size() + 1; |
| 64 | Obs.erase(It1); |
| 65 | } |
| 66 | } |
| 67 | if( i != TempV.size() + 1) |
| 68 | ++It1; |
| 69 | } |
| 70 | }*/ |
| 71 | C.vars=Obs; |
| 72 | return C; |
| 73 | } |
| 74 | |
| 75 | vector<vector<GameObject *> > NullList |
| 76 | (vector<vector<GameObject*> > Obs, World* W, string** conds, int level) |
| 77 | { |
| 78 | // turn one vector into many many vectors, using trickery |
| 79 | |
| 80 | vector<vector<GameObject *> > Vec; |
| 81 | vector<GameObject *> TempV; |
| 82 | int i,j,k,npcvalue, num, value_int, groupval; |
| 83 | string attrib, ineq, groupname; |
| 84 | vector<int> IsIn(((*W).NPCs).size(),0); |
| 85 | vector<int> Passed; |
| 86 | ///>for(i=0; i<Obs.size(); i++) |
| 87 | ///>{ |
| 88 | if(conds[level][0]=="npc") |
| 89 | { |
| 90 | Obs.push_back(vector<GameObject*>(1,&W->NPCs[rand()%W->NPCs.size()])); |
| 91 | return Obs; |
| 92 | } |
| 93 | Obs.push_back(vector<GameObject*>(1,NULL)); |
| 94 | return Obs; |
| 95 | |
| 96 | // iterate through each piece of each condition |
| 97 | /*for(j=1; j<10; j++) |
| 98 | { |
| 99 | std::istringstream iss(conds[level][j]); |
| 100 | // npc stuff here; |
| 101 | // ******(**)****** |
| 102 | if(conds[i][j]=="") |
| 103 | break; |
| 104 | iss>>attrib; |
| 105 | iss>>num; //assume n=0 for now |
| 106 | for(int a=0; a<num+1; a++) |
| 107 | { |
| 108 | if(attrib=="rel") |
| 109 | { |
| 110 | iss>>groupname; |
| 111 | iss>>groupval; |
| 112 | } |
| 113 | else ///> added else here |
| 114 | { |
| 115 | iss>>ineq; |
| 116 | iss>>value_int; |
| 117 | } |
| 118 | |
| 119 | if(j==1) |
| 120 | { |
| 121 | for(k=0; k<((*W).NPCs).size(); k++) |
| 122 | { |
| 123 | ///>TempV.clear(); |
| 124 | ///>TempV=Obs[i]; |
| 125 | if(attrib=="rel") |
| 126 | npcvalue=((*W).NPCs)[k].relationships[std::pair<string,int>(groupname, groupval)]; |
| 127 | else |
| 128 | npcvalue=(((*W).NPCs)[k]).attributes[attrib]; |
| 129 | ///~ does any of this handle NPC1.hair == NPC2.hair ? |
| 130 | if(ineq=="=="){ |
| 131 | if(npcvalue==value_int && IsIn[k]==0){ |
| 132 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 133 | IsIn[k]=1;}} |
| 134 | else if(ineq=="!=") { |
| 135 | if(npcvalue != value_int && IsIn[k]==0){ |
| 136 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 137 | IsIn[k]=1;}} |
| 138 | else if(ineq=="<=") { |
| 139 | if(npcvalue <= value_int && IsIn[k]==0) { |
| 140 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 141 | IsIn[k]=1;}} |
| 142 | else if(ineq==">=") { |
| 143 | if(npcvalue >= value_int && IsIn[k]==0){ |
| 144 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 145 | IsIn[k]=1;}} |
| 146 | else if(ineq=="<") { |
| 147 | if(npcvalue < value_int && IsIn[k]==0){ |
| 148 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 149 | IsIn[k]=1;}} |
| 150 | else if(ineq==">"){ |
| 151 | if(npcvalue > value_int && IsIn[k]==0){ |
| 152 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 153 | IsIn[k]=1;}} |
| 154 | else { |
| 155 | ///>TempV.push_back(NULL); |
| 156 | } |
| 157 | ///>Vec.push_back(TempV); |
| 158 | ///>vector<int> temp(Vec.size(),0); |
| 159 | ///>Passed=temp; |
| 160 | } |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | for(k=0; k<((*W).NPCs).size(); k++) |
| 165 | { |
| 166 | ///>TempV.clear(); |
| 167 | ///>TempV=Obs[i]; |
| 168 | if(attrib=="rel") |
| 169 | npcvalue=((*W).NPCs)[k].relationships[std::pair<string,int>(groupname, groupval)]; |
| 170 | else |
| 171 | npcvalue=(((*W).NPCs)[k]).attributes[attrib]; |
| 172 | if(ineq=="=="){ |
| 173 | if(npcvalue!=value_int && IsIn[k]==1){ |
| 174 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 175 | IsIn[k]=0;}} |
| 176 | else if(ineq=="!=") { |
| 177 | if(npcvalue == value_int && IsIn[k]==1){ |
| 178 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 179 | IsIn[k]=0;}} |
| 180 | else if(ineq=="<=") { |
| 181 | if(npcvalue > value_int && IsIn[k]==1) { |
| 182 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 183 | IsIn[k]=0;}} |
| 184 | else if(ineq==">=") { |
| 185 | if(npcvalue < value_int && IsIn[k]==1){ |
| 186 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 187 | IsIn[k]=0;}} |
| 188 | else if(ineq=="<") { |
| 189 | if(npcvalue >= value_int && IsIn[k]==1){ |
| 190 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 191 | IsIn[k]=0;}} |
| 192 | else if(ineq==">"){ |
| 193 | if(npcvalue <= value_int && IsIn[k]==1){ |
| 194 | ///>TempV.push_back(&((*W).NPCs[k])); |
| 195 | IsIn[k]=0;}} |
| 196 | else { |
| 197 | ///>TempV.push_back(NULL); |
| 198 | } |
| 199 | ///>Vec.push_back(TempV); |
| 200 | ///>vector<int> temp(Vec.size(),0); |
| 201 | ///>Passed=temp; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | // end iterate through each condition |
| 206 | } //end npc list |
| 207 | |
| 208 | /*for(int ind=0; ind<Vec.size(); ind++) |
| 209 | { |
| 210 | // go through current list of stuff //******(**)****** |
| 211 | // call GetAttrib function here |
| 212 | if(attrib=="rel") |
| 213 | npcvalue=((NPC*)(Vec[ind][level]))->relationships[std::pair<string,int>(groupname, groupval)]; |
| 214 | else |
| 215 | npcvalue=((NPC*)(Vec[ind][level]))->attributes[attrib]; |
| 216 | if(ineq=="=="){ |
| 217 | if(npcvalue==value_int) { |
| 218 | Passed[ind]=1;}} |
| 219 | else if(ineq=="!="){ |
| 220 | if(npcvalue != value_int) { |
| 221 | Passed[ind]=1;}} |
| 222 | else if(ineq=="<="){ |
| 223 | if(npcvalue <= value_int) { |
| 224 | Passed[ind]=1;}} |
| 225 | else if(ineq==">="){ |
| 226 | if(npcvalue >= value_int) { |
| 227 | Passed[ind]=1;}} |
| 228 | else if(ineq=="<"){ |
| 229 | if(npcvalue < value_int) { |
| 230 | Passed[ind]=1;}} |
| 231 | else if(ineq==">"){ |
| 232 | if(npcvalue > value_int) { |
| 233 | Passed[ind]=1;}} |
| 234 | }*/ |
| 235 | ///>} |
| 236 | |
| 237 | |
| 238 | /* for(int p=0; p<IsIn.size(); ++p) |
| 239 | { |
| 240 | if(IsIn[p]) |
| 241 | { |
| 242 | TempV.push_back(&(*W).NPCs[p]); |
| 243 | } |
| 244 | } |
| 245 | if(TempV.size() == 0) |
| 246 | { |
| 247 | if(level == 0 || Obs[level-1].size()==0) |
| 248 | { |
| 249 | Vec = Obs; |
| 250 | Vec.push_back(vector<GameObject*>(1, NULL)); |
| 251 | return Vec; |
| 252 | } |
| 253 | Vec = Obs; |
| 254 | Vec.push_back(vector<GameObject*>(Vec[level-1].size(),NULL)); |
| 255 | return Vec; |
| 256 | } |
| 257 | if(level == 0) |
| 258 | { |
| 259 | Vec.push_back(TempV); |
| 260 | return Vec; |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | int size = Obs[0].size(); |
| 265 | |
| 266 | for(int t=1; t<TempV.size(); ++t) |
| 267 | { |
| 268 | for(int s=0; s<Obs.size(); ++s) |
| 269 | { |
| 270 | for(int q=0; q<Obs[s].size(); ++q) |
| 271 | Vec[s].push_back(Obs[s][q]); |
| 272 | } |
| 273 | } |
| 274 | Vec.push_back(vector<GameObject*>()); |
| 275 | for(int z=0; z<TempV.size(); ++z) |
| 276 | for(int f=0; f<size; ++f) |
| 277 | Vec[level].push_back(TempV[z]); |
| 278 | } |
| 279 | return Vec; |
| 280 | /*int ind = 0; |
| 281 | for(std::vector<vector<GameObject*> >::iterator Iter=Vec.begin(); Iter!=Vec.end(); Iter++) |
| 282 | { |
| 283 | if(Passed[ind]==0) |
| 284 | (*Iter)[level]=NULL; |
| 285 | ind++; |
| 286 | }*/ |
| 287 | |
| 288 | |
| 289 | |
| 290 | return Vec; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | /* |
| 295 | vector<vector<GameObject *> > NullList |
| 296 | (vector<vector<GameObject*> > Obs, World* W, string** conds, int level) |
| 297 | { |
| 298 | // turn one vector into many many vectors, using trickery |
| 299 | std::cerr << "1: " << Obs.size() << std::endl;///~ |
| 300 | vector<vector<GameObject *> > Vec (Obs); |
| 301 | vector<GameObject *> TempV; |
| 302 | int i,j,k,npcvalue, num, value_int, groupval; |
| 303 | string attrib, ineq, groupname; |
| 304 | vector<int> IsIn(((*W).NPCs).size(),0); |
| 305 | vector<int> Passed; |
| 306 | for(i=0; i<Obs.size(); i++) |
| 307 | { |
| 308 | if(conds[level][0]=="npc") |
| 309 | { |
| 310 | // iterate through each piece of each condition |
| 311 | for(j=1; j<10; j++) |
| 312 | { |
| 313 | std::istringstream iss(conds[level][j]); |
| 314 | // npc stuff here; |
| 315 | // ******(**)****** |
| 316 | if(conds[i][j]=="") |
| 317 | break; |
| 318 | iss>>attrib; |
| 319 | iss>>num; //assume n=0 for now |
| 320 | for(int a=0; a<num+1; a++) |
| 321 | { |
| 322 | if(attrib=="rel") |
| 323 | { |
| 324 | iss>>groupname; |
| 325 | iss>>groupval; |
| 326 | } |
| 327 | else ///> added else here |
| 328 | { |
| 329 | iss>>ineq; |
| 330 | iss>>value_int; |
| 331 | } |
| 332 | |
| 333 | if(j==1) |
| 334 | { |
| 335 | for(k=0; k<((*W).NPCs).size(); k++) |
| 336 | { |
| 337 | TempV.clear(); |
| 338 | TempV=Obs[i]; |
| 339 | if(attrib=="rel") |
| 340 | npcvalue=((*W).NPCs)[k].relationships[std::pair<string,int>(groupname, groupval)]; |
| 341 | else |
| 342 | npcvalue=(((*W).NPCs)[k]).attributes[attrib]; |
| 343 | if(ineq=="=="){ |
| 344 | if(npcvalue==value_int && IsIn[k]==0){ |
| 345 | TempV.push_back(&((*W).NPCs[k])); |
| 346 | IsIn[k]=1;}} |
| 347 | else if(ineq=="!=") { |
| 348 | if(npcvalue != value_int && IsIn[k]==0){ |
| 349 | TempV.push_back(&((*W).NPCs[k])); |
| 350 | IsIn[k]=1;}} |
| 351 | else if(ineq=="<=") { |
| 352 | if(npcvalue <= value_int && IsIn[k]==0) { |
| 353 | TempV.push_back(&((*W).NPCs[k])); |
| 354 | IsIn[k]=1;}} |
| 355 | else if(ineq==">=") { |
| 356 | if(npcvalue >= value_int && IsIn[k]==0){ |
| 357 | TempV.push_back(&((*W).NPCs[k])); |
| 358 | IsIn[k]=1;}} |
| 359 | else if(ineq=="<") { |
| 360 | if(npcvalue < value_int && IsIn[k]==0){ |
| 361 | TempV.push_back(&((*W).NPCs[k])); |
| 362 | IsIn[k]=1;}} |
| 363 | else if(ineq==">"){ |
| 364 | if(npcvalue > value_int && IsIn[k]==0){ |
| 365 | TempV.push_back(&((*W).NPCs[k])); |
| 366 | IsIn[k]=1;}} |
| 367 | else { |
| 368 | TempV.push_back(NULL);} |
| 369 | Vec.push_back(TempV); |
| 370 | vector<int> temp(Vec.size(),0); |
| 371 | Passed=temp; |
| 372 | } |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | for(int ind=0; ind<Vec.size(); ind++) |
| 377 | { |
| 378 | // go through current list of stuff //******(**)****** |
| 379 | // call GetAttrib function here |
| 380 | if(attrib=="rel") |
| 381 | npcvalue=((NPC*)(Vec[ind][level]))->relationships[std::pair<string,int>(groupname, groupval)]; |
| 382 | else |
| 383 | npcvalue=((NPC*)(Vec[ind][level]))->attributes[attrib]; |
| 384 | if(ineq=="=="){ |
| 385 | if(npcvalue==value_int) { |
| 386 | Passed[ind]=1;}} |
| 387 | else if(ineq=="!="){ |
| 388 | if(npcvalue != value_int) { |
| 389 | Passed[ind]=1;}} |
| 390 | else if(ineq=="<="){ |
| 391 | if(npcvalue <= value_int) { |
| 392 | Passed[ind]=1;}} |
| 393 | else if(ineq==">="){ |
| 394 | if(npcvalue >= value_int) { |
| 395 | Passed[ind]=1;}} |
| 396 | else if(ineq=="<"){ |
| 397 | if(npcvalue < value_int) { |
| 398 | Passed[ind]=1;}} |
| 399 | else if(ineq==">"){ |
| 400 | if(npcvalue > value_int) { |
| 401 | Passed[ind]=1;}} |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | int ind = 0; |
| 406 | for(std::vector<vector<GameObject*> >::iterator Iter=Vec.begin(); Iter!=Vec.end(); Iter++) |
| 407 | { |
| 408 | if(Passed[ind]==0) |
| 409 | (*Iter)[level]=NULL; |
| 410 | ind++; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | // end iterate through each condition |
| 415 | } //end npc list |
| 416 | } |
| 417 | std::cerr << "2: " << Vec.size() << std::endl;///~ |
| 418 | return Vec; |
| 419 | } |
| 420 | */ |
| 421 | |
| 422 | |
| 423 | |
| 424 |
Note: See TracBrowser for help on using the browser.
