]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/havocbot/role_assault.qc
57380dd038db1160c7053ef125a930dbb5e5c0ed
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / role_assault.qc
1 #define HAVOCBOT_AST_ROLE_NONE          0
2 #define HAVOCBOT_AST_ROLE_DEFENSE       2
3 #define HAVOCBOT_AST_ROLE_OFFENSE       8
4
5 .float havocbot_role_flags;
6 .float havocbot_attack_time;
7
8 .void() havocbot_role;
9 .void() havocbot_previous_role;
10
11 void() havocbot_role_ast_defense;
12 void() havocbot_role_ast_offense;
13 .entity havocbot_ast_target;
14
15 void(entity bot) havocbot_ast_reset_role;
16
17 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
18 void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
19 .entity assault_decreaser;
20
21 void havocbot_goalrating_ast_targets(float ratingscale)
22 {
23         entity ad, best, pl, wp, tod;
24         float radius, found, bestvalue, c;
25         vector p;
26
27         ad = findchain(classname, "func_assault_destructible");
28
29         for (; ad; ad = ad.chain)
30         {
31                 if (ad.target == "")
32                         continue;
33
34                 found = FALSE;
35                 for(tod = world; (tod = find(tod, targetname, ad.target)); )
36                 {
37                         if(tod.classname == "target_objective_decrease")
38                         {
39                                 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
40                                 {
41                                         dprint(etos(tod.enemy),"\n");
42                                         found = TRUE;
43                                         break;
44                                 }
45                         }
46                 }
47
48                 if(!found)
49                         continue;
50
51                 p = 0.5 * (ad.absmin + ad.absmax);
52         //      dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
53                 te_knightspike(p);
54                 te_lightning2(world, '0 0 0', p);
55
56                 // Find and rate waypoints around it
57                 found = FALSE;
58                 best = world;
59                 bestvalue = 99999999999;
60                 for(radius=0; radius<1000 && !found; radius+=500)
61                 {
62                         for(wp=findradius(p, radius); wp; wp=wp.chain)
63                         {
64                                 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
65                                 if(wp.classname=="waypoint")
66                                 if(checkpvs(wp.origin, ad))
67                                 {
68                                         found = TRUE;
69                                         if(wp.cnt<bestvalue)
70                                         {
71                                                 best = wp;
72                                                 bestvalue = wp.cnt;
73                                         }
74                                 }
75                         }
76                 }
77
78                 if(best)
79                 {
80                         dprint("waypoints around target were found\n");
81                 //      te_lightning2(world, '0 0 0', best.origin);
82                 //      te_knightspike(best.origin);
83
84                         navigation_routerating(best, ratingscale, 10000);
85                         best.cnt += 1;
86
87                         self.havocbot_attack_time = 0;
88
89                         if(checkpvs(self.view_ofs,ad))
90                         if(checkpvs(self.view_ofs,best))
91                         {
92                         //      dprint("increasing attack time for this target\n");
93                                 self.havocbot_attack_time = time + 2;
94                         }
95                 }
96         }
97 }
98
99 void havocbot_role_ast_offense()
100 {
101         if(self.deadflag != DEAD_NO)
102         {
103                 self.havocbot_attack_time = 0;
104                 havocbot_ast_reset_role(self);
105                 return;
106         }
107
108         // Set the role timeout if necessary
109         if (!self.havocbot_role_timeout)
110                 self.havocbot_role_timeout = time + 120;
111
112         if (time > self.havocbot_role_timeout)
113         {
114                 havocbot_ast_reset_role(self);
115                 return;
116         }
117
118         if(self.havocbot_attack_time>time)
119                 return;
120
121         if (self.bot_strategytime < time)
122         {
123                 navigation_goalrating_start();
124         ///     havocbot_goalrating_enemyplayers(20000, self.origin, 650);
125
126         //      if(!havocbot_goalrating_ast_generator_attack(20000))
127         //              havocbot_goalrating_ast_controlpoints_attack(20000);
128         //      havocbot_goalrating_ast_offenseitems(10000, self.origin, 10000);
129
130                 havocbot_goalrating_ast_targets(20000);
131         ///     havocbot_goalrating_items(10000, self.origin, 10000);
132                 navigation_goalrating_end();
133
134                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
135         }
136 };
137
138 void havocbot_role_ast_defense()
139 {
140         if(self.deadflag != DEAD_NO)
141         {
142                 self.havocbot_attack_time = 0;
143                 havocbot_ast_reset_role(self);
144                 return;
145         }
146
147         // Set the role timeout if necessary
148         if (!self.havocbot_role_timeout)
149                 self.havocbot_role_timeout = time + 120;
150
151         if (time > self.havocbot_role_timeout)
152         {
153                 havocbot_ast_reset_role(self);
154                 return;
155         }
156
157         if(self.havocbot_attack_time>time)
158                 return;
159
160         if (self.bot_strategytime < time)
161         {
162                 navigation_goalrating_start();
163                 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
164         //      if(!havocbot_goalrating_ast_generator_attack(20000))
165         //              havocbot_goalrating_ast_controlpoints_attack(20000);
166         //      havocbot_goalrating_ast_offenseitems(10000, self.origin, 10000);
167                 havocbot_goalrating_items(10000, self.origin, 10000);
168                 navigation_goalrating_end();
169
170                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
171         }
172 };
173
174 void havocbot_role_ast_setrole(entity bot, float role)
175 {
176         switch(role)
177         {
178                 case HAVOCBOT_AST_ROLE_DEFENSE:
179                         bot.havocbot_role = havocbot_role_ast_defense;
180                         bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
181                         bot.havocbot_role_timeout = 0;
182                         break;
183                 case HAVOCBOT_AST_ROLE_OFFENSE:
184                         bot.havocbot_role = havocbot_role_ast_offense;
185                         bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
186                         bot.havocbot_role_timeout = 0;
187                         break;
188         }
189 };
190
191 void havocbot_ast_reset_role(entity bot)
192 {
193         local entity head;
194         local float c;
195
196         if(self.deadflag != DEAD_NO)
197                 return;
198
199         bot.havocbot_ast_target = world;
200
201         if(bot.team==assault_attacker_team)
202                 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
203         else
204                 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
205 };
206
207 void havocbot_chooserole_ast()
208 {
209         havocbot_ast_reset_role(self);
210 };