]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/havocbot/role_keyhunt.qc
Shoot down another gamemode specific check
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / role_keyhunt.qc
1 #include "role_keyhunt.qh"
2
3 #include "havocbot.qh"
4
5 #include "../bot.qh"
6 #include "../navigation.qh"
7
8 #include "../../mutators/mutators_include.qh"
9
10 void() havocbot_role_kh_carrier;
11 void() havocbot_role_kh_defense;
12 void() havocbot_role_kh_offense;
13 void() havocbot_role_kh_freelancer;
14
15
16 void havocbot_goalrating_kh(float ratingscale_team, float ratingscale_dropped, float ratingscale_enemy)
17 {SELFPARAM();
18         entity head;
19         for (head = kh_worldkeylist; head; head = head.kh_worldkeynext)
20         {
21                 if(head.owner == self)
22                         continue;
23                 if(!kh_tracking_enabled)
24                 {
25                         // if it's carried by our team we know about it
26                         // otherwise we have to see it to know about it
27                         if(!head.owner || head.team != self.team)
28                         {
29                                 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
30                                 if (trace_fraction < 1 && trace_ent != head)
31                                         continue; // skip what I can't see
32                         }
33                 }
34                 if(!head.owner)
35                         navigation_routerating(head, ratingscale_dropped * BOT_PICKUP_RATING_HIGH, 100000);
36                 else if(head.team == self.team)
37                         navigation_routerating(head.owner, ratingscale_team * BOT_PICKUP_RATING_HIGH, 100000);
38                 else
39                         navigation_routerating(head.owner, ratingscale_enemy * BOT_PICKUP_RATING_HIGH, 100000);
40         }
41
42         havocbot_goalrating_items(1, self.origin, 10000);
43 }
44
45 void havocbot_role_kh_carrier()
46 {SELFPARAM();
47         if(self.deadflag != DEAD_NO)
48                 return;
49
50         if (!(self.kh_next))
51         {
52                 LOG_TRACE("changing role to freelancer\n");
53                 self.havocbot_role = havocbot_role_kh_freelancer;
54                 self.havocbot_role_timeout = 0;
55                 return;
56         }
57
58         if (self.bot_strategytime < time)
59         {
60                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
61                 navigation_goalrating_start();
62
63                 if(kh_Key_AllOwnedByWhichTeam() == self.team)
64                         havocbot_goalrating_kh(10, 0.1, 0.1); // bring home
65                 else
66                         havocbot_goalrating_kh(4, 4, 1); // play defensively
67
68                 navigation_goalrating_end();
69         }
70 }
71
72 void havocbot_role_kh_defense()
73 {SELFPARAM();
74         if(self.deadflag != DEAD_NO)
75                 return;
76
77         if (self.kh_next)
78         {
79                 LOG_TRACE("changing role to carrier\n");
80                 self.havocbot_role = havocbot_role_kh_carrier;
81                 self.havocbot_role_timeout = 0;
82                 return;
83         }
84
85         if (!self.havocbot_role_timeout)
86                 self.havocbot_role_timeout = time + random() * 10 + 20;
87         if (time > self.havocbot_role_timeout)
88         {
89                 LOG_TRACE("changing role to freelancer\n");
90                 self.havocbot_role = havocbot_role_kh_freelancer;
91                 self.havocbot_role_timeout = 0;
92                 return;
93         }
94
95         if (self.bot_strategytime < time)
96         {
97                 float key_owner_team;
98                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
99                 navigation_goalrating_start();
100
101                 key_owner_team = kh_Key_AllOwnedByWhichTeam();
102                 if(key_owner_team == self.team)
103                         havocbot_goalrating_kh(10, 0.1, 0.1); // defend key carriers
104                 else if(key_owner_team == -1)
105                         havocbot_goalrating_kh(4, 1, 0.1); // play defensively
106                 else
107                         havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK ANYWAY
108
109                 navigation_goalrating_end();
110         }
111 }
112
113 void havocbot_role_kh_offense()
114 {SELFPARAM();
115         if(self.deadflag != DEAD_NO)
116                 return;
117
118         if (self.kh_next)
119         {
120                 LOG_TRACE("changing role to carrier\n");
121                 self.havocbot_role = havocbot_role_kh_carrier;
122                 self.havocbot_role_timeout = 0;
123                 return;
124         }
125
126         if (!self.havocbot_role_timeout)
127                 self.havocbot_role_timeout = time + random() * 10 + 20;
128         if (time > self.havocbot_role_timeout)
129         {
130                 LOG_TRACE("changing role to freelancer\n");
131                 self.havocbot_role = havocbot_role_kh_freelancer;
132                 self.havocbot_role_timeout = 0;
133                 return;
134         }
135
136         if (self.bot_strategytime < time)
137         {
138                 float key_owner_team;
139
140                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
141                 navigation_goalrating_start();
142
143                 key_owner_team = kh_Key_AllOwnedByWhichTeam();
144                 if(key_owner_team == self.team)
145                         havocbot_goalrating_kh(10, 0.1, 0.1); // defend anyway
146                 else if(key_owner_team == -1)
147                         havocbot_goalrating_kh(0.1, 1, 4); // play offensively
148                 else
149                         havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK! EMERGENCY!
150
151                 navigation_goalrating_end();
152         }
153 }
154
155 void havocbot_role_kh_freelancer()
156 {SELFPARAM();
157         if(self.deadflag != DEAD_NO)
158                 return;
159
160         if (self.kh_next)
161         {
162                 LOG_TRACE("changing role to carrier\n");
163                 self.havocbot_role = havocbot_role_kh_carrier;
164                 self.havocbot_role_timeout = 0;
165                 return;
166         }
167
168         if (!self.havocbot_role_timeout)
169                 self.havocbot_role_timeout = time + random() * 10 + 10;
170         if (time > self.havocbot_role_timeout)
171         {
172                 if (random() < 0.5)
173                 {
174                         LOG_TRACE("changing role to offense\n");
175                         self.havocbot_role = havocbot_role_kh_offense;
176                 }
177                 else
178                 {
179                         LOG_TRACE("changing role to defense\n");
180                         self.havocbot_role = havocbot_role_kh_defense;
181                 }
182                 self.havocbot_role_timeout = 0;
183                 return;
184         }
185
186         if (self.bot_strategytime < time)
187         {
188                 float key_owner_team;
189
190                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
191                 navigation_goalrating_start();
192
193                 key_owner_team = kh_Key_AllOwnedByWhichTeam();
194                 if(key_owner_team == self.team)
195                         havocbot_goalrating_kh(10, 0.1, 0.1); // defend anyway
196                 else if(key_owner_team == -1)
197                         havocbot_goalrating_kh(1, 10, 4); // prefer dropped keys
198                 else
199                         havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK ANYWAY
200
201                 navigation_goalrating_end();
202         }
203 }
204
205 void havocbot_chooserole_kh()
206 {SELFPARAM();
207         float r;
208
209         if(self.deadflag != DEAD_NO)
210                 return;
211
212         r = random() * 3;
213         if (r < 1)
214                 self.havocbot_role = havocbot_role_kh_offense;
215         else if (r < 2)
216                 self.havocbot_role = havocbot_role_kh_defense;
217         else
218                 self.havocbot_role = havocbot_role_kh_freelancer;
219 }