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