2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Escort robot behavior.
24 #include <stdio.h> // for printf()
25 #include <stdlib.h> // for rand() and qsort()
26 #include <string.h> // for memset()
39 #include "editor/editor.h"
42 extern void multi_send_stolen_items();
43 void say_escort_goal(int goal_num);
44 void show_escort_menu(char *msg);
47 char *Escort_goal_text[MAX_ESCORT_GOALS] = {
72 // -- too much work -- "KAMIKAZE "
75 int Max_escort_length = 200;
76 int Escort_kill_object = -1;
77 ubyte Stolen_items[MAX_STOLEN_ITEMS];
78 int Stolen_item_index;
79 fix Escort_last_path_created = 0;
80 int Escort_goal_object = ESCORT_GOAL_UNSPECIFIED, Escort_special_goal = -1, Escort_goal_index = -1, Buddy_messages_suppressed = 0;
82 int Buddy_objnum, Buddy_allowed_to_talk;
83 int Looking_for_marker;
86 fix Last_buddy_message_time;
88 char guidebot_name[GUIDEBOT_NAME_LEN+1] = "GUIDE-BOT";
89 cvar_t real_guidebot_name = { "GuideBotName", "GUIDE-BOT", 1 };
91 void init_buddy_for_level(void)
95 Buddy_allowed_to_talk = 0;
97 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
98 Escort_special_goal = -1;
99 Escort_goal_index = -1;
100 Buddy_messages_suppressed = 0;
102 for (i=0; i<=Highest_object_index; i++)
103 if (Robot_info[Objects[i].id].companion)
105 if (i <= Highest_object_index)
108 Buddy_sorry_time = -F1_0;
110 Looking_for_marker = -1;
114 // -----------------------------------------------------------------------------
115 // See if segment from curseg through sidenum is reachable.
116 // Return true if it is reachable, else return false.
117 int segment_is_reachable(int curseg, int sidenum)
120 segment *segp = &Segments[curseg];
122 if (!IS_CHILD(segp->children[sidenum]))
125 wall_num = segp->sides[sidenum].wall_num;
127 // If no wall, then it is reachable
131 rval = ai_door_is_openable(NULL, segp, sidenum);
135 // -- MK, 10/17/95 --
136 // -- MK, 10/17/95 -- // Hmm, a closed wall. I think this mean not reachable.
137 // -- MK, 10/17/95 -- if (Walls[wall_num].type == WALL_CLOSED)
138 // -- MK, 10/17/95 -- return 0;
139 // -- MK, 10/17/95 --
140 // -- MK, 10/17/95 -- if (Walls[wall_num].type == WALL_DOOR) {
141 // -- MK, 10/17/95 -- if (Walls[wall_num].keys == KEY_NONE) {
142 // -- MK, 10/17/95 -- return 1; // @MK, 10/17/95: Be consistent with ai_door_is_openable
143 // -- MK, 10/17/95 -- // -- if (Walls[wall_num].flags & WALL_DOOR_LOCKED)
144 // -- MK, 10/17/95 -- // -- return 0;
145 // -- MK, 10/17/95 -- // -- else
146 // -- MK, 10/17/95 -- // -- return 1;
147 // -- MK, 10/17/95 -- } else if (Walls[wall_num].keys == KEY_BLUE)
148 // -- MK, 10/17/95 -- return (Players[Player_num].flags & PLAYER_FLAGS_BLUE_KEY);
149 // -- MK, 10/17/95 -- else if (Walls[wall_num].keys == KEY_GOLD)
150 // -- MK, 10/17/95 -- return (Players[Player_num].flags & PLAYER_FLAGS_GOLD_KEY);
151 // -- MK, 10/17/95 -- else if (Walls[wall_num].keys == KEY_RED)
152 // -- MK, 10/17/95 -- return (Players[Player_num].flags & PLAYER_FLAGS_RED_KEY);
153 // -- MK, 10/17/95 -- else
154 // -- MK, 10/17/95 -- Int3(); // Impossible! Doesn't have no key, but doesn't have any key!
155 // -- MK, 10/17/95 -- } else
156 // -- MK, 10/17/95 -- return 1;
157 // -- MK, 10/17/95 --
158 // -- MK, 10/17/95 -- Int3(); // Hmm, thought 'if' above had to return!
159 // -- MK, 10/17/95 -- return 0;
164 // -----------------------------------------------------------------------------
165 // Create a breadth-first list of segments reachable from current segment.
166 // max_segs is maximum number of segments to search. Use MAX_SEGMENTS to search all.
167 // On exit, *length <= max_segs.
171 // bfs_list: array of shorts, each reachable segment. Includes start segment.
172 // length: number of elements in bfs_list
173 void create_bfs_list(int start_seg, short bfs_list[], int *length, int max_segs)
176 sbyte visited[MAX_SEGMENTS];
178 for (i=0; i<MAX_SEGMENTS; i++)
184 bfs_list[head++] = start_seg;
185 visited[start_seg] = 1;
187 while ((head != tail) && (head < max_segs)) {
192 curseg = bfs_list[tail++];
193 cursegp = &Segments[curseg];
195 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++) {
198 connected_seg = cursegp->children[i];
200 if (IS_CHILD(connected_seg) && (visited[connected_seg] == 0)) {
201 if (segment_is_reachable(curseg, i)) {
202 bfs_list[head++] = connected_seg;
203 if (head >= max_segs)
205 visited[connected_seg] = 1;
206 Assert(head < MAX_SEGMENTS);
216 // -----------------------------------------------------------------------------
217 // Return true if ok for buddy to talk, else return false.
218 // Buddy is allowed to talk if the segment he is in does not contain a blastable wall that has not been blasted
219 // AND he has never yet, since being initialized for level, been allowed to talk.
220 int ok_for_buddy_to_talk(void)
225 if (Objects[Buddy_objnum].type != OBJ_ROBOT) {
226 Buddy_allowed_to_talk = 0;
230 if (Buddy_allowed_to_talk)
233 if ((Objects[Buddy_objnum].type == OBJ_ROBOT) && (Buddy_objnum <= Highest_object_index) && !Robot_info[Objects[Buddy_objnum].id].companion) {
234 for (i=0; i<=Highest_object_index; i++)
235 if (Robot_info[Objects[i].id].companion)
237 if (i > Highest_object_index)
243 segp = &Segments[Objects[Buddy_objnum].segnum];
245 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++) {
246 int wall_num = segp->sides[i].wall_num;
248 if (wall_num != -1) {
249 if ((Walls[wall_num].type == WALL_BLASTABLE) && !(Walls[wall_num].flags & WALL_BLASTED))
253 // Check one level deeper.
254 if (IS_CHILD(segp->children[i])) {
256 segment *csegp = &Segments[segp->children[i]];
258 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++) {
259 int wall2 = csegp->sides[j].wall_num;
262 if ((Walls[wall2].type == WALL_BLASTABLE) && !(Walls[wall2].flags & WALL_BLASTED))
269 Buddy_allowed_to_talk = 1;
273 // --------------------------------------------------------------------------------------------
274 void detect_escort_goal_accomplished(int index)
279 if (!Buddy_allowed_to_talk)
282 // If goal is to go away, how can it be achieved?
283 if (Escort_special_goal == ESCORT_GOAL_SCRAM)
286 // See if goal found was a key. Need to handle default goals differently.
287 // Note, no buddy_met_goal sound when blow up reactor or exit. Not great, but ok
288 // since for reactor, noisy, for exit, buddy is disappearing.
289 if ((Escort_special_goal == -1) && (Escort_goal_index == index)) {
294 if ((Escort_goal_index <= ESCORT_GOAL_RED_KEY) && (index >= 0)) {
295 if (Objects[index].type == OBJ_POWERUP) {
296 if (Objects[index].id == POW_KEY_BLUE) {
297 if (Escort_goal_index == ESCORT_GOAL_BLUE_KEY) {
301 } else if (Objects[index].id == POW_KEY_GOLD) {
302 if (Escort_goal_index == ESCORT_GOAL_GOLD_KEY) {
306 } else if (Objects[index].id == POW_KEY_RED) {
307 if (Escort_goal_index == ESCORT_GOAL_RED_KEY) {
314 if (Escort_special_goal != -1)
316 if (Escort_special_goal == ESCORT_GOAL_ENERGYCEN) {
320 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++)
321 if (Segments[index].children[i] == Escort_goal_index) {
325 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
326 if (Segments[i].children[j] == Escort_goal_index) {
332 } else if ((Objects[index].type == OBJ_POWERUP) && (Escort_special_goal == ESCORT_GOAL_POWERUP))
333 detected = 1; // Any type of powerup picked up will do.
334 else if ((Objects[index].type == Objects[Escort_goal_index].type) && (Objects[index].id == Objects[Escort_goal_index].id)) {
335 // Note: This will help a little bit in making the buddy believe a goal is satisfied. Won't work for a general goal like "find any powerup"
336 // because of the insistence of both type and id matching.
342 if (detected && ok_for_buddy_to_talk()) {
343 digi_play_sample_once(SOUND_BUDDY_MET_GOAL, F1_0);
344 Escort_goal_index = -1;
345 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
346 Escort_special_goal = -1;
347 Looking_for_marker = -1;
352 void change_guidebot_name()
355 char text[GUIDEBOT_NAME_LEN+1]="";
358 strcpy(text,guidebot_name);
360 m.type=NM_TYPE_INPUT; m.text_len = GUIDEBOT_NAME_LEN; m.text = text;
361 item = newmenu_do( NULL, "Enter Guide-bot name:", 1, &m, NULL );
364 strcpy(guidebot_name,text);
365 cvar_set_cvar(&real_guidebot_name, text);
369 // -----------------------------------------------------------------------------
370 void buddy_message(char * format, ... )
372 if (Buddy_messages_suppressed)
375 if (Game_mode & GM_MULTI)
378 if ((Last_buddy_message_time + F1_0 < GameTime) || (Last_buddy_message_time > GameTime)) {
379 if (ok_for_buddy_to_talk()) {
380 char gb_str[16], new_format[128];
384 va_start(args, format );
385 vsprintf(new_format, format, args);
389 gb_str[1] = BM_XRGB(28, 0, 0);
390 strcpy(&gb_str[2], guidebot_name);
391 t = (int)strlen(gb_str);
394 gb_str[t+2] = BM_XRGB(0, 31, 0);
397 HUD_init_message("%s %s", gb_str, new_format);
399 Last_buddy_message_time = GameTime;
405 // -----------------------------------------------------------------------------
406 void thief_message(char * format, ... )
409 char gb_str[16], new_format[128];
412 va_start(args, format );
413 vsprintf(new_format, format, args);
417 gb_str[1] = BM_XRGB(28, 0, 0);
418 strcpy(&gb_str[2], "THIEF:");
420 gb_str[9] = BM_XRGB(0, 31, 0);
423 HUD_init_message("%s %s", gb_str, new_format);
427 // -----------------------------------------------------------------------------
428 // Return true if marker #id has been placed.
429 int marker_exists_in_mine(int id)
433 for (i=0; i<=Highest_object_index; i++)
434 if (Objects[i].type == OBJ_MARKER)
435 if (Objects[i].id == id)
441 // -----------------------------------------------------------------------------
442 void set_escort_special_goal(int special_key)
446 Buddy_messages_suppressed = 0;
448 if (!Buddy_allowed_to_talk) {
449 ok_for_buddy_to_talk();
450 if (!Buddy_allowed_to_talk) {
453 for (i=0; i<=Highest_object_index; i++)
454 if ((Objects[i].type == OBJ_ROBOT) && Robot_info[Objects[i].id].companion) {
455 HUD_init_message("%s has not been released.",guidebot_name);
458 if (i == Highest_object_index+1)
459 HUD_init_message("No Guide-Bot in mine.");
465 special_key = special_key & (~KEY_SHIFTED);
467 marker_key = special_key;
470 switch(special_key) {
472 marker_key = KEY_1+4;
475 marker_key = KEY_1+5;
478 marker_key = KEY_1+6;
481 marker_key = KEY_1+7;
484 marker_key = KEY_1+8;
487 marker_key = KEY_1+9;
492 if (Last_buddy_key == special_key)
494 if ((Looking_for_marker == -1) && (special_key != KEY_0)) {
495 if (marker_exists_in_mine(marker_key - KEY_1))
496 Looking_for_marker = marker_key - KEY_1;
498 Last_buddy_message_time = 0; // Force this message to get through.
499 buddy_message("Marker %i not placed.", marker_key - KEY_1 + 1);
500 Looking_for_marker = -1;
503 Looking_for_marker = -1;
507 Last_buddy_key = special_key;
509 if (special_key == KEY_0)
510 Looking_for_marker = -1;
512 if ( Looking_for_marker != -1 ) {
513 Escort_special_goal = ESCORT_GOAL_MARKER1 + marker_key - KEY_1;
515 switch (special_key) {
516 case KEY_1: Escort_special_goal = ESCORT_GOAL_ENERGY; break;
517 case KEY_2: Escort_special_goal = ESCORT_GOAL_ENERGYCEN; break;
518 case KEY_3: Escort_special_goal = ESCORT_GOAL_SHIELD; break;
519 case KEY_4: Escort_special_goal = ESCORT_GOAL_POWERUP; break;
520 case KEY_5: Escort_special_goal = ESCORT_GOAL_ROBOT; break;
521 case KEY_6: Escort_special_goal = ESCORT_GOAL_HOSTAGE; break;
522 case KEY_7: Escort_special_goal = ESCORT_GOAL_SCRAM; break;
523 case KEY_8: Escort_special_goal = ESCORT_GOAL_PLAYER_SPEW; break;
524 case KEY_9: Escort_special_goal = ESCORT_GOAL_EXIT; break;
525 case KEY_0: Escort_special_goal = -1; break;
527 Int3(); // Oops, called with illegal key value.
531 Last_buddy_message_time = GameTime - 2*F1_0; // Allow next message to come through.
533 say_escort_goal(Escort_special_goal);
534 // -- Escort_goal_object = escort_set_goal_object();
536 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
539 // -- old, pre-bfs, way -- // -----------------------------------------------------------------------------
540 // -- old, pre-bfs, way -- // Return object of interest.
541 // -- old, pre-bfs, way -- int exists_in_mine(int objtype, int objid)
542 // -- old, pre-bfs, way -- {
543 // -- old, pre-bfs, way -- int i;
544 // -- old, pre-bfs, way --
545 // -- old, pre-bfs, way -- mprintf((0, "exists_in_mine, type == %i, id == %i\n", objtype, objid));
546 // -- old, pre-bfs, way --
547 // -- old, pre-bfs, way -- if (objtype == FUELCEN_CHECK) {
548 // -- old, pre-bfs, way -- for (i=0; i<=Highest_segment_index; i++)
549 // -- old, pre-bfs, way -- if (Segments[i].special == SEGMENT_IS_FUELCEN)
550 // -- old, pre-bfs, way -- return i;
551 // -- old, pre-bfs, way -- } else {
552 // -- old, pre-bfs, way -- for (i=0; i<=Highest_object_index; i++) {
553 // -- old, pre-bfs, way -- if (Objects[i].type == objtype) {
554 // -- old, pre-bfs, way -- // Don't find escort robots if looking for robot!
555 // -- old, pre-bfs, way -- if ((Objects[i].type == OBJ_ROBOT) && (Robot_info[Objects[i].id].companion))
556 // -- old, pre-bfs, way -- continue;
557 // -- old, pre-bfs, way --
558 // -- old, pre-bfs, way -- if (objid == -1) {
559 // -- old, pre-bfs, way -- if ((objtype == OBJ_POWERUP) && (Objects[i].id != POW_KEY_BLUE) && (Objects[i].id != POW_KEY_GOLD) && (Objects[i].id != POW_KEY_RED))
560 // -- old, pre-bfs, way -- return i;
561 // -- old, pre-bfs, way -- else
562 // -- old, pre-bfs, way -- return i;
563 // -- old, pre-bfs, way -- } else if (Objects[i].id == objid)
564 // -- old, pre-bfs, way -- return i;
565 // -- old, pre-bfs, way -- }
566 // -- old, pre-bfs, way -- }
567 // -- old, pre-bfs, way -- }
568 // -- old, pre-bfs, way --
569 // -- old, pre-bfs, way -- return -1;
570 // -- old, pre-bfs, way --
571 // -- old, pre-bfs, way -- }
573 // -----------------------------------------------------------------------------
574 // Return id of boss.
575 int get_boss_id(void)
579 for (i=0; i<=Highest_object_index; i++)
580 if (Objects[i].type == OBJ_ROBOT)
581 if (Robot_info[Objects[i].id].boss_flag)
582 return Objects[i].id;
587 // -----------------------------------------------------------------------------
588 // Return object index if object of objtype, objid exists in mine, else return -1
589 // "special" is used to find objects spewed by player which is hacked into flags field of powerup.
590 int exists_in_mine_2(int segnum, int objtype, int objid, int special)
592 if (Segments[segnum].objects != -1) {
593 int objnum = Segments[segnum].objects;
595 while (objnum != -1) {
596 object *curobjp = &Objects[objnum];
598 if (special == ESCORT_GOAL_PLAYER_SPEW) {
599 if (curobjp->flags & OF_PLAYER_DROPPED)
603 if (curobjp->type == objtype) {
604 // Don't find escort robots if looking for robot!
605 if ((curobjp->type == OBJ_ROBOT) && (Robot_info[curobjp->id].companion))
607 else if (objid == -1) {
608 if ((objtype == OBJ_POWERUP) && (curobjp->id != POW_KEY_BLUE) && (curobjp->id != POW_KEY_GOLD) && (curobjp->id != POW_KEY_RED))
612 } else if (curobjp->id == objid)
616 if (objtype == OBJ_POWERUP)
617 if (curobjp->contains_count)
618 if (curobjp->contains_type == OBJ_POWERUP)
619 if (curobjp->contains_id == objid)
622 objnum = curobjp->next;
629 // -----------------------------------------------------------------------------
630 // Return nearest object of interest.
631 // If special == ESCORT_GOAL_PLAYER_SPEW, then looking for any object spewed by player.
632 // -1 means object does not exist in mine.
633 // -2 means object does exist in mine, but buddy-bot can't reach it (eg, behind triggered wall)
634 int exists_in_mine(int start_seg, int objtype, int objid, int special)
636 int segindex, segnum;
637 short bfs_list[MAX_SEGMENTS];
640 // mprintf((0, "exists_in_mine, type == %i, id == %i\n", objtype, objid));
642 create_bfs_list(start_seg, bfs_list, &length, MAX_SEGMENTS);
644 if (objtype == FUELCEN_CHECK) {
645 for (segindex=0; segindex<length; segindex++) {
646 segnum = bfs_list[segindex];
647 if (Segment2s[segnum].special == SEGMENT_IS_FUELCEN)
651 for (segindex=0; segindex<length; segindex++) {
654 segnum = bfs_list[segindex];
656 objnum = exists_in_mine_2(segnum, objtype, objid, special);
663 // Couldn't find what we're looking for by looking at connectivity.
664 // See if it's in the mine. It could be hidden behind a trigger or switch
665 // which the buddybot doesn't understand.
666 if (objtype == FUELCEN_CHECK) {
667 for (segnum=0; segnum<=Highest_segment_index; segnum++)
668 if (Segment2s[segnum].special == SEGMENT_IS_FUELCEN)
671 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
674 objnum = exists_in_mine_2(segnum, objtype, objid, special);
683 // -----------------------------------------------------------------------------
684 // Return true if it happened, else return false.
685 int find_exit_segment(void)
689 // ---------- Find exit doors ----------
690 for (i=0; i<=Highest_segment_index; i++)
691 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
692 if (Segments[i].children[j] == -2) {
699 #define BUDDY_MARKER_TEXT_LEN 25
701 // -----------------------------------------------------------------------------
702 void say_escort_goal(int goal_num)
708 case ESCORT_GOAL_BLUE_KEY: buddy_message("Finding BLUE KEY"); break;
709 case ESCORT_GOAL_GOLD_KEY: buddy_message("Finding YELLOW KEY"); break;
710 case ESCORT_GOAL_RED_KEY: buddy_message("Finding RED KEY"); break;
711 case ESCORT_GOAL_CONTROLCEN: buddy_message("Finding REACTOR"); break;
712 case ESCORT_GOAL_EXIT: buddy_message("Finding EXIT"); break;
713 case ESCORT_GOAL_ENERGY: buddy_message("Finding ENERGY"); break;
714 case ESCORT_GOAL_ENERGYCEN: buddy_message("Finding ENERGY CENTER"); break;
715 case ESCORT_GOAL_SHIELD: buddy_message("Finding a SHIELD"); break;
716 case ESCORT_GOAL_POWERUP: buddy_message("Finding a POWERUP"); break;
717 case ESCORT_GOAL_ROBOT: buddy_message("Finding a ROBOT"); break;
718 case ESCORT_GOAL_HOSTAGE: buddy_message("Finding a HOSTAGE"); break;
719 case ESCORT_GOAL_SCRAM: buddy_message("Staying away..."); break;
720 case ESCORT_GOAL_BOSS: buddy_message("Finding BOSS robot"); break;
721 case ESCORT_GOAL_PLAYER_SPEW: buddy_message("Finding your powerups"); break;
722 case ESCORT_GOAL_MARKER1:
723 case ESCORT_GOAL_MARKER2:
724 case ESCORT_GOAL_MARKER3:
725 case ESCORT_GOAL_MARKER4:
726 case ESCORT_GOAL_MARKER5:
727 case ESCORT_GOAL_MARKER6:
728 case ESCORT_GOAL_MARKER7:
729 case ESCORT_GOAL_MARKER8:
730 case ESCORT_GOAL_MARKER9:
731 { char marker_text[BUDDY_MARKER_TEXT_LEN];
732 strncpy(marker_text, MarkerMessage[goal_num-ESCORT_GOAL_MARKER1], BUDDY_MARKER_TEXT_LEN-1);
733 marker_text[BUDDY_MARKER_TEXT_LEN-1] = 0;
734 buddy_message("Finding marker %i: '%s'", goal_num-ESCORT_GOAL_MARKER1+1, marker_text);
740 // -----------------------------------------------------------------------------
741 void escort_create_path_to_goal(object *objp)
744 int objnum = OBJECT_NUMBER(objp);
745 ai_static *aip = &objp->ctype.ai_info;
746 ai_local *ailp = &Ai_local_info[objnum];
748 if (Escort_special_goal != -1)
749 Escort_goal_object = Escort_special_goal;
751 Escort_kill_object = -1;
753 if (Looking_for_marker != -1) {
755 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_MARKER, Escort_goal_object-ESCORT_GOAL_MARKER1, -1);
756 if (Escort_goal_index > -1)
757 goal_seg = Objects[Escort_goal_index].segnum;
759 switch (Escort_goal_object) {
760 case ESCORT_GOAL_BLUE_KEY:
761 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_KEY_BLUE, -1);
762 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
764 case ESCORT_GOAL_GOLD_KEY:
765 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_KEY_GOLD, -1);
766 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
768 case ESCORT_GOAL_RED_KEY:
769 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_KEY_RED, -1);
770 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
772 case ESCORT_GOAL_CONTROLCEN:
773 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_CNTRLCEN, -1, -1);
774 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
776 case ESCORT_GOAL_EXIT:
777 case ESCORT_GOAL_EXIT2:
778 goal_seg = find_exit_segment();
779 Escort_goal_index = goal_seg;
781 case ESCORT_GOAL_ENERGY:
782 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_ENERGY, -1);
783 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
785 case ESCORT_GOAL_ENERGYCEN:
786 goal_seg = exists_in_mine(objp->segnum, FUELCEN_CHECK, -1, -1);
787 Escort_goal_index = goal_seg;
789 case ESCORT_GOAL_SHIELD:
790 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_SHIELD_BOOST, -1);
791 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
793 case ESCORT_GOAL_POWERUP:
794 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, -1, -1);
795 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
797 case ESCORT_GOAL_ROBOT:
798 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_ROBOT, -1, -1);
799 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
801 case ESCORT_GOAL_HOSTAGE:
802 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_HOSTAGE, -1, -1);
803 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
805 case ESCORT_GOAL_PLAYER_SPEW:
806 Escort_goal_index = exists_in_mine(objp->segnum, -1, -1, ESCORT_GOAL_PLAYER_SPEW);
807 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
809 case ESCORT_GOAL_SCRAM:
810 goal_seg = -3; // Kinda a hack.
811 Escort_goal_index = goal_seg;
813 case ESCORT_GOAL_BOSS: {
816 boss_id = get_boss_id();
817 Assert(boss_id != -1);
818 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_ROBOT, boss_id, -1);
819 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
823 Int3(); // Oops, Illegal value in Escort_goal_object.
829 // -- mprintf((0, "Creating path from escort to goal #%i in segment #%i.\n", Escort_goal_object, goal_seg));
830 if ((Escort_goal_index < 0) && (Escort_goal_index != -3)) { // I apologize for this statement -- MK, 09/22/95
831 if (Escort_goal_index == -1) {
832 Last_buddy_message_time = 0; // Force this message to get through.
833 buddy_message("No %s in mine.", Escort_goal_text[Escort_goal_object-1]);
834 Looking_for_marker = -1;
835 } else if (Escort_goal_index == -2) {
836 Last_buddy_message_time = 0; // Force this message to get through.
837 buddy_message("Can't reach %s.", Escort_goal_text[Escort_goal_object-1]);
838 Looking_for_marker = -1;
842 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
843 Escort_special_goal = -1;
845 if (goal_seg == -3) {
846 create_n_segment_path(objp, 16 + d_rand() * 16, -1);
847 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
849 create_path_to_segment(objp, goal_seg, Max_escort_length, 1); // MK!: Last parm (safety_flag) used to be 1!!
850 if (aip->path_length > 3)
851 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
852 if ((aip->path_length > 0) && (Point_segs[aip->hide_index + aip->path_length - 1].segnum != goal_seg)) {
854 Last_buddy_message_time = 0; // Force this message to get through.
855 buddy_message("Can't reach %s.", Escort_goal_text[Escort_goal_object-1]);
856 Looking_for_marker = -1;
857 Escort_goal_object = ESCORT_GOAL_SCRAM;
858 dist_to_player = find_connected_distance(&objp->pos, objp->segnum, &Believed_player_pos, Believed_player_seg, 100, WID_FLY_FLAG);
859 if (dist_to_player > MIN_ESCORT_DISTANCE)
860 create_path_to_player(objp, Max_escort_length, 1); // MK!: Last parm used to be 1!
862 create_n_segment_path(objp, 8 + d_rand() * 8, -1);
863 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
868 ailp->mode = AIM_GOTO_OBJECT;
870 say_escort_goal(Escort_goal_object);
875 // -----------------------------------------------------------------------------
876 // Escort robot chooses goal object based on player's keys, location.
877 // Returns goal object.
878 int escort_set_goal_object(void)
880 if (Escort_special_goal != -1)
881 return ESCORT_GOAL_UNSPECIFIED;
882 else if (!(ConsoleObject->flags & PLAYER_FLAGS_BLUE_KEY) && (exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_BLUE, -1) != -1))
883 return ESCORT_GOAL_BLUE_KEY;
884 else if (!(ConsoleObject->flags & PLAYER_FLAGS_GOLD_KEY) && (exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_GOLD, -1) != -1))
885 return ESCORT_GOAL_GOLD_KEY;
886 else if (!(ConsoleObject->flags & PLAYER_FLAGS_RED_KEY) && (exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_RED, -1) != -1))
887 return ESCORT_GOAL_RED_KEY;
888 else if (Control_center_destroyed == 0) {
889 if (Num_boss_teleport_segs)
890 return ESCORT_GOAL_BOSS;
892 return ESCORT_GOAL_CONTROLCEN;
894 return ESCORT_GOAL_EXIT;
898 #define MAX_ESCORT_TIME_AWAY (F1_0*4)
900 fix Buddy_last_seen_player = 0, Buddy_last_player_path_created;
902 // -----------------------------------------------------------------------------
903 int time_to_visit_player(object *objp, ai_local *ailp, ai_static *aip)
905 // Note: This one has highest priority because, even if already going towards player,
906 // might be necessary to create a new path, as player can move.
907 if (GameTime - Buddy_last_seen_player > MAX_ESCORT_TIME_AWAY)
908 if (GameTime - Buddy_last_player_path_created > F1_0)
911 if (ailp->mode == AIM_GOTO_PLAYER)
914 if (objp->segnum == ConsoleObject->segnum)
917 if (aip->cur_path_index < aip->path_length/2)
924 int Buddy_dude_cheat;
925 fix Last_come_back_message_time = 0;
927 fix Buddy_last_missile_time;
929 // -----------------------------------------------------------------------------
930 void bash_buddy_weapon_info(int weapon_objnum)
932 object *objp = &Objects[weapon_objnum];
934 objp->ctype.laser_info.parent_num = OBJECT_NUMBER(ConsoleObject);
935 objp->ctype.laser_info.parent_type = OBJ_PLAYER;
936 objp->ctype.laser_info.parent_signature = ConsoleObject->signature;
939 // -----------------------------------------------------------------------------
940 int maybe_buddy_fire_mega(int objnum)
942 object *objp = &Objects[objnum];
943 object *buddy_objp = &Objects[Buddy_objnum];
945 vms_vector vec_to_robot;
948 vm_vec_sub(&vec_to_robot, &buddy_objp->pos, &objp->pos);
949 dist = vm_vec_normalize_quick(&vec_to_robot);
954 dot = vm_vec_dot(&vec_to_robot, &buddy_objp->orient.fvec);
959 if (!object_to_object_visibility(buddy_objp, objp, FQ_TRANSWALL))
962 if (Weapon_info[MEGA_ID].render_type == 0) {
963 con_printf(CON_VERBOSE, "Buddy can't fire mega (shareware)\n");
964 buddy_message("CLICK!");
968 mprintf((0, "Buddy firing mega in frame %i\n", FrameCount));
970 buddy_message("GAHOOGA!");
972 weapon_objnum = Laser_create_new_easy( &buddy_objp->orient.fvec, &buddy_objp->pos, objnum, MEGA_ID, 1);
974 if (weapon_objnum != -1)
975 bash_buddy_weapon_info(weapon_objnum);
980 //-----------------------------------------------------------------------------
981 int maybe_buddy_fire_smart(int objnum)
983 object *objp = &Objects[objnum];
984 object *buddy_objp = &Objects[Buddy_objnum];
988 dist = vm_vec_dist_quick(&buddy_objp->pos, &objp->pos);
993 if (!object_to_object_visibility(buddy_objp, objp, FQ_TRANSWALL))
996 mprintf((0, "Buddy firing smart missile in frame %i\n", FrameCount));
998 buddy_message("WHAMMO!");
1000 weapon_objnum = Laser_create_new_easy( &buddy_objp->orient.fvec, &buddy_objp->pos, objnum, SMART_ID, 1);
1002 if (weapon_objnum != -1)
1003 bash_buddy_weapon_info(weapon_objnum);
1008 // -----------------------------------------------------------------------------
1009 void do_buddy_dude_stuff(void)
1013 if (!ok_for_buddy_to_talk())
1016 if (Buddy_last_missile_time > GameTime)
1017 Buddy_last_missile_time = 0;
1019 if (Buddy_last_missile_time + F1_0*2 < GameTime) {
1020 // See if a robot potentially in view cone
1021 for (i=0; i<=Highest_object_index; i++)
1022 if ((Objects[i].type == OBJ_ROBOT) && !Robot_info[Objects[i].id].companion)
1023 if (maybe_buddy_fire_mega(i)) {
1024 Buddy_last_missile_time = GameTime;
1028 // See if a robot near enough that buddy should fire smart missile
1029 for (i=0; i<=Highest_object_index; i++)
1030 if ((Objects[i].type == OBJ_ROBOT) && !Robot_info[Objects[i].id].companion)
1031 if (maybe_buddy_fire_smart(i)) {
1032 Buddy_last_missile_time = GameTime;
1039 // -----------------------------------------------------------------------------
1040 // Called every frame (or something).
1041 void do_escort_frame(object *objp, fix dist_to_player, int player_visibility)
1043 int objnum = OBJECT_NUMBER(objp);
1044 ai_static *aip = &objp->ctype.ai_info;
1045 ai_local *ailp = &Ai_local_info[objnum];
1047 Buddy_objnum = OBJECT_NUMBER(objp);
1049 if (player_visibility) {
1050 Buddy_last_seen_player = GameTime;
1051 if (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON) // DAMN! MK, stupid bug, fixed 12/08/95, changed PLAYER_FLAGS_HEADLIGHT to PLAYER_FLAGS_HEADLIGHT_ON
1052 if (f2i(Players[Player_num].energy) < 40)
1053 if ((f2i(Players[Player_num].energy)/2) & 2)
1054 if (!Player_is_dead)
1055 buddy_message("Hey, your headlight's on!");
1059 if (Buddy_dude_cheat)
1060 do_buddy_dude_stuff();
1062 if (Buddy_sorry_time + F1_0 > GameTime) {
1063 Last_buddy_message_time = 0; // Force this message to get through.
1064 if (Buddy_sorry_time < GameTime + F1_0*2)
1065 buddy_message("Oops, sorry 'bout that...");
1066 Buddy_sorry_time = -F1_0*2;
1069 // If buddy not allowed to talk, then he is locked in his room. Make him mostly do nothing unless you're nearby.
1070 if (!Buddy_allowed_to_talk)
1071 if (dist_to_player > F1_0*100)
1072 aip->SKIP_AI_COUNT = (F1_0/4)/FrameTime;
1074 // -- mprintf((0, "%10s: Dist to player = %7.3f, segnum = %4i\n", mode_text[ailp->mode], f2fl(dist_to_player), objp->segnum));
1076 // AIM_WANDER has been co-opted for buddy behavior (didn't want to modify aistruct.h)
1077 // It means the object has been told to get lost and has come to the end of its path.
1078 // If the player is now visible, then create a path.
1079 if (ailp->mode == AIM_WANDER)
1080 if (player_visibility) {
1081 // -- mprintf((0, "Buddy: Going from wander to path following!\n"));
1082 create_n_segment_path(objp, 16 + d_rand() * 16, -1);
1083 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1086 if (Escort_special_goal == ESCORT_GOAL_SCRAM) {
1087 if (player_visibility)
1088 if (Escort_last_path_created + F1_0*3 < GameTime) {
1089 mprintf((0, "Frame %i: Buddy creating new scram path.\n", FrameCount));
1090 create_n_segment_path(objp, 10 + d_rand() * 16, ConsoleObject->segnum);
1091 Escort_last_path_created = GameTime;
1095 // -- mprintf((0, "Buddy: Seg = %3i, dist = %7.3f\n", objp->segnum, f2fl(dist_to_player)));
1099 // Force checking for new goal every 5 seconds, and create new path, if necessary.
1100 if (((Escort_special_goal != ESCORT_GOAL_SCRAM) && ((Escort_last_path_created + F1_0*5) < GameTime)) ||
1101 ((Escort_special_goal == ESCORT_GOAL_SCRAM) && ((Escort_last_path_created + F1_0*15) < GameTime))) {
1102 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
1103 Escort_last_path_created = GameTime;
1106 if ((Escort_special_goal != ESCORT_GOAL_SCRAM) && time_to_visit_player(objp, ailp, aip)) {
1109 Buddy_last_player_path_created = GameTime;
1110 ailp->mode = AIM_GOTO_PLAYER;
1111 if (!player_visibility) {
1112 if ((Last_come_back_message_time + F1_0 < GameTime) || (Last_come_back_message_time > GameTime)) {
1113 buddy_message("Coming back to get you.");
1114 Last_come_back_message_time = GameTime;
1117 // No point in Buddy creating very long path if he's not allowed to talk. Really kills framerate.
1118 max_len = Max_escort_length;
1119 if (!Buddy_allowed_to_talk)
1121 create_path_to_player(objp, max_len, 1); // MK!: Last parm used to be 1!
1122 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1123 // -- mprintf((0, "Creating path to player, length = %i\n", aip->path_length));
1124 ailp->mode = AIM_GOTO_PLAYER;
1125 } else if (GameTime - Buddy_last_seen_player > MAX_ESCORT_TIME_AWAY) {
1126 // This is to prevent buddy from looking for a goal, which he will do because we only allow path creation once/second.
1128 } else if ((ailp->mode == AIM_GOTO_PLAYER) && (dist_to_player < MIN_ESCORT_DISTANCE)) {
1129 Escort_goal_object = escort_set_goal_object();
1130 ailp->mode = AIM_GOTO_OBJECT; // May look stupid to be before path creation, but ai_door_is_openable uses mode to determine what doors can be got through
1131 escort_create_path_to_goal(objp);
1132 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1133 // mprintf((0, "Creating path to goal, length = %i\n", aip->path_length));
1134 if (aip->path_length < 3) {
1135 create_n_segment_path(objp, 5, Believed_player_seg);
1136 // mprintf((0, "Path to goal has length %i, just wandering...\n", aip->path_length));
1138 ailp->mode = AIM_GOTO_OBJECT;
1139 } else if (Escort_goal_object == ESCORT_GOAL_UNSPECIFIED) {
1140 if ((ailp->mode != AIM_GOTO_PLAYER) || (dist_to_player < MIN_ESCORT_DISTANCE)) {
1141 Escort_goal_object = escort_set_goal_object();
1142 ailp->mode = AIM_GOTO_OBJECT; // May look stupid to be before path creation, but ai_door_is_openable uses mode to determine what doors can be got through
1143 escort_create_path_to_goal(objp);
1144 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1145 // mprintf((0, "Creating path to goal, length = %i\n", aip->path_length));
1146 if (aip->path_length < 3) {
1147 create_n_segment_path(objp, 5, Believed_player_seg);
1148 // mprintf((0, "Path to goal has length %i, just wandering...\n", aip->path_length));
1150 ailp->mode = AIM_GOTO_OBJECT;
1153 ; // mprintf((0, "!"));
1157 void invalidate_escort_goal(void)
1159 Escort_goal_object = -1;
1162 // -------------------------------------------------------------------------------------------------
1163 void do_snipe_frame(object *objp, fix dist_to_player, int player_visibility, vms_vector *vec_to_player)
1165 int objnum = OBJECT_NUMBER(objp);
1166 ai_local *ailp = &Ai_local_info[objnum];
1167 fix connected_distance;
1169 if (dist_to_player > F1_0*500)
1172 // -- mprintf((0, "Mode: %10s, Dist: %7.3f\n", mode_text[ailp->mode], f2fl(dist_to_player)));
1174 switch (ailp->mode) {
1175 case AIM_SNIPE_WAIT:
1176 if ((dist_to_player > F1_0*50) && (ailp->next_action_time > 0))
1179 ailp->next_action_time = SNIPE_WAIT_TIME;
1181 connected_distance = find_connected_distance(&objp->pos, objp->segnum, &Believed_player_pos, Believed_player_seg, 30, WID_FLY_FLAG);
1182 if (connected_distance < F1_0*500) {
1183 // -- mprintf((0, "Object #%i entering attack mode.\n", objnum));
1184 create_path_to_player(objp, 30, 1);
1185 ailp->mode = AIM_SNIPE_ATTACK;
1186 ailp->next_action_time = SNIPE_ATTACK_TIME; // have up to 10 seconds to find player.
1190 case AIM_SNIPE_RETREAT:
1191 case AIM_SNIPE_RETREAT_BACKWARDS:
1192 if (ailp->next_action_time < 0) {
1193 ailp->mode = AIM_SNIPE_WAIT;
1194 ailp->next_action_time = SNIPE_WAIT_TIME;
1195 // -- mprintf((0, "Object #%i going from retreat to wait.\n", objnum));
1196 } else if ((player_visibility == 0) || (ailp->next_action_time > SNIPE_ABORT_RETREAT_TIME)) {
1197 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1198 ailp->mode = AIM_SNIPE_RETREAT_BACKWARDS;
1200 // -- mprintf((0, "Object #%i going from retreat to fire.\n", objnum));
1201 ailp->mode = AIM_SNIPE_FIRE;
1202 ailp->next_action_time = SNIPE_FIRE_TIME/2;
1206 case AIM_SNIPE_ATTACK:
1207 if (ailp->next_action_time < 0) {
1208 // -- mprintf((0, "Object #%i timed out from attack to retreat mode.\n", objnum));
1209 ailp->mode = AIM_SNIPE_RETREAT;
1210 ailp->next_action_time = SNIPE_WAIT_TIME;
1212 // -- mprintf((0, "Object #%i attacking: visibility = %i\n", player_visibility));
1213 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1214 if (player_visibility) {
1215 ailp->mode = AIM_SNIPE_FIRE;
1216 ailp->next_action_time = SNIPE_FIRE_TIME;
1218 ailp->mode = AIM_SNIPE_ATTACK;
1222 case AIM_SNIPE_FIRE:
1223 if (ailp->next_action_time < 0) {
1224 ai_static *aip = &objp->ctype.ai_info;
1225 // -- mprintf((0, "Object #%i going from fire to retreat.\n", objnum));
1226 create_n_segment_path(objp, 10 + d_rand()/2048, ConsoleObject->segnum);
1227 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1228 if (d_rand() < 8192)
1229 ailp->mode = AIM_SNIPE_RETREAT_BACKWARDS;
1231 ailp->mode = AIM_SNIPE_RETREAT;
1232 ailp->next_action_time = SNIPE_RETREAT_TIME;
1238 Int3(); // Oops, illegal mode for snipe behavior.
1239 ailp->mode = AIM_SNIPE_ATTACK;
1240 ailp->next_action_time = F1_0;
1246 #define THIEF_DEPTH 20
1248 extern int pick_connected_segment(object *objp, int max_depth);
1250 // ------------------------------------------------------------------------------------------------------
1251 // Choose segment to recreate thief in.
1252 int choose_thief_recreation_segment(void)
1257 cur_drop_depth = THIEF_DEPTH;
1259 while ((segnum == -1) && (cur_drop_depth > THIEF_DEPTH/2)) {
1260 segnum = pick_connected_segment(&Objects[Players[Player_num].objnum], cur_drop_depth);
1261 if (Segment2s[segnum].special == SEGMENT_IS_CONTROLCEN)
1267 mprintf((1, "Warning: Unable to find a connected segment for thief recreation.\n"));
1268 return (d_rand() * Highest_segment_index) >> 15;
1274 extern object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id);
1276 fix Re_init_thief_time = 0x3f000000;
1278 // ----------------------------------------------------------------------
1279 void recreate_thief(object *objp)
1282 vms_vector center_point;
1285 segnum = choose_thief_recreation_segment();
1286 compute_segment_center(¢er_point, &Segments[segnum]);
1288 new_obj = create_morph_robot( &Segments[segnum], ¢er_point, objp->id);
1289 init_ai_object(OBJECT_NUMBER(new_obj), AIB_SNIPE, -1);
1290 Re_init_thief_time = GameTime + F1_0*10; // In 10 seconds, re-initialize thief.
1293 // ----------------------------------------------------------------------------
1294 #define THIEF_ATTACK_TIME (F1_0*10)
1296 fix Thief_wait_times[NDL] = {F1_0*30, F1_0*25, F1_0*20, F1_0*15, F1_0*10};
1298 // -------------------------------------------------------------------------------------------------
1299 void do_thief_frame(object *objp, fix dist_to_player, int player_visibility, vms_vector *vec_to_player)
1301 int objnum = OBJECT_NUMBER(objp);
1302 ai_local *ailp = &Ai_local_info[objnum];
1303 fix connected_distance;
1305 // -- mprintf((0, "%10s: Action Time: %7.3f\n", mode_text[ailp->mode], f2fl(ailp->next_action_time)));
1307 if ((Current_level_num < 0) && (Re_init_thief_time < GameTime)) {
1308 if (Re_init_thief_time > GameTime - F1_0*2)
1309 init_thief_for_level();
1310 Re_init_thief_time = 0x3f000000;
1313 if ((dist_to_player > F1_0*500) && (ailp->next_action_time > 0))
1317 ailp->mode = AIM_THIEF_RETREAT;
1319 switch (ailp->mode) {
1320 case AIM_THIEF_WAIT:
1321 // -- mprintf((0, "WAIT\n"));
1323 if (ailp->player_awareness_type >= PA_PLAYER_COLLISION) {
1324 ailp->player_awareness_type = 0;
1325 // -- mprintf((0, "Thief: Awareness = %i ", ailp->player_awareness_type));
1327 // -- mprintf((0, "ATTACK\n"));
1328 create_path_to_player(objp, 30, 1);
1329 ailp->mode = AIM_THIEF_ATTACK;
1330 ailp->next_action_time = THIEF_ATTACK_TIME/2;
1332 } else if (player_visibility) {
1333 // -- mprintf((0, "RETREAT\n"));
1334 create_n_segment_path(objp, 15, ConsoleObject->segnum);
1335 ailp->mode = AIM_THIEF_RETREAT;
1339 if ((dist_to_player > F1_0*50) && (ailp->next_action_time > 0))
1342 ailp->next_action_time = Thief_wait_times[Difficulty_level]/2;
1344 connected_distance = find_connected_distance(&objp->pos, objp->segnum, &Believed_player_pos, Believed_player_seg, 30, WID_FLY_FLAG);
1345 if (connected_distance < F1_0*500) {
1346 // -- mprintf((0, "Thief creating path to player.\n", objnum));
1347 create_path_to_player(objp, 30, 1);
1348 ailp->mode = AIM_THIEF_ATTACK;
1349 ailp->next_action_time = THIEF_ATTACK_TIME; // have up to 10 seconds to find player.
1354 case AIM_THIEF_RETREAT:
1355 // -- mprintf((0, "RETREAT\n"));
1357 if (ailp->next_action_time < 0) {
1358 ailp->mode = AIM_THIEF_WAIT;
1359 ailp->next_action_time = Thief_wait_times[Difficulty_level];
1360 } else if ((dist_to_player < F1_0*100) || player_visibility || (ailp->player_awareness_type >= PA_PLAYER_COLLISION)) {
1361 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1362 if ((dist_to_player < F1_0*100) || (ailp->player_awareness_type >= PA_PLAYER_COLLISION)) {
1363 ai_static *aip = &objp->ctype.ai_info;
1364 if (((aip->cur_path_index <=1) && (aip->PATH_DIR == -1)) || ((aip->cur_path_index >= aip->path_length-1) && (aip->PATH_DIR == 1))) {
1365 ailp->player_awareness_type = 0;
1366 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1368 // If path is real short, try again, allowing to go through player's segment
1369 if (aip->path_length < 4) {
1370 // -- mprintf((0, "Thief is cornered. Willing to fly through player.\n"));
1371 create_n_segment_path(objp, 10, -1);
1372 } else if (objp->shields* 4 < Robot_info[objp->id].strength) {
1373 // If robot really low on hits, will run through player with even longer path
1374 if (aip->path_length < 8) {
1375 create_n_segment_path(objp, 10, -1);
1379 ailp->mode = AIM_THIEF_RETREAT;
1380 // -- mprintf((0, "Thief creating new RETREAT path.\n"));
1383 ailp->mode = AIM_THIEF_RETREAT;
1389 // This means the thief goes from wherever he is to the player.
1390 // Note: When thief successfully steals something, his action time is forced negative and his mode is changed
1391 // to retreat to get him out of attack mode.
1392 case AIM_THIEF_ATTACK:
1393 // -- mprintf((0, "ATTACK\n"));
1395 if (ailp->player_awareness_type >= PA_PLAYER_COLLISION) {
1396 ailp->player_awareness_type = 0;
1397 if (d_rand() > 8192) {
1398 // --- mprintf((0, "RETREAT!!\n"));
1399 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1400 Ai_local_info[OBJECT_NUMBER(objp)].next_action_time = Thief_wait_times[Difficulty_level]/2;
1401 Ai_local_info[OBJECT_NUMBER(objp)].mode = AIM_THIEF_RETREAT;
1403 } else if (ailp->next_action_time < 0) {
1404 // This forces him to create a new path every second.
1405 ailp->next_action_time = F1_0;
1406 create_path_to_player(objp, 100, 0);
1407 ailp->mode = AIM_THIEF_ATTACK;
1408 // -- mprintf((0, "Creating path to player.\n"));
1410 if (player_visibility && (dist_to_player < F1_0*100)) {
1411 // If the player is close to looking at the thief, thief shall run away.
1412 // No more stupid thief trying to sneak up on you when you're looking right at him!
1413 if (dist_to_player > F1_0*60) {
1414 fix dot = vm_vec_dot(vec_to_player, &ConsoleObject->orient.fvec);
1415 if (dot < -F1_0/2) { // Looking at least towards thief, so thief will run!
1416 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1417 Ai_local_info[OBJECT_NUMBER(objp)].next_action_time = Thief_wait_times[Difficulty_level]/2;
1418 Ai_local_info[OBJECT_NUMBER(objp)].mode = AIM_THIEF_RETREAT;
1421 ai_turn_towards_vector(vec_to_player, objp, F1_0/4);
1422 move_towards_player(objp, vec_to_player);
1424 ai_static *aip = &objp->ctype.ai_info;
1425 // If path length == 0, then he will keep trying to create path, but he is probably stuck in his closet.
1426 if ((aip->path_length > 1) || ((FrameCount & 0x0f) == 0)) {
1427 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1428 ailp->mode = AIM_THIEF_ATTACK;
1435 mprintf ((0,"Thief mode (broken) = %d\n",ailp->mode));
1436 // -- Int3(); // Oops, illegal mode for thief behavior.
1437 ailp->mode = AIM_THIEF_ATTACK;
1438 ailp->next_action_time = F1_0;
1444 // ----------------------------------------------------------------------------
1445 // Return true if this item (whose presence is indicated by Players[player_num].flags) gets stolen.
1446 int maybe_steal_flag_item(int player_num, int flagval)
1448 if (Players[player_num].flags & flagval) {
1449 if (d_rand() < THIEF_PROBABILITY) {
1450 int powerup_index=-1;
1451 Players[player_num].flags &= (~flagval);
1452 // -- mprintf((0, "You lost your %4x capability!\n", flagval));
1454 case PLAYER_FLAGS_INVULNERABLE:
1455 powerup_index = POW_INVULNERABILITY;
1456 thief_message("Invulnerability stolen!");
1458 case PLAYER_FLAGS_CLOAKED:
1459 powerup_index = POW_CLOAK;
1460 thief_message("Cloak stolen!");
1462 case PLAYER_FLAGS_MAP_ALL:
1463 powerup_index = POW_FULL_MAP;
1464 thief_message("Full map stolen!");
1466 case PLAYER_FLAGS_QUAD_LASERS:
1467 powerup_index = POW_QUAD_FIRE;
1468 thief_message("Quad lasers stolen!");
1470 case PLAYER_FLAGS_AFTERBURNER:
1471 powerup_index = POW_AFTERBURNER;
1472 thief_message("Afterburner stolen!");
1474 // -- case PLAYER_FLAGS_AMMO_RACK:
1475 // -- powerup_index = POW_AMMO_RACK;
1476 // -- thief_message("Ammo Rack stolen!");
1478 case PLAYER_FLAGS_CONVERTER:
1479 powerup_index = POW_CONVERTER;
1480 thief_message("Converter stolen!");
1482 case PLAYER_FLAGS_HEADLIGHT:
1483 powerup_index = POW_HEADLIGHT;
1484 thief_message("Headlight stolen!");
1485 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
1488 Assert(powerup_index != -1);
1489 Stolen_items[Stolen_item_index] = powerup_index;
1491 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1499 // ----------------------------------------------------------------------------
1500 int maybe_steal_secondary_weapon(int player_num, int weapon_num)
1502 if ((Players[player_num].secondary_weapon_flags & HAS_FLAG(weapon_num)) && Players[player_num].secondary_ammo[weapon_num])
1503 if (d_rand() < THIEF_PROBABILITY) {
1504 if (weapon_num == PROXIMITY_INDEX)
1505 if (d_rand() > 8192) // Come in groups of 4, only add 1/4 of time.
1507 Players[player_num].secondary_ammo[weapon_num]--;
1509 // Smart mines and proxbombs don't get dropped because they only come in 4 packs.
1510 if ((weapon_num != PROXIMITY_INDEX) && (weapon_num != SMART_MINE_INDEX)) {
1511 Stolen_items[Stolen_item_index] = Secondary_weapon_to_powerup[weapon_num];
1514 thief_message("%s stolen!", Text_string[114+weapon_num]); // Danger! Danger! Use of literal! Danger!
1515 if (Players[Player_num].secondary_ammo[weapon_num] == 0)
1516 auto_select_weapon(1);
1518 // -- compress_stolen_items();
1519 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1526 // ----------------------------------------------------------------------------
1527 int maybe_steal_primary_weapon(int player_num, int weapon_num)
1529 if ((Players[player_num].primary_weapon_flags & HAS_FLAG(weapon_num)) && Players[player_num].primary_ammo[weapon_num]) {
1530 if (d_rand() < THIEF_PROBABILITY) {
1531 if (weapon_num == 0) {
1532 if (Players[player_num].laser_level > 0) {
1533 if (Players[player_num].laser_level > 3) {
1534 Stolen_items[Stolen_item_index] = POW_SUPER_LASER;
1536 Stolen_items[Stolen_item_index] = Primary_weapon_to_powerup[weapon_num];
1538 thief_message("%s level decreased!", Text_string[104+weapon_num]); // Danger! Danger! Use of literal! Danger!
1539 Players[player_num].laser_level--;
1540 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1543 } else if (Players[player_num].primary_weapon_flags & (1 << weapon_num)) {
1544 Players[player_num].primary_weapon_flags &= ~(1 << weapon_num);
1545 Stolen_items[Stolen_item_index] = Primary_weapon_to_powerup[weapon_num];
1547 thief_message("%s stolen!", Text_string[104+weapon_num]); // Danger! Danger! Use of literal! Danger!
1548 auto_select_weapon(0);
1549 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1560 // ----------------------------------------------------------------------------
1561 // Called for a thief-type robot.
1562 // If a item successfully stolen, returns true, else returns false.
1563 // If a wapon successfully stolen, do everything, removing it from player,
1564 // updating Stolen_items information, deselecting, etc.
1565 int attempt_to_steal_item_3(object *objp, int player_num)
1569 if (Ai_local_info[OBJECT_NUMBER(objp)].mode != AIM_THIEF_ATTACK)
1572 // First, try to steal equipped items.
1574 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_INVULNERABLE))
1577 // If primary weapon = laser, first try to rip away those nasty quad lasers!
1578 if (Primary_weapon == 0)
1579 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_QUAD_LASERS))
1582 // Makes it more likely to steal primary than secondary.
1584 if (maybe_steal_primary_weapon(player_num, Primary_weapon))
1587 if (maybe_steal_secondary_weapon(player_num, Secondary_weapon))
1590 // See what the player has and try to snag something.
1591 // Try best things first.
1592 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_INVULNERABLE))
1594 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_CLOAKED))
1596 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_QUAD_LASERS))
1598 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_AFTERBURNER))
1600 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_CONVERTER))
1602 // -- if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_AMMO_RACK)) // Can't steal because what if have too many items, say 15 homing missiles?
1604 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_HEADLIGHT))
1606 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_MAP_ALL))
1609 for (i=MAX_SECONDARY_WEAPONS-1; i>=0; i--) {
1610 if (maybe_steal_primary_weapon(player_num, i))
1612 if (maybe_steal_secondary_weapon(player_num, i))
1619 // ----------------------------------------------------------------------------
1620 int attempt_to_steal_item_2(object *objp, int player_num)
1624 rval = attempt_to_steal_item_3(objp, player_num);
1627 Stolen_item_index = (Stolen_item_index+1) % MAX_STOLEN_ITEMS;
1628 if (d_rand() > 20000) // Occasionally, boost the value again
1629 Stolen_item_index = (Stolen_item_index+1) % MAX_STOLEN_ITEMS;
1635 // ----------------------------------------------------------------------------
1636 // Called for a thief-type robot.
1637 // If a item successfully stolen, returns true, else returns false.
1638 // If a wapon successfully stolen, do everything, removing it from player,
1639 // updating Stolen_items information, deselecting, etc.
1640 int attempt_to_steal_item(object *objp, int player_num)
1645 if (objp->ctype.ai_info.dying_start_time)
1648 rval += attempt_to_steal_item_2(objp, player_num);
1650 for (i=0; i<3; i++) {
1651 if (!rval || (d_rand() < 11000)) { // about 1/3 of time, steal another item
1652 rval += attempt_to_steal_item_2(objp, player_num);
1656 // -- mprintf((0, "%i items were stolen!\n", rval));
1658 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1659 Ai_local_info[OBJECT_NUMBER(objp)].next_action_time = Thief_wait_times[Difficulty_level]/2;
1660 Ai_local_info[OBJECT_NUMBER(objp)].mode = AIM_THIEF_RETREAT;
1662 PALETTE_FLASH_ADD(30, 15, -20);
1663 update_laser_weapon_info();
1664 // digi_link_sound_to_pos( SOUND_NASTY_ROBOT_HIT_1, objp->segnum, 0, &objp->pos, 0 , DEFAULT_ROBOT_SOUND_VOLUME);
1665 // I removed this to make the "steal sound" more obvious -AP
1667 if (Game_mode & GM_NETWORK)
1668 multi_send_stolen_items();
1674 // --------------------------------------------------------------------------------------------------------------
1675 // Indicate no items have been stolen.
1676 void init_thief_for_level(void)
1680 for (i=0; i<MAX_STOLEN_ITEMS; i++)
1681 Stolen_items[i] = 255;
1683 Assert (MAX_STOLEN_ITEMS >= 3*2); // Oops! Loop below will overwrite memory!
1685 if (!(Game_mode & GM_MULTI))
1686 for (i=0; i<3; i++) {
1687 Stolen_items[2*i] = POW_SHIELD_BOOST;
1688 Stolen_items[2*i+1] = POW_ENERGY;
1691 Stolen_item_index = 0;
1694 // --------------------------------------------------------------------------------------------------------------
1695 void drop_stolen_items(object *objp)
1699 mprintf ((0,"Dropping thief items!\n"));
1701 // -- compress_stolen_items();
1703 for (i=0; i<MAX_STOLEN_ITEMS; i++) {
1704 if (Stolen_items[i] != 255)
1705 drop_powerup(OBJ_POWERUP, Stolen_items[i], 1, &objp->mtype.phys_info.velocity, &objp->pos, objp->segnum);
1706 Stolen_items[i] = 255;
1711 // --------------------------------------------------------------------------------------------------------------
1712 void do_escort_menu(void)
1719 char goal_str[32], tstr[32];
1721 if (Game_mode & GM_MULTI) {
1722 HUD_init_message("No Guide-Bot in Multiplayer!");
1726 for (i=0; i<=Highest_object_index; i++) {
1727 if (Objects[i].type == OBJ_ROBOT)
1728 if (Robot_info[Objects[i].id].companion)
1732 if (i > Highest_object_index) {
1734 HUD_init_message("No Guide-Bot present in mine!");
1737 // If no buddy bot, create one!
1738 HUD_init_message("Debug Version: Creating Guide-Bot!");
1745 ok_for_buddy_to_talk(); // Needed here or we might not know buddy can talk when he can.
1747 if (!Buddy_allowed_to_talk) {
1748 HUD_init_message("%s has not been released",guidebot_name);
1752 digi_pause_digi_sounds();
1756 apply_modified_palette();
1757 reset_palette_add();
1759 game_flush_inputs();
1763 // set_screen_mode( SCREEN_MENU );
1765 gr_palette_load( gr_palette );
1767 // This prevents the buddy from coming back if you've told him to scram.
1768 // If we don't set next_goal, we get garbage there.
1769 if (Escort_special_goal == ESCORT_GOAL_SCRAM) {
1770 Escort_special_goal = -1; // Else setting next goal might fail.
1771 next_goal = escort_set_goal_object();
1772 Escort_special_goal = ESCORT_GOAL_SCRAM;
1774 Escort_special_goal = -1; // Else setting next goal might fail.
1775 next_goal = escort_set_goal_object();
1778 switch (next_goal) {
1780 case ESCORT_GOAL_UNSPECIFIED:
1782 sprintf(goal_str, "ERROR");
1786 case ESCORT_GOAL_BLUE_KEY:
1787 sprintf(goal_str, "blue key");
1789 case ESCORT_GOAL_GOLD_KEY:
1790 sprintf(goal_str, "yellow key");
1792 case ESCORT_GOAL_RED_KEY:
1793 sprintf(goal_str, "red key");
1795 case ESCORT_GOAL_CONTROLCEN:
1796 sprintf(goal_str, "reactor");
1798 case ESCORT_GOAL_BOSS:
1799 sprintf(goal_str, "boss");
1801 case ESCORT_GOAL_EXIT:
1802 sprintf(goal_str, "exit");
1804 case ESCORT_GOAL_MARKER1:
1805 case ESCORT_GOAL_MARKER2:
1806 case ESCORT_GOAL_MARKER3:
1807 case ESCORT_GOAL_MARKER4:
1808 case ESCORT_GOAL_MARKER5:
1809 case ESCORT_GOAL_MARKER6:
1810 case ESCORT_GOAL_MARKER7:
1811 case ESCORT_GOAL_MARKER8:
1812 case ESCORT_GOAL_MARKER9:
1813 sprintf(goal_str, "marker %i", next_goal-ESCORT_GOAL_MARKER1+1);
1818 if (!Buddy_messages_suppressed)
1819 sprintf(tstr, "Suppress");
1821 sprintf(tstr, "Enable");
1823 sprintf(msg, "Select Guide-Bot Command:\n\n"
1824 "0. Next Goal: %s" CC_LSPACING_S "3\n"
1825 "\x84. Find Energy Powerup" CC_LSPACING_S "3\n"
1826 "2. Find Energy Center" CC_LSPACING_S "3\n"
1827 "3. Find Shield Powerup" CC_LSPACING_S "3\n"
1828 "4. Find Any Powerup" CC_LSPACING_S "3\n"
1829 "5. Find a Robot" CC_LSPACING_S "3\n"
1830 "6. Find a Hostage" CC_LSPACING_S "3\n"
1831 "7. Stay Away From Me" CC_LSPACING_S "3\n"
1832 "8. Find My Powerups" CC_LSPACING_S "3\n"
1833 "9. Find the exit\n\n"
1835 // -- "9. Find the exit" CC_LSPACING_S "3\n"
1838 show_escort_menu(msg); //TXT_PAUSE);
1841 key = newmenu_getch();
1854 Looking_for_marker = -1;
1855 Last_buddy_key = -1;
1856 set_escort_special_goal(key);
1857 Last_buddy_key = -1;
1863 clear_boxed_message();
1867 //--10/08/95-- Screwed up font, background. Why needed, anyway?
1868 //--10/08/95-- case KEY_F1:
1869 //--10/08/95-- clear_boxed_message();
1870 //--10/08/95-- do_show_help();
1871 //--10/08/95-- show_boxed_message(msg);
1872 //--10/08/95-- break;
1874 case KEY_PRINT_SCREEN:
1875 save_screen_shot(0);
1879 case KEY_BACKSP: Int3(); break;
1886 temp = !Buddy_messages_suppressed;
1889 strcpy(msg, "suppressed");
1891 strcpy(msg, "enabled");
1893 Buddy_messages_suppressed = 1;
1894 buddy_message("Messages %s.", msg);
1896 Buddy_messages_suppressed = temp;
1909 game_flush_inputs();
1914 digi_resume_digi_sounds();
1918 // -------------------------------------------------------------------------------
1919 // Show the Buddy menu!
1920 void show_escort_menu(char *msg)
1926 gr_set_current_canvas(&VR_screen_pages[0]);
1928 gr_set_curfont( GAME_FONT );
1930 gr_get_string_size(msg,&w,&h,&aw);
1932 x = (grd_curscreen->sc_w-w)/2;
1933 y = (grd_curscreen->sc_h-h)/4;
1935 gr_set_fontcolor( gr_getcolor(0, 28, 0), -1 );
1937 nm_draw_background(x-15,y-15,x+w+15-1,y+h+15-1);
1939 gr_ustring( x, y, msg );