]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/bot/bot_misc.qc
commit 1.2.1 game media
[divverent/nexuiz.git] / data / qcsrc / bot / bot_misc.qc
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.b_pants = 11;
59                 self.b_shirt = 0; 
60                 return "Vincent";
61         }
62         else if (r == 2)
63         {
64                 self.b_pants = 1;
65                 self.b_shirt = 3;
66                 return "Bishop";
67         }
68         else if (r == 3)
69         {       
70                 self.b_pants = 13;
71                 self.b_shirt = 2;
72                 return "Nomad";
73         }
74         else if (r == 4)
75         {
76                 self.b_pants = 7;
77                 self.b_shirt = 6;
78                 return "Hudson";
79         } 
80         else if (r == 5)
81         {
82                 self.b_pants = 12;
83                 self.b_shirt = 6;
84                 return "Lore";
85         }
86         else if (r == 6)
87         {
88                 self.b_pants = 4;
89                 self.b_shirt = 4;
90                 return "Servo";
91         }
92         else if (r == 7)
93         {
94                 self.b_pants = 2;
95                 self.b_shirt = 5;
96                 return "Gort";
97         } 
98         else if (r == 8)
99         {       
100                 self.b_pants = 10;
101                 self.b_shirt = 3;
102                 return "Kryten";
103         }
104         else if (r == 9)
105         {
106                 self.b_pants = 9;
107                 self.b_shirt = 4;
108                 return "Pimp Bot";
109         }
110         else if (r == 10)
111         {
112                 self.b_pants = 4;
113                 self.b_shirt = 7;
114                 return "Max";
115         }
116         else if (r == 11)
117         {
118                 self.b_pants = 3;
119                 self.b_shirt = 11;
120                 return "Marvin";
121         } 
122         else if (r == 12)
123         {
124                 self.b_pants = 13;
125                 self.b_shirt = 12;
126                 return "Erwin";
127         }
128         else if (r == 13)
129         {
130                 self.b_pants = 11;
131                 self.b_shirt = 2;
132                 return "FrikBot";
133         }
134         else if (r == 14)
135         {
136                 self.b_pants = 0;
137                 self.b_shirt = 2;
138                 return "Krosis";
139         }
140         else if (r == 15)
141         {
142                 self.b_pants = 8;
143                 self.b_shirt = 9;
144                 return "Gypsy";
145         }
146         else if (r == 16)
147         {
148                 self.b_pants = 5;
149                 self.b_shirt = 10;
150                 return "Hal";
151         }
152 };
153 string () PickARandomName =
154 {
155         if (bot_count > 16)
156                 return "player";
157
158         local float y, test;
159         local string h;
160         local entity t;
161         y = TRUE;
162         while(y)
163         {
164                 test = ceil(random() * 16);
165                 h = BotName(test);
166                 t = find(world, netname, h);
167                 if (t == world)
168                         y = FALSE;
169         }
170         return h;
171 };
172
173
174
175 // I didn't like the old code so this is very stripped down
176
177 entity b_originator;
178 float b_topic;
179 /* FBX Topics
180
181 b_originator == self
182  1 - sign on
183  2 - killed targ
184  3 - team message "friendly eyes"
185  4 - team message "on your back"
186  5 - team message "need back up"
187  6 - excuses
188  ----
189  7 - gameover
190  ----
191  8 - welcoming someone onto server
192  9 - ridicule lost frag (killed self?)
193  10 - ridicule lost frag (lava)
194  11 - lag
195 b_originator == targ
196
197  
198 */
199 void(float tpic) bot_start_topic =
200 {
201         if (random() < 0.2)
202         {
203                 b_topic = tpic;
204                 b_originator = self;
205         }
206         else
207                 b_topic = 0;
208 };
209
210 void() bot_chat =
211 {
212         local float r;
213         if (b_options & OPT_NOCHAT)
214                 return;
215         r = ceil (random() * 6);
216         
217         if (self.b_chattime > time)
218         {
219                 if (self.b_skill < 2)
220                         self.keys = self.button0 = self.button2 = 0;
221                 return;
222         }
223         else if (self.b_chattime)
224         {
225                 if (b_topic == 1)
226                 {
227                         if (b_originator == self)
228                         {
229                                 if (r == 1)
230                                 {
231                                         BotSay(": lo all\n");
232                                         bot_start_topic(8);
233                                 }
234                                 else if (r == 2)
235                                 {
236                                         BotSay(": hey everyone\n");
237                                         bot_start_topic(8);
238                                 }
239                                 else if (r == 3)
240                                 {
241                                         BotSay(": prepare to be fragged!\n");
242                                         bot_start_topic(0);
243                                 }
244                                 else if (r == 4)
245                                 {
246                                         BotSay(": boy this is laggy\n");
247                                         bot_start_topic(11);
248                                 }
249                                 else if (r == 5)
250                                 {
251                                         BotSay(": #mm getting some lag here\n");
252                                         bot_start_topic(11);
253                                 }
254                                 else
255                                 {
256                                         BotSay(": hi everyone\n");
257                                         bot_start_topic(8);
258                                 }
259                         }
260                 }
261                 else if (b_topic == 2)
262                 {
263                         if (b_originator == self)
264                         {
265                                 if (r == 1)
266                                         BotSay(": take that\n");
267                                 else if (r == 2)
268                                         BotSay(": yehaww!\n");
269                                 else if (r == 3)
270                                         BotSay(": wh00p\n");
271                                 else if (r == 4)
272                                         BotSay(": j00_sawk();\n");
273                                 else if (r == 5)
274                                         BotSay(": i rule\n");
275                                 else
276                                         BotSay(": eat that\n");
277                                 bot_start_topic(0);
278                         }
279                 }
280                 else if (b_topic == 3)
281                 {
282                         if (b_originator == self)
283                         {
284                                 if (r < 3)
285                                         BotSayTeam(": friendly eyes\n");
286                                 else
287                                         BotSayTeam(": team eyes\n");
288                                 bot_start_topic(0);
289                         }
290                 }
291                 else if (b_topic == 4)
292                 {
293                         if (b_originator == self)
294                         {
295                                 if (r < 3)
296                                         BotSayTeam(": on your back\n");
297                                 else
298                                         BotSayTeam(": I'm with you\n");
299                                 bot_start_topic(0);
300                         }
301                 }
302                 else if (b_topic == 5)
303                 {
304                         if (b_originator == self)
305                         {
306                                 if (r < 3)
307                                         BotSayTeam(": I need help\n");
308                                 else
309                                         BotSayTeam(": need backup\n");
310                                 bot_start_topic(0);
311                         }
312                 }
313                 else if (b_topic == 6)
314                 {
315                         if (b_originator == self)
316                         {
317                                 if (r == 1)
318                                 {
319                                         BotSay(": sun got in my eyes\n");
320                                         bot_start_topic(0);
321                                 }
322                                 else if (r == 2)
323                                 {
324                                         BotSay(": mouse needs cleaning\n");
325                                         bot_start_topic(0);
326                                 }
327                                 else if (r == 3)
328                                 {
329                                         BotSay(": i meant to do that\n");
330                                         bot_start_topic(0);
331                                 }
332                                 else if (r == 4)
333                                 {
334                                         BotSay(": lag\n");
335                                         bot_start_topic(11);
336                                 }
337                                 else if (r == 5)
338                                 {
339                                         BotSay(": killer lag\n");
340                                         bot_start_topic(11);
341                                 }
342                                 else
343                                 {
344                                         BotSay(": 100% lag\n");
345                                         bot_start_topic(11);
346                                 }
347                         }
348                 }
349                 else if (b_topic == 7)
350                 {
351                         if (r == 1)
352                                 BotSay(": gg\n");
353                         else if (r == 2)
354                                 BotSay(": gg all\n");
355                         else if (r == 3)
356                                 BotSay(": that was fun\n");
357                         else if (r == 4)
358                                 BotSay(": good game\n");
359                         else if (r == 5)
360                                 BotSay(": pah\n");
361                         else
362                                 BotSay(": hrm\n");
363                         bot_start_topic(0);
364                 }
365                 else if (b_topic == 8)
366                 {
367                         if (b_originator != self)
368                         {
369                                 if (r == 1)
370                                 {
371                                         BotSay(": heya\n");
372                                         bot_start_topic(0);
373                                 }
374                                 else if (r == 2)
375                                 {
376                                         BotSay(": welcome\n");
377                                         bot_start_topic(0);
378                                 }
379                                 else if (r == 3)
380                                 {
381                                         BotSayInit();
382                                         BotSay2(": hi ");
383                                         BotSay2(b_originator.netname);
384                                         BotSay2("\n");
385                                         bot_start_topic(0);
386                                 }
387                                 else if (r == 4)
388                                 {
389                                         BotSayInit();
390                                         BotSay2(": hey ");
391                                         BotSay2(b_originator.netname);
392                                         BotSay2("\n");
393                                         bot_start_topic(0);
394                                 }
395                                 else if (r == 5)
396                                 {
397                                         BotSay(": howdy\n");
398                                         bot_start_topic(0);
399                                 }
400                                 else
401                                 {
402                                         BotSay(": lo\n");
403                                         bot_start_topic(0);     
404                                 }
405                         }
406                 }
407
408                 else if (b_topic == 9)
409                 {
410                         if (b_originator != self)
411                         {
412                                 if (r == 1)
413                                         BotSay(": hah\n");
414                                 else if (r == 2)
415                                         BotSay(": heheh\n");
416                                 else if (r == 3)
417                                 {
418                                         BotSayInit();
419                                         BotSay2(": good work ");
420                                         BotSay2(b_originator.netname);
421                                         BotSay2("\n");
422                                 }
423                                 else if (r == 4)
424                                 {
425                                         BotSayInit();
426                                         BotSay2(": nice1 ");
427                                         BotSay2(b_originator.netname);
428                                         BotSay2("\n");
429                                 }
430                                 else if (r == 5)
431                                         BotSay(": lol\n");
432                                 else
433                                         BotSay(": :)\n");
434                                 b_topic = 6;
435                         }
436                 }
437                 else if (b_topic == 10)
438                 {
439                         if (b_originator != self)
440                         {
441                                 if (r == 1)
442                                         BotSay(": have a nice dip?\n");
443                                 else if (r == 2)
444                                         BotSay(": bah I hate levels with lava\n");
445                                 else if (r == 3)
446                                 {
447                                         BotSayInit();
448                                         BotSay2(": good job ");
449                                         BotSay2(b_originator.netname);
450                                         BotSay2("\n");
451                                 }
452                                 else if (r == 4)
453                                 {
454                                         BotSayInit();
455                                         BotSay2(": nice backflip ");
456                                         BotSay2(b_originator.netname);
457                                         BotSay2("\n");
458                                 }
459                                 else if (r == 5)
460                                         BotSay(": watch your step\n");
461                                 else
462                                         BotSay(": hehe\n");
463                                 b_topic = 6;
464                         }
465                 }
466
467                 else if (b_topic == 11)
468                 {
469                         if (b_originator != self)
470                         {
471                                 if (r == 1)
472                                 {
473                                         BotSayInit();
474                                         BotSay2(": yeah right ");
475                                         BotSay2(b_originator.netname);
476                                         BotSay2("\n");
477                                         bot_start_topic(0);
478                                 }
479                                 else if (r == 2)
480                                 {
481                                         BotSay(": ping\n");
482                                         bot_start_topic(0);
483                                 }
484                                 else if (r == 3)
485                                 {
486                                         BotSay(": shuddup, you're an lpb\n");
487                                         bot_start_topic(0);
488                                 }
489                                 else if (r == 4)
490                                 {
491                                         BotSay(": lag my eye\n");
492                                         bot_start_topic(0);
493                                 }
494                                 else if (r == 5)
495                                 {
496                                         BotSay(": yeah\n");
497                                         bot_start_topic(11);
498                                 }
499                                 else
500                                 {
501                                         BotSay(": totally\n");
502                                         bot_start_topic(11);
503                                 }
504                         }
505                 }
506                 self.b_chattime = 0;
507         }
508         else if (b_topic)
509         {
510                 if (random() < 0.5)
511                 {
512                         if (self == b_originator)
513                         {
514                                 if (b_topic <= 7)
515                                         self.b_chattime = time + 2;
516                         }
517                         else
518                         {
519                                 if (b_topic >= 7)
520                                         self.b_chattime = time + 2;
521                         }
522                 }
523         }
524 };
525
526 /*
527 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
528
529 Kick A Bot. 
530
531 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
532 */
533
534 void() KickABot =
535 {
536         local entity ty;
537         ty = find(world, classname, "player");
538         while (ty != world)
539         {
540                 if (!(ty.ishuman))
541                 {
542                         
543                         BotDisconnect(ty);
544                         ty.ishuman = TRUE;
545                         ty = world;
546                 }
547                 else
548                         ty = find(ty, classname, "player");
549         }
550
551 };
552
553
554 /*
555 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
556
557 Simplified origin checking. 
558
559 God, I wish I had inline
560
561 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
562 */
563
564 vector(entity ent) realorigin =
565 {
566 // even more simplified...
567         return (ent.absmin + ent.absmax) * 0.5;
568 };
569
570 /*
571 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
572
573 fisible
574
575 a version of visible that checks for corners
576 of the bounding boxes
577
578 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
579 */
580
581 float (entity targ) fisible =
582 {
583         local vector    spot1, org;
584         local float thruwater, pc1, pc2;
585         
586         org = realorigin(targ);
587         spot1 = self.origin + self.view_ofs;
588         
589         if (targ.solid == SOLID_BSP)
590         {
591                 traceline (spot1, org, TRUE, self);
592                 if (trace_ent == targ)
593                         return TRUE;
594                 else if (trace_fraction == 1)
595                         return TRUE;
596                 return FALSE;
597         }
598         else
599         {
600                 pc1 = pointcontents(org);
601                 pc2 = pointcontents(spot1);
602                 if (targ.classname == "player")
603                         thruwater = FALSE;
604                 else if (pc1 == CONTENT_LAVA)
605                         return FALSE;
606                 else    
607                         thruwater = TRUE;
608         }
609         
610         if (pc1 < -1) // targ's origin is in water or other liquid
611         {
612                 if (pc2 != pc1)
613                 {
614                         // look for their head
615                         traceline (spot1, org + targ.mins, TRUE, self);
616                         // cross the water check
617                         if (trace_inopen)
618                                 if (trace_inwater)
619                                         if (!thruwater)
620                                                 return FALSE;
621                         if (trace_ent == targ)
622                                 return TRUE;
623                         else if (trace_fraction == 1)
624                                 return TRUE;
625                         return FALSE;
626                 }
627         }
628         else
629         {
630                 if (pc2 != pc1)
631                 {
632                         traceline (spot1, org + targ.maxs, TRUE, self);
633                         if (trace_inopen)
634                                 if (trace_inwater)
635                                         if (!thruwater)
636                                                 return FALSE;
637                         if (trace_ent == targ)
638                                 return TRUE;
639                         else if (trace_fraction == 1)
640                                 return TRUE;
641                         return FALSE;
642                 }
643         }
644         traceline (spot1, org, TRUE, self);
645         if (trace_ent == targ)
646                 return TRUE;
647         else if (trace_fraction == 1)
648                 return TRUE;
649         traceline (spot1, org + targ.maxs, TRUE, self);
650         if (trace_ent == targ)
651                 return TRUE;
652         else if (trace_fraction == 1)
653                 return TRUE;
654         traceline (spot1, org + targ.mins, TRUE, self);
655         if (trace_ent == targ)
656                 return TRUE;
657         else if (trace_fraction == 1)
658                 return TRUE;
659         return FALSE;
660 };
661
662
663 /*
664 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
665
666 Wisible 
667
668 goes through movable brushes/entities, used
669 for waypoints
670
671 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
672 */
673
674 // this is used for waypoint stuff....
675 float (entity targ1, entity targ2) wisible =
676 {
677         local vector    spot1, spot2;
678         local entity ignore;
679
680         spot1 = targ1.origin;
681         spot2 = realorigin(targ2);
682         
683         ignore = self;
684         do
685         {
686                 traceline (spot1, spot2, TRUE, ignore);
687                 spot1 = realorigin(trace_ent);
688                 ignore = trace_ent;
689         } while ((trace_ent != world) && (trace_fraction != 1));
690         if (trace_endpos == spot2)
691                 return TRUE;
692         else 
693                 return FALSE;
694 };
695
696
697 /*
698 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
699
700 sisible
701
702 Now this is getting ridiculous. Simple visible,
703 used when we need just a simple traceline nothing else
704
705 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
706 */
707
708 float (entity targ) sisible =
709 {
710         traceline (self.origin, targ.origin, TRUE, self);
711         if (trace_ent == targ)
712                 return TRUE;
713         else if (trace_fraction == 1)
714                 return TRUE;
715 };
716 /*
717 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
718
719 angcomp
720
721 subtracts one angle from another
722
723 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
724 */
725
726 float (float y1, float y2) angcomp = 
727 {
728         y1 = frik_anglemod(y1);
729         y2 = frik_anglemod(y2);
730
731         local float answer;
732         answer = y1 - y2;
733         if (answer > 180)
734                 answer = (360 - answer) * -1;
735         else if (answer < -180)
736                 answer = answer + 360;
737         return answer;
738 };
739
740 /*
741 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
742
743 fov
744
745 is the entity in the bot's field of view
746
747 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
748 */
749 float (entity targ) fov =
750 {
751         local vector yawn;
752         local float g;
753         yawn = realorigin(targ);
754         yawn = (yawn + targ.view_ofs) - (self.origin + self.view_ofs);
755         yawn = normalize(yawn);
756         yawn = vectoangles(yawn);
757         g = angcomp(self.v_angle_x, yawn_x);
758         if (fabs(g) > 45)
759                 return FALSE;
760         g = angcomp(self.v_angle_y, yawn_y);
761         if (fabs(g) > 60)
762                 return FALSE;
763  
764         return TRUE;
765 };
766
767 /*
768 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
769
770 frik_anglemod
771
772 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
773 */
774 float(float v) frik_anglemod =
775 {
776         return v - floor(v/360) * 360;
777 };