]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/bot_misc.c
fix a couple warnings
[divverent/nexuiz.git] / qcsrc / gamec / bot_misc.c
1 /***********************************************
2 *                                              *
3 *              FrikBot Misc Code               *
4 *   "Because you can't name it anything else"  *
5 *                                              *
6 ***********************************************/
7
8 /*
9 This program is in the Public Domain. My crack legal
10 team would like to add:
11
12 RYAN "FRIKAC" SMITH IS PROVIDING THIS SOFTWARE "AS IS"
13 AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE
14 ACCURACY, CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR
15 FUNCTIONING OF THIS SOFTWARE AND/OR DOCUMENTATION. IN
16 NO EVENT WILL RYAN "FRIKAC" SMITH BE LIABLE FOR ANY
17 GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL,
18 EXEMPLARY, OR SPECIAL DAMAGES, EVEN IF RYAN "FRIKAC"
19 SMITH HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
20 DAMAGES, IRRESPECTIVE OF THE CAUSE OF SUCH DAMAGES.
21
22 You accept this software on the condition that you
23 indemnify and hold harmless Ryan "FrikaC" Smith from
24 any and all liability or damages to third parties,
25 including attorney fees, court costs, and other
26 related costs and expenses, arising out of your use
27 of this software irrespective of the cause of said
28 liability.
29
30 The export from the United States or the subsequent
31 reexport of this software is subject to compliance
32 with United States export control and munitions
33 control restrictions. You agree that in the event you
34 seek to export this software, you assume full
35 responsibility for obtaining all necessary export
36 licenses and approvals and for assuring compliance
37 with applicable reexport restrictions.
38
39 Any reproduction of this software must contain
40 this notice in its entirety.
41
42 */
43
44 /*
45 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
46
47 BotName
48
49 Sets bot's name and colors
50
51 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
52 */
53 string(float r) BotName =
54 {
55         self.b_num = r;
56         if (r == 1)
57         {
58                 self.playermodel = "models/player/visitant.zym";
59                 return "Visitant";
60         }
61         else if (r == 2)
62         {
63                 self.playermodel = "models/player/marine.zym";
64                 return "Marine";
65         }
66         else if (r == 3)
67         {
68                 self.playermodel = "models/player/specop.zym";
69                 return "Specop";
70         }
71         else if (r == 4)
72         {
73                 self.playermodel = "models/player/mulder.zym";
74                 return "Mulder";
75         }
76         else if (r == 5)
77         {
78                 self.playermodel = "models/player/fshock.zym";
79                 return "fShock";
80         }
81         else if (r == 6)
82         {
83                 self.playermodel = "models/player/lurk.zym";
84                 return "Lurk";
85         }
86         else if (r == 7)
87         {
88                 self.playermodel = "models/player/headhunter.zym";
89                 return "HeadHunter";
90         }
91         else
92         {
93                 self.playermodel = "models/player/robot.zym";
94                 return "Robot";
95         }
96
97 };
98 string () PickARandomName =
99 {
100         if (bot_count > 16)
101                 return "player";
102
103         local float y, test;
104         local string h;
105         local entity t;
106         y = TRUE;
107         while(y)
108         {
109                 test = ceil(random() * 16);
110                 h = BotName(test);
111                 t = find(world, netname, h);
112                 if (t == world)
113                         y = FALSE;
114         }
115         return h;
116 };
117
118
119
120 // I didn't like the old code so this is very stripped down
121
122 entity b_originator;
123 float b_topic;
124 /* FBX Topics
125
126 b_originator == self
127  1 - sign on
128  2 - killed targ
129  3 - team message "friendly eyes"
130  4 - team message "on your back"
131  5 - team message "need back up"
132  6 - excuses
133  ----
134  7 - gameover
135  ----
136  8 - welcoming someone onto server
137  9 - ridicule lost frag (killed self?)
138  10 - ridicule lost frag (lava)
139  11 - lag
140 b_originator == targ
141
142
143 */
144 void(float tpic) bot_start_topic =
145 {
146         if (random() < 0.2)
147         {
148                 b_topic = tpic;
149                 b_originator = self;
150         }
151         else
152                 b_topic = 0;
153 };
154
155 void() bot_chat =
156 {
157         local float r;
158         if (b_options & OPT_NOCHAT)
159                 return;
160         r = ceil (random() * 6);
161
162         if (self.b_chattime > time)
163         {
164                 if (self.b_skill < 2)
165                         self.keys = self.button0 = self.button2 = 0;
166                 return;
167         }
168         else if (self.b_chattime)
169         {
170                 if (b_topic == 1)
171                 {
172                         if (b_originator == self)
173                         {
174                                 if (r == 1)
175                                 {
176                                         BotSay(": lo all\n");
177                                         bot_start_topic(8);
178                                 }
179                                 else if (r == 2)
180                                 {
181                                         BotSay(": hey everyone\n");
182                                         bot_start_topic(8);
183                                 }
184                                 else if (r == 3)
185                                 {
186                                         BotSay(": prepare to be fragged!\n");
187                                         bot_start_topic(0);
188                                 }
189                                 else if (r == 4)
190                                 {
191                                         BotSay(": boy this is laggy\n");
192                                         bot_start_topic(11);
193                                 }
194                                 else if (r == 5)
195                                 {
196                                         BotSay(": #mm getting some lag here\n");
197                                         bot_start_topic(11);
198                                 }
199                                 else
200                                 {
201                                         BotSay(": hi everyone\n");
202                                         bot_start_topic(8);
203                                 }
204                         }
205                 }
206                 else if (b_topic == 2)
207                 {
208                         if (b_originator == self)
209                         {
210                                 if (r == 1)
211                                         BotSay(": take that\n");
212                                 else if (r == 2)
213                                         BotSay(": yehaww!\n");
214                                 else if (r == 3)
215                                         BotSay(": wh00p\n");
216                                 else if (r == 4)
217                                         BotSay(": j00_sawk();\n");
218                                 else if (r == 5)
219                                         BotSay(": i rule\n");
220                                 else
221                                         BotSay(": eat that\n");
222                                 bot_start_topic(0);
223                         }
224                 }
225                 else if (b_topic == 3)
226                 {
227                         if (b_originator == self)
228                         {
229                                 if (r < 3)
230                                         BotSayTeam(": friendly eyes\n");
231                                 else
232                                         BotSayTeam(": team eyes\n");
233                                 bot_start_topic(0);
234                         }
235                 }
236                 else if (b_topic == 4)
237                 {
238                         if (b_originator == self)
239                         {
240                                 if (r < 3)
241                                         BotSayTeam(": on your back\n");
242                                 else
243                                         BotSayTeam(": I'm with you\n");
244                                 bot_start_topic(0);
245                         }
246                 }
247                 else if (b_topic == 5)
248                 {
249                         if (b_originator == self)
250                         {
251                                 if (r < 3)
252                                         BotSayTeam(": I need help\n");
253                                 else
254                                         BotSayTeam(": need backup\n");
255                                 bot_start_topic(0);
256                         }
257                 }
258                 else if (b_topic == 6)
259                 {
260                         if (b_originator == self)
261                         {
262                                 if (r == 1)
263                                 {
264                                         BotSay(": sun got in my eyes\n");
265                                         bot_start_topic(0);
266                                 }
267                                 else if (r == 2)
268                                 {
269                                         BotSay(": mouse needs cleaning\n");
270                                         bot_start_topic(0);
271                                 }
272                                 else if (r == 3)
273                                 {
274                                         BotSay(": i meant to do that\n");
275                                         bot_start_topic(0);
276                                 }
277                                 else if (r == 4)
278                                 {
279                                         BotSay(": lag\n");
280                                         bot_start_topic(11);
281                                 }
282                                 else if (r == 5)
283                                 {
284                                         BotSay(": killer lag\n");
285                                         bot_start_topic(11);
286                                 }
287                                 else
288                                 {
289                                         BotSay(": 100% lag\n");
290                                         bot_start_topic(11);
291                                 }
292                         }
293                 }
294                 else if (b_topic == 7)
295                 {
296                         if (r == 1)
297                                 BotSay(": gg\n");
298                         else if (r == 2)
299                                 BotSay(": gg all\n");
300                         else if (r == 3)
301                                 BotSay(": that was fun\n");
302                         else if (r == 4)
303                                 BotSay(": good game\n");
304                         else if (r == 5)
305                                 BotSay(": pah\n");
306                         else
307                                 BotSay(": hrm\n");
308                         bot_start_topic(0);
309                 }
310                 else if (b_topic == 8)
311                 {
312                         if (b_originator != self)
313                         {
314                                 if (r == 1)
315                                 {
316                                         BotSay(": heya\n");
317                                         bot_start_topic(0);
318                                 }
319                                 else if (r == 2)
320                                 {
321                                         BotSay(": welcome\n");
322                                         bot_start_topic(0);
323                                 }
324                                 else if (r == 3)
325                                 {
326                                         BotSayInit();
327                                         BotSay2(": hi ");
328                                         BotSay2(b_originator.netname);
329                                         BotSay2("\n");
330                                         bot_start_topic(0);
331                                 }
332                                 else if (r == 4)
333                                 {
334                                         BotSayInit();
335                                         BotSay2(": hey ");
336                                         BotSay2(b_originator.netname);
337                                         BotSay2("\n");
338                                         bot_start_topic(0);
339                                 }
340                                 else if (r == 5)
341                                 {
342                                         BotSay(": howdy\n");
343                                         bot_start_topic(0);
344                                 }
345                                 else
346                                 {
347                                         BotSay(": lo\n");
348                                         bot_start_topic(0);
349                                 }
350                         }
351                 }
352
353                 else if (b_topic == 9)
354                 {
355                         if (b_originator != self)
356                         {
357                                 if (r == 1)
358                                         BotSay(": hah\n");
359                                 else if (r == 2)
360                                         BotSay(": heheh\n");
361                                 else if (r == 3)
362                                 {
363                                         BotSayInit();
364                                         BotSay2(": good work ");
365                                         BotSay2(b_originator.netname);
366                                         BotSay2("\n");
367                                 }
368                                 else if (r == 4)
369                                 {
370                                         BotSayInit();
371                                         BotSay2(": nice1 ");
372                                         BotSay2(b_originator.netname);
373                                         BotSay2("\n");
374                                 }
375                                 else if (r == 5)
376                                         BotSay(": lol\n");
377                                 else
378                                         BotSay(": :)\n");
379                                 b_topic = 6;
380                         }
381                 }
382                 else if (b_topic == 10)
383                 {
384                         if (b_originator != self)
385                         {
386                                 if (r == 1)
387                                         BotSay(": have a nice dip?\n");
388                                 else if (r == 2)
389                                         BotSay(": bah I hate levels with lava\n");
390                                 else if (r == 3)
391                                 {
392                                         BotSayInit();
393                                         BotSay2(": good job ");
394                                         BotSay2(b_originator.netname);
395                                         BotSay2("\n");
396                                 }
397                                 else if (r == 4)
398                                 {
399                                         BotSayInit();
400                                         BotSay2(": nice backflip ");
401                                         BotSay2(b_originator.netname);
402                                         BotSay2("\n");
403                                 }
404                                 else if (r == 5)
405                                         BotSay(": watch your step\n");
406                                 else
407                                         BotSay(": hehe\n");
408                                 b_topic = 6;
409                         }
410                 }
411
412                 else if (b_topic == 11)
413                 {
414                         if (b_originator != self)
415                         {
416                                 if (r == 1)
417                                 {
418                                         BotSayInit();
419                                         BotSay2(": yeah right ");
420                                         BotSay2(b_originator.netname);
421                                         BotSay2("\n");
422                                         bot_start_topic(0);
423                                 }
424                                 else if (r == 2)
425                                 {
426                                         BotSay(": ping\n");
427                                         bot_start_topic(0);
428                                 }
429                                 else if (r == 3)
430                                 {
431                                         BotSay(": shuddup, you're an lpb\n");
432                                         bot_start_topic(0);
433                                 }
434                                 else if (r == 4)
435                                 {
436                                         BotSay(": lag my eye\n");
437                                         bot_start_topic(0);
438                                 }
439                                 else if (r == 5)
440                                 {
441                                         BotSay(": yeah\n");
442                                         bot_start_topic(11);
443                                 }
444                                 else
445                                 {
446                                         BotSay(": totally\n");
447                                         bot_start_topic(11);
448                                 }
449                         }
450                 }
451                 self.b_chattime = 0;
452         }
453         else if (b_topic)
454         {
455                 if (random() < 0.5)
456                 {
457                         if (self == b_originator)
458                         {
459                                 if (b_topic <= 7)
460                                         self.b_chattime = time + 2;
461                         }
462                         else
463                         {
464                                 if (b_topic >= 7)
465                                         self.b_chattime = time + 2;
466                         }
467                 }
468         }
469 };
470
471 /*
472 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
473
474 Kick A Bot.
475
476 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
477 */
478
479 void() KickABot =
480 {
481         local entity ty;
482         ty = find(world, classname, "player");
483         while (ty != world)
484         {
485                 if (!(ty.ishuman))
486                 {
487
488                         BotDisconnect(ty);
489                         ty.ishuman = TRUE;
490                         ty = world;
491                 }
492                 else
493                         ty = find(ty, classname, "player");
494         }
495
496 };
497
498
499 /*
500 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
501
502 Simplified origin checking.
503
504 God, I wish I had inline
505
506 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
507 */
508
509 vector(entity ent) realorigin =
510 {
511 // even more simplified...
512         return (ent.absmin + ent.absmax) * 0.5;
513 };
514
515 /*
516 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
517
518 fisible
519
520 a version of visible that checks for corners
521 of the bounding boxes
522
523 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
524 */
525
526 float (entity targ) fisible =
527 {
528         local vector    spot1, org;
529         local float thruwater, pc1, pc2;
530
531         org = realorigin(targ);
532         spot1 = self.origin + self.view_ofs;
533
534         if (targ.solid == SOLID_BSP)
535         {
536                 traceline (spot1, org, TRUE, self);
537                 if (trace_ent == targ)
538                         return TRUE;
539                 else if (trace_fraction == 1)
540                         return TRUE;
541                 return FALSE;
542         }
543         else
544         {
545                 pc1 = pointcontents(org);
546                 pc2 = pointcontents(spot1);
547                 if (targ.classname == "player")
548                         thruwater = FALSE;
549                 else if (pc1 == CONTENT_LAVA)
550                         return FALSE;
551                 else
552                         thruwater = TRUE;
553         }
554
555         if (pc1 < -1) // targ's origin is in water or other liquid
556         {
557                 if (pc2 != pc1)
558                 {
559                         // look for their head
560                         traceline (spot1, org + targ.mins, TRUE, self);
561                         // cross the water check
562                         if (trace_inopen)
563                                 if (trace_inwater)
564                                         if (!thruwater)
565                                                 return FALSE;
566                         if (trace_ent == targ)
567                                 return TRUE;
568                         else if (trace_fraction == 1)
569                                 return TRUE;
570                         return FALSE;
571                 }
572         }
573         else
574         {
575                 if (pc2 != pc1)
576                 {
577                         traceline (spot1, org + targ.maxs, TRUE, self);
578                         if (trace_inopen)
579                                 if (trace_inwater)
580                                         if (!thruwater)
581                                                 return FALSE;
582                         if (trace_ent == targ)
583                                 return TRUE;
584                         else if (trace_fraction == 1)
585                                 return TRUE;
586                         return FALSE;
587                 }
588         }
589         traceline (spot1, org, TRUE, self);
590         if (trace_ent == targ)
591                 return TRUE;
592         else if (trace_fraction == 1)
593                 return TRUE;
594         traceline (spot1, org + targ.maxs, TRUE, self);
595         if (trace_ent == targ)
596                 return TRUE;
597         else if (trace_fraction == 1)
598                 return TRUE;
599         traceline (spot1, org + targ.mins, TRUE, self);
600         if (trace_ent == targ)
601                 return TRUE;
602         else if (trace_fraction == 1)
603                 return TRUE;
604         return FALSE;
605 };
606
607
608 /*
609 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
610
611 Wisible
612
613 goes through movable brushes/entities, used
614 for waypoints
615
616 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
617 */
618
619 // this is used for waypoint stuff....
620 float (entity targ1, entity targ2) wisible =
621 {
622         local vector    spot1, spot2;
623         local entity ignore;
624
625         spot1 = targ1.origin;
626         spot2 = realorigin(targ2);
627
628         ignore = self;
629         do
630         {
631                 traceline (spot1, spot2, TRUE, ignore);
632                 spot1 = realorigin(trace_ent);
633                 ignore = trace_ent;
634         } while ((trace_ent != world) && (trace_fraction != 1));
635         if (trace_endpos == spot2)
636                 return TRUE;
637         else
638                 return FALSE;
639 };
640
641
642 /*
643 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
644
645 sisible
646
647 Now this is getting ridiculous. Simple visible,
648 used when we need just a simple traceline nothing else
649
650 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
651 */
652
653 float (entity targ) sisible =
654 {
655         traceline (self.origin, targ.origin, TRUE, self);
656         if (trace_ent == targ)
657                 return TRUE;
658         else if (trace_fraction == 1)
659                 return TRUE;
660         return FALSE;
661 };
662 /*
663 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
664
665 angcomp
666
667 subtracts one angle from another
668
669 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
670 */
671
672 float (float y1, float y2) angcomp =
673 {
674         y1 = frik_anglemod(y1);
675         y2 = frik_anglemod(y2);
676
677         local float answer;
678         answer = y1 - y2;
679         if (answer > 180)
680                 answer = (360 - answer) * -1;
681         else if (answer < -180)
682                 answer = answer + 360;
683         return answer;
684 };
685
686 /*
687 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
688
689 fov
690
691 is the entity in the bot's field of view
692
693 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
694 */
695 float (entity targ) fov =
696 {
697         local vector yawn;
698         local float g;
699         yawn = realorigin(targ);
700         yawn = (yawn + targ.view_ofs) - (self.origin + self.view_ofs);
701         yawn = normalize(yawn);
702         yawn = vectoangles(yawn);
703         g = angcomp(self.v_angle_x, yawn_x);
704         if (fabs(g) > 45)
705                 return FALSE;
706         g = angcomp(self.v_angle_y, yawn_y);
707         if (fabs(g) > 60)
708                 return FALSE;
709
710         return TRUE;
711 };
712
713 /*
714 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
715
716 frik_anglemod
717
718 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
719 */
720 float(float v) frik_anglemod =
721 {
722         return v - floor(v/360) * 360;
723 };