]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/havocbot/roles.qc
Merge branch 'master' into Mario/ons_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / roles.qc
1
2 .float max_armorvalue;
3 .float havocbot_role_timeout;
4
5 .void() havocbot_previous_role;
6 .void() havocbot_role;
7
8 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
9 {
10         entity head;
11         entity player;
12         float rating, d, discard, distance, friend_distance, enemy_distance;
13         vector o;
14         ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
15         head = findchainfloat(bot_pickup, true);
16
17         while (head)
18         {
19                 o = (head.absmin + head.absmax) * 0.5;
20                 distance = vlen(o - org);
21                 friend_distance = 10000; enemy_distance = 10000;
22                 rating = 0;
23
24                 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
25                 {
26                         head = head.chain;
27                         continue;
28                 }
29
30                 // Check if the item can be picked up safely
31                 if(head.classname == "droppedweapon")
32                 {
33                         traceline(o, o + '0 0 -1500', true, world);
34
35                         d = pointcontents(trace_endpos + '0 0 1');
36                         if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
37                         {
38                                 head = head.chain;
39                                 continue;
40                         }
41                         if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
42                         {
43                                 head = head.chain;
44                                 continue;
45                         }
46                 }
47                 else
48                 {
49                         // Ignore items under water
50                         traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
51                         if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
52                         {
53                                 head = head.chain;
54                                 continue;
55                         }
56                 }
57
58                 if(teamplay)
59                 {
60                         discard = false;
61
62                         FOR_EACH_PLAYER(player)
63                         {
64
65                                 if ( self == player || player.deadflag )
66                                         continue;
67
68                                 d = vlen(player.origin - o); // distance between player and item
69
70                                 if ( player.team == self.team )
71                                 {
72                                         if ( !IS_REAL_CLIENT(player) || discard )
73                                                 continue;
74
75                                         if( d > friend_distance)
76                                                 continue;
77
78                                         friend_distance = d;
79
80                                         discard = true;
81
82                                         if( head.health && player.health > self.health )
83                                                 continue;
84
85                                         if( head.armorvalue && player.armorvalue > self.armorvalue)
86                                                 continue;
87
88                                         if( head.weapons )
89                                         if( head.weapons & ~player.weapons )
90                                                 continue;
91
92                                         if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
93                                                 continue;
94
95                                         if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
96                                                 continue;
97
98                                         if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
99                                                 continue;
100
101                                         if (head.ammo_cells && player.ammo_cells > self.ammo_cells)
102                                                 continue;
103
104                                         if (head.ammo_plasma && player.ammo_plasma > self.ammo_plasma)
105                                                 continue;
106
107                                         discard = false;
108                                 }
109                                 else
110                                 {
111                                         // If enemy only track distances
112                                         // TODO: track only if visible ?
113                                         if( d < enemy_distance )
114                                                 enemy_distance = d;
115                                 }
116                         }
117
118                         // Rate the item only if no one needs it, or if an enemy is closer to it
119                         if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
120                                 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
121                                 rating = head.bot_pickupevalfunc(self, head);
122
123                 }
124                 else
125                         rating = head.bot_pickupevalfunc(self, head);
126
127                 if(rating > 0)
128                         navigation_routerating(head, rating * ratingscale, 2000);
129                 head = head.chain;
130         }
131 }
132
133 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
134 {
135         entity head;
136         head = findchain(classname, "dom_controlpoint");
137         while (head)
138         {
139                 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
140                 {
141                         if(head.cnt > -1) // this is just being fought for
142                                 navigation_routerating(head, ratingscale, 5000);
143                         else if(head.goalentity.cnt == 0) // unclaimed point
144                                 navigation_routerating(head, ratingscale * 0.5, 5000);
145                         else if(head.goalentity.team != self.team) // other team's point
146                                 navigation_routerating(head, ratingscale * 0.2, 5000);
147                 }
148                 head = head.chain;
149         }
150 }
151
152 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
153 {
154         entity head;
155         int t;
156         float distance;
157         noref bool noteam = ((self.team == 0) || !teamplay);
158
159         if (autocvar_bot_nofire)
160                 return;
161
162         // don't chase players if we're under water
163         if(self.waterlevel>WATERLEVEL_WETFEET)
164                 return;
165
166         FOR_EACH_PLAYER(head)
167         {
168                 // TODO: Merge this logic with the bot_shouldattack function
169                 if(bot_shouldattack(head))
170                 {
171                         distance = vlen(head.origin - org);
172                         if (distance < 100 || distance > sradius)
173                                 continue;
174
175                         // rate only visible enemies
176                         /*
177                         traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
178                         if (trace_fraction < 1 || trace_ent != head)
179                                 continue;
180                         */
181
182                         if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
183                                 continue;
184
185                         // not falling
186                         if((head.flags & FL_ONGROUND) == 0)
187                         {
188                                 traceline(head.origin, head.origin + '0 0 -1500', true, world);
189                                 t = pointcontents(trace_endpos + '0 0 1');
190                                 if( t != CONTENT_SOLID )
191                                 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
192                                         continue;
193                                 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
194                                         continue;
195                         }
196
197                         // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
198                         //               adding a player as a goal seems to be quite dangerous, especially on space maps
199                         //               remove hack in navigation_poptouchedgoals() after performing this change
200
201                         t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
202                         navigation_routerating(head, t * ratingscale, 2000);
203                 }
204         }
205 }
206
207 // choose a role according to the situation
208 void havocbot_role_dm();
209
210 //DM:
211 //go to best items
212 void havocbot_role_dm()
213 {
214         if(self.deadflag != DEAD_NO)
215                 return;
216
217         if (self.bot_strategytime < time)
218         {
219                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
220                 navigation_goalrating_start();
221                 havocbot_goalrating_items(10000, self.origin, 10000);
222                 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
223                 //havocbot_goalrating_waypoints(1, self.origin, 1000);
224                 navigation_goalrating_end();
225         }
226 }
227
228 void havocbot_chooserole_dm()
229 {
230         self.havocbot_role = havocbot_role_dm;
231 }
232
233 void havocbot_chooserole()
234 {
235         dprint("choosing a role...\n");
236         self.bot_strategytime = 0;
237         if (MUTATOR_CALLHOOK(HavocBot_ChooseRole))
238                 return;
239         else if (g_keyhunt)
240                 havocbot_chooserole_kh();
241         else // assume anything else is deathmatch
242                 havocbot_chooserole_dm();
243 }