root/deus/doops.cpp

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

added old DEUS project to SVN

Line 
1
2 #include "structures.h"
3
4 #include <time.h>
5 #include <stdlib.h>
6
7
8 void DoOps(World* W, Operator* O)
9 {
10         srand(time(0));
11
12         vector<string> attributes(7);
13         vector<int> size(7);
14         attributes[0]="Hunger";                 size[0]=100;
15         attributes[1]="Occupation";             size[1]=20;
16         attributes[2]="Drunk";                  size[2]=100;
17         attributes[3]="Thirst";                 size[3]=10;
18         attributes[4]="Money";                  size[4]=10000;
19         attributes[5]="Morality";               size[5]=10;
20         attributes[6]="Fatigue";                size[6]=10;
21         Operator Op=*(O);
22        
23         int which_attrib, group_value, attrib_value;
24         if(((Op.PreConds).vars).size()==0)
25                 return;
26         NPC n=*((NPC*)(((Op.PreConds).vars)[0][0]));
27
28         if(Op.code==OP_MOVENPC)
29         {
30                 //istringstream iss=(Op.PostConds.conditions
31                 n.xcoord=rand()%300;
32                 n.ycoord=rand()%300;
33         }
34
35         if(Op.code==OP_CHANGEATTRIBUTE)
36         {
37                 which_attrib=rand()%7;
38                 attrib_value=rand()%(size[which_attrib]);
39                 (n.attributes)[attributes[which_attrib]]=attrib_value;
40         }
41
42         if(Op.code==OP_CHANGERELATIONSHIP)
43         {
44                 which_attrib=rand()%7;
45                 group_value=rand()%(size[which_attrib]);
46                 attrib_value=rand()%51;
47                 attrib_value=attrib_value*(1-2*(rand()%2));
48                 std::map<std::pair<string,int>,int>::iterator It=((n.relationships).find(std::pair<string,int>(attributes[which_attrib], group_value)));
49                 if(It==((n.relationships).end()))
50                 {
51                         std::pair<string, int> P1;
52                         P1=std::pair<string,int> (attributes[which_attrib], group_value);
53                         (n.relationships).insert(std::pair<std::pair<string, int>,int>(P1, attrib_value));
54                 }
55                 else
56                 {
57                         (n.relationships)[std::pair<string, int>(attributes[which_attrib], group_value)]=attrib_value;
58                 }
59
60         }
61 }
Note: See TracBrowser for help on using the browser.