1 /* $Id: escort.c,v 1.5 2003-03-27 01:23:18 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 #include <stdio.h> // for printf()
20 #include <stdlib.h> // for rand() and qsort()
21 #include <string.h> // for memset()
59 #include "editor/editor.h"
62 extern void multi_send_stolen_items();
63 void say_escort_goal(int goal_num);
64 void show_escort_menu(char *msg);
67 char *Escort_goal_text[MAX_ESCORT_GOALS] = {
92 // -- too much work -- "KAMIKAZE "
95 int Max_escort_length = 200;
96 int Escort_kill_object = -1;
97 ubyte Stolen_items[MAX_STOLEN_ITEMS];
98 int Stolen_item_index;
99 fix Escort_last_path_created = 0;
100 int Escort_goal_object = ESCORT_GOAL_UNSPECIFIED, Escort_special_goal = -1, Escort_goal_index = -1, Buddy_messages_suppressed = 0;
101 fix Buddy_sorry_time;
102 int Buddy_objnum, Buddy_allowed_to_talk;
103 int Looking_for_marker;
106 fix Last_buddy_message_time;
108 char guidebot_name[GUIDEBOT_NAME_LEN+1] = "GUIDE-BOT";
109 char real_guidebot_name[GUIDEBOT_NAME_LEN+1] = "GUIDE-BOT";
111 void init_buddy_for_level(void)
115 Buddy_allowed_to_talk = 0;
117 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
118 Escort_special_goal = -1;
119 Escort_goal_index = -1;
120 Buddy_messages_suppressed = 0;
122 for (i=0; i<=Highest_object_index; i++)
123 if (Robot_info[Objects[i].id].companion)
125 if (i <= Highest_object_index)
128 Buddy_sorry_time = -F1_0;
130 Looking_for_marker = -1;
134 // -----------------------------------------------------------------------------
135 // See if segment from curseg through sidenum is reachable.
136 // Return true if it is reachable, else return false.
137 int segment_is_reachable(int curseg, int sidenum)
140 segment *segp = &Segments[curseg];
142 if (!IS_CHILD(segp->children[sidenum]))
145 wall_num = segp->sides[sidenum].wall_num;
147 // If no wall, then it is reachable
151 rval = ai_door_is_openable(NULL, segp, sidenum);
155 // -- MK, 10/17/95 --
156 // -- MK, 10/17/95 -- // Hmm, a closed wall. I think this mean not reachable.
157 // -- MK, 10/17/95 -- if (Walls[wall_num].type == WALL_CLOSED)
158 // -- MK, 10/17/95 -- return 0;
159 // -- MK, 10/17/95 --
160 // -- MK, 10/17/95 -- if (Walls[wall_num].type == WALL_DOOR) {
161 // -- MK, 10/17/95 -- if (Walls[wall_num].keys == KEY_NONE) {
162 // -- MK, 10/17/95 -- return 1; // @MK, 10/17/95: Be consistent with ai_door_is_openable
163 // -- MK, 10/17/95 -- // -- if (Walls[wall_num].flags & WALL_DOOR_LOCKED)
164 // -- MK, 10/17/95 -- // -- return 0;
165 // -- MK, 10/17/95 -- // -- else
166 // -- MK, 10/17/95 -- // -- return 1;
167 // -- MK, 10/17/95 -- } else if (Walls[wall_num].keys == KEY_BLUE)
168 // -- MK, 10/17/95 -- return (Players[Player_num].flags & PLAYER_FLAGS_BLUE_KEY);
169 // -- MK, 10/17/95 -- else if (Walls[wall_num].keys == KEY_GOLD)
170 // -- MK, 10/17/95 -- return (Players[Player_num].flags & PLAYER_FLAGS_GOLD_KEY);
171 // -- MK, 10/17/95 -- else if (Walls[wall_num].keys == KEY_RED)
172 // -- MK, 10/17/95 -- return (Players[Player_num].flags & PLAYER_FLAGS_RED_KEY);
173 // -- MK, 10/17/95 -- else
174 // -- MK, 10/17/95 -- Int3(); // Impossible! Doesn't have no key, but doesn't have any key!
175 // -- MK, 10/17/95 -- } else
176 // -- MK, 10/17/95 -- return 1;
177 // -- MK, 10/17/95 --
178 // -- MK, 10/17/95 -- Int3(); // Hmm, thought 'if' above had to return!
179 // -- MK, 10/17/95 -- return 0;
184 // -----------------------------------------------------------------------------
185 // Create a breadth-first list of segments reachable from current segment.
186 // max_segs is maximum number of segments to search. Use MAX_SEGMENTS to search all.
187 // On exit, *length <= max_segs.
191 // bfs_list: array of shorts, each reachable segment. Includes start segment.
192 // length: number of elements in bfs_list
193 void create_bfs_list(int start_seg, short bfs_list[], int *length, int max_segs)
196 byte visited[MAX_SEGMENTS];
198 for (i=0; i<MAX_SEGMENTS; i++)
204 bfs_list[head++] = start_seg;
205 visited[start_seg] = 1;
207 while ((head != tail) && (head < max_segs)) {
212 curseg = bfs_list[tail++];
213 cursegp = &Segments[curseg];
215 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++) {
218 connected_seg = cursegp->children[i];
220 if (IS_CHILD(connected_seg) && (visited[connected_seg] == 0)) {
221 if (segment_is_reachable(curseg, i)) {
222 bfs_list[head++] = connected_seg;
223 if (head >= max_segs)
225 visited[connected_seg] = 1;
226 Assert(head < MAX_SEGMENTS);
236 // -----------------------------------------------------------------------------
237 // Return true if ok for buddy to talk, else return false.
238 // Buddy is allowed to talk if the segment he is in does not contain a blastable wall that has not been blasted
239 // AND he has never yet, since being initialized for level, been allowed to talk.
240 int ok_for_buddy_to_talk(void)
245 if (Objects[Buddy_objnum].type != OBJ_ROBOT) {
246 Buddy_allowed_to_talk = 0;
250 if (Buddy_allowed_to_talk)
253 if ((Objects[Buddy_objnum].type == OBJ_ROBOT) && (Buddy_objnum <= Highest_object_index) && !Robot_info[Objects[Buddy_objnum].id].companion) {
254 for (i=0; i<=Highest_object_index; i++)
255 if (Robot_info[Objects[i].id].companion)
257 if (i > Highest_object_index)
263 segp = &Segments[Objects[Buddy_objnum].segnum];
265 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++) {
266 int wall_num = segp->sides[i].wall_num;
268 if (wall_num != -1) {
269 if ((Walls[wall_num].type == WALL_BLASTABLE) && !(Walls[wall_num].flags & WALL_BLASTED))
273 // Check one level deeper.
274 if (IS_CHILD(segp->children[i])) {
276 segment *csegp = &Segments[segp->children[i]];
278 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++) {
279 int wall2 = csegp->sides[j].wall_num;
282 if ((Walls[wall2].type == WALL_BLASTABLE) && !(Walls[wall2].flags & WALL_BLASTED))
289 Buddy_allowed_to_talk = 1;
293 // --------------------------------------------------------------------------------------------
294 void detect_escort_goal_accomplished(int index)
299 if (!Buddy_allowed_to_talk)
302 // If goal is to go away, how can it be achieved?
303 if (Escort_special_goal == ESCORT_GOAL_SCRAM)
306 // See if goal found was a key. Need to handle default goals differently.
307 // Note, no buddy_met_goal sound when blow up reactor or exit. Not great, but ok
308 // since for reactor, noisy, for exit, buddy is disappearing.
309 if ((Escort_special_goal == -1) && (Escort_goal_index == index)) {
314 if ((Escort_goal_index <= ESCORT_GOAL_RED_KEY) && (index >= 0)) {
315 if (Objects[index].type == OBJ_POWERUP) {
316 if (Objects[index].id == POW_KEY_BLUE) {
317 if (Escort_goal_index == ESCORT_GOAL_BLUE_KEY) {
321 } else if (Objects[index].id == POW_KEY_GOLD) {
322 if (Escort_goal_index == ESCORT_GOAL_GOLD_KEY) {
326 } else if (Objects[index].id == POW_KEY_RED) {
327 if (Escort_goal_index == ESCORT_GOAL_RED_KEY) {
334 if (Escort_special_goal != -1)
336 if (Escort_special_goal == ESCORT_GOAL_ENERGYCEN) {
340 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++)
341 if (Segments[index].children[i] == Escort_goal_index) {
345 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
346 if (Segments[i].children[j] == Escort_goal_index) {
352 } else if ((Objects[index].type == OBJ_POWERUP) && (Escort_special_goal == ESCORT_GOAL_POWERUP))
353 detected = 1; // Any type of powerup picked up will do.
354 else if ((Objects[index].type == Objects[Escort_goal_index].type) && (Objects[index].id == Objects[Escort_goal_index].id)) {
355 // 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"
356 // because of the insistence of both type and id matching.
362 if (detected && ok_for_buddy_to_talk()) {
363 digi_play_sample_once(SOUND_BUDDY_MET_GOAL, F1_0);
364 Escort_goal_index = -1;
365 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
366 Escort_special_goal = -1;
367 Looking_for_marker = -1;
372 void change_guidebot_name()
375 char text[GUIDEBOT_NAME_LEN+1]="";
378 strcpy(text,guidebot_name);
380 m.type=NM_TYPE_INPUT; m.text_len = GUIDEBOT_NAME_LEN; m.text = text;
381 item = newmenu_do( NULL, "Enter Guide-bot name:", 1, &m, NULL );
384 strcpy(guidebot_name,text);
385 strcpy(real_guidebot_name,text);
390 // -----------------------------------------------------------------------------
391 void buddy_message(char * format, ... )
393 if (Buddy_messages_suppressed)
396 if (Game_mode & GM_MULTI)
399 if ((Last_buddy_message_time + F1_0 < GameTime) || (Last_buddy_message_time > GameTime)) {
400 if (ok_for_buddy_to_talk()) {
401 char gb_str[16], new_format[128];
405 va_start(args, format );
406 vsprintf(new_format, format, args);
410 gb_str[1] = BM_XRGB(28, 0, 0);
411 strcpy(&gb_str[2], guidebot_name);
415 gb_str[t+2] = BM_XRGB(0, 31, 0);
418 HUD_init_message("%s %s", gb_str, new_format);
420 Last_buddy_message_time = GameTime;
426 // -----------------------------------------------------------------------------
427 void thief_message(char * format, ... )
430 char gb_str[16], new_format[128];
433 va_start(args, format );
434 vsprintf(new_format, format, args);
438 gb_str[1] = BM_XRGB(28, 0, 0);
439 strcpy(&gb_str[2], "THIEF:");
441 gb_str[9] = BM_XRGB(0, 31, 0);
444 HUD_init_message("%s %s", gb_str, new_format);
448 // -----------------------------------------------------------------------------
449 // Return true if marker #id has been placed.
450 int marker_exists_in_mine(int id)
454 for (i=0; i<=Highest_object_index; i++)
455 if (Objects[i].type == OBJ_MARKER)
456 if (Objects[i].id == id)
462 // -----------------------------------------------------------------------------
463 void set_escort_special_goal(int special_key)
467 Buddy_messages_suppressed = 0;
469 if (!Buddy_allowed_to_talk) {
470 ok_for_buddy_to_talk();
471 if (!Buddy_allowed_to_talk) {
474 for (i=0; i<=Highest_object_index; i++)
475 if ((Objects[i].type == OBJ_ROBOT) && Robot_info[Objects[i].id].companion) {
476 HUD_init_message("%s has not been released.",guidebot_name);
479 if (i == Highest_object_index+1)
480 HUD_init_message("No Guide-Bot in mine.");
486 special_key = special_key & (~KEY_SHIFTED);
488 marker_key = special_key;
491 switch(special_key) {
493 marker_key = KEY_1+4;
496 marker_key = KEY_1+5;
499 marker_key = KEY_1+6;
502 marker_key = KEY_1+7;
505 marker_key = KEY_1+8;
508 marker_key = KEY_1+9;
513 if (Last_buddy_key == special_key)
515 if ((Looking_for_marker == -1) && (special_key != KEY_0)) {
516 if (marker_exists_in_mine(marker_key - KEY_1))
517 Looking_for_marker = marker_key - KEY_1;
519 Last_buddy_message_time = 0; // Force this message to get through.
520 buddy_message("Marker %i not placed.", marker_key - KEY_1 + 1);
521 Looking_for_marker = -1;
524 Looking_for_marker = -1;
528 Last_buddy_key = special_key;
530 if (special_key == KEY_0)
531 Looking_for_marker = -1;
533 if ( Looking_for_marker != -1 ) {
534 Escort_special_goal = ESCORT_GOAL_MARKER1 + marker_key - KEY_1;
536 switch (special_key) {
537 case KEY_1: Escort_special_goal = ESCORT_GOAL_ENERGY; break;
538 case KEY_2: Escort_special_goal = ESCORT_GOAL_ENERGYCEN; break;
539 case KEY_3: Escort_special_goal = ESCORT_GOAL_SHIELD; break;
540 case KEY_4: Escort_special_goal = ESCORT_GOAL_POWERUP; break;
541 case KEY_5: Escort_special_goal = ESCORT_GOAL_ROBOT; break;
542 case KEY_6: Escort_special_goal = ESCORT_GOAL_HOSTAGE; break;
543 case KEY_7: Escort_special_goal = ESCORT_GOAL_SCRAM; break;
544 case KEY_8: Escort_special_goal = ESCORT_GOAL_PLAYER_SPEW; break;
545 case KEY_9: Escort_special_goal = ESCORT_GOAL_EXIT; break;
546 case KEY_0: Escort_special_goal = -1; break;
548 Int3(); // Oops, called with illegal key value.
552 Last_buddy_message_time = GameTime - 2*F1_0; // Allow next message to come through.
554 say_escort_goal(Escort_special_goal);
555 // -- Escort_goal_object = escort_set_goal_object();
557 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
560 // -- old, pre-bfs, way -- // -----------------------------------------------------------------------------
561 // -- old, pre-bfs, way -- // Return object of interest.
562 // -- old, pre-bfs, way -- int exists_in_mine(int objtype, int objid)
563 // -- old, pre-bfs, way -- {
564 // -- old, pre-bfs, way -- int i;
565 // -- old, pre-bfs, way --
566 // -- old, pre-bfs, way -- mprintf((0, "exists_in_mine, type == %i, id == %i\n", objtype, objid));
567 // -- old, pre-bfs, way --
568 // -- old, pre-bfs, way -- if (objtype == FUELCEN_CHECK) {
569 // -- old, pre-bfs, way -- for (i=0; i<=Highest_segment_index; i++)
570 // -- old, pre-bfs, way -- if (Segments[i].special == SEGMENT_IS_FUELCEN)
571 // -- old, pre-bfs, way -- return i;
572 // -- old, pre-bfs, way -- } else {
573 // -- old, pre-bfs, way -- for (i=0; i<=Highest_object_index; i++) {
574 // -- old, pre-bfs, way -- if (Objects[i].type == objtype) {
575 // -- old, pre-bfs, way -- // Don't find escort robots if looking for robot!
576 // -- old, pre-bfs, way -- if ((Objects[i].type == OBJ_ROBOT) && (Robot_info[Objects[i].id].companion))
577 // -- old, pre-bfs, way -- continue;
578 // -- old, pre-bfs, way --
579 // -- old, pre-bfs, way -- if (objid == -1) {
580 // -- 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))
581 // -- old, pre-bfs, way -- return i;
582 // -- old, pre-bfs, way -- else
583 // -- old, pre-bfs, way -- return i;
584 // -- old, pre-bfs, way -- } else if (Objects[i].id == objid)
585 // -- old, pre-bfs, way -- return i;
586 // -- old, pre-bfs, way -- }
587 // -- old, pre-bfs, way -- }
588 // -- old, pre-bfs, way -- }
589 // -- old, pre-bfs, way --
590 // -- old, pre-bfs, way -- return -1;
591 // -- old, pre-bfs, way --
592 // -- old, pre-bfs, way -- }
594 // -----------------------------------------------------------------------------
595 // Return id of boss.
596 int get_boss_id(void)
600 for (i=0; i<=Highest_object_index; i++)
601 if (Objects[i].type == OBJ_ROBOT)
602 if (Robot_info[Objects[i].id].boss_flag)
603 return Objects[i].id;
608 // -----------------------------------------------------------------------------
609 // Return object index if object of objtype, objid exists in mine, else return -1
610 // "special" is used to find objects spewed by player which is hacked into flags field of powerup.
611 int exists_in_mine_2(int segnum, int objtype, int objid, int special)
613 if (Segments[segnum].objects != -1) {
614 int objnum = Segments[segnum].objects;
616 while (objnum != -1) {
617 object *curobjp = &Objects[objnum];
619 if (special == ESCORT_GOAL_PLAYER_SPEW) {
620 if (curobjp->flags & OF_PLAYER_DROPPED)
624 if (curobjp->type == objtype) {
625 // Don't find escort robots if looking for robot!
626 if ((curobjp->type == OBJ_ROBOT) && (Robot_info[curobjp->id].companion))
628 else if (objid == -1) {
629 if ((objtype == OBJ_POWERUP) && (curobjp->id != POW_KEY_BLUE) && (curobjp->id != POW_KEY_GOLD) && (curobjp->id != POW_KEY_RED))
633 } else if (curobjp->id == objid)
637 if (objtype == OBJ_POWERUP)
638 if (curobjp->contains_count)
639 if (curobjp->contains_type == OBJ_POWERUP)
640 if (curobjp->contains_id == objid)
643 objnum = curobjp->next;
650 // -----------------------------------------------------------------------------
651 // Return nearest object of interest.
652 // If special == ESCORT_GOAL_PLAYER_SPEW, then looking for any object spewed by player.
653 // -1 means object does not exist in mine.
654 // -2 means object does exist in mine, but buddy-bot can't reach it (eg, behind triggered wall)
655 int exists_in_mine(int start_seg, int objtype, int objid, int special)
657 int segindex, segnum;
658 short bfs_list[MAX_SEGMENTS];
661 // mprintf((0, "exists_in_mine, type == %i, id == %i\n", objtype, objid));
663 create_bfs_list(start_seg, bfs_list, &length, MAX_SEGMENTS);
665 if (objtype == FUELCEN_CHECK) {
666 for (segindex=0; segindex<length; segindex++) {
667 segnum = bfs_list[segindex];
668 if (Segment2s[segnum].special == SEGMENT_IS_FUELCEN)
672 for (segindex=0; segindex<length; segindex++) {
675 segnum = bfs_list[segindex];
677 objnum = exists_in_mine_2(segnum, objtype, objid, special);
684 // Couldn't find what we're looking for by looking at connectivity.
685 // See if it's in the mine. It could be hidden behind a trigger or switch
686 // which the buddybot doesn't understand.
687 if (objtype == FUELCEN_CHECK) {
688 for (segnum=0; segnum<=Highest_segment_index; segnum++)
689 if (Segment2s[segnum].special == SEGMENT_IS_FUELCEN)
692 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
695 objnum = exists_in_mine_2(segnum, objtype, objid, special);
704 // -----------------------------------------------------------------------------
705 // Return true if it happened, else return false.
706 int find_exit_segment(void)
710 // ---------- Find exit doors ----------
711 for (i=0; i<=Highest_segment_index; i++)
712 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
713 if (Segments[i].children[j] == -2) {
720 #define BUDDY_MARKER_TEXT_LEN 25
722 // -----------------------------------------------------------------------------
723 void say_escort_goal(int goal_num)
729 case ESCORT_GOAL_BLUE_KEY: buddy_message("Finding BLUE KEY"); break;
730 case ESCORT_GOAL_GOLD_KEY: buddy_message("Finding YELLOW KEY"); break;
731 case ESCORT_GOAL_RED_KEY: buddy_message("Finding RED KEY"); break;
732 case ESCORT_GOAL_CONTROLCEN: buddy_message("Finding REACTOR"); break;
733 case ESCORT_GOAL_EXIT: buddy_message("Finding EXIT"); break;
734 case ESCORT_GOAL_ENERGY: buddy_message("Finding ENERGY"); break;
735 case ESCORT_GOAL_ENERGYCEN: buddy_message("Finding ENERGY CENTER"); break;
736 case ESCORT_GOAL_SHIELD: buddy_message("Finding a SHIELD"); break;
737 case ESCORT_GOAL_POWERUP: buddy_message("Finding a POWERUP"); break;
738 case ESCORT_GOAL_ROBOT: buddy_message("Finding a ROBOT"); break;
739 case ESCORT_GOAL_HOSTAGE: buddy_message("Finding a HOSTAGE"); break;
740 case ESCORT_GOAL_SCRAM: buddy_message("Staying away..."); break;
741 case ESCORT_GOAL_BOSS: buddy_message("Finding BOSS robot"); break;
742 case ESCORT_GOAL_PLAYER_SPEW: buddy_message("Finding your powerups"); break;
743 case ESCORT_GOAL_MARKER1:
744 case ESCORT_GOAL_MARKER2:
745 case ESCORT_GOAL_MARKER3:
746 case ESCORT_GOAL_MARKER4:
747 case ESCORT_GOAL_MARKER5:
748 case ESCORT_GOAL_MARKER6:
749 case ESCORT_GOAL_MARKER7:
750 case ESCORT_GOAL_MARKER8:
751 case ESCORT_GOAL_MARKER9:
752 { char marker_text[BUDDY_MARKER_TEXT_LEN];
753 strncpy(marker_text, MarkerMessage[goal_num-ESCORT_GOAL_MARKER1], BUDDY_MARKER_TEXT_LEN-1);
754 marker_text[BUDDY_MARKER_TEXT_LEN-1] = 0;
755 buddy_message("Finding marker %i: '%s'", goal_num-ESCORT_GOAL_MARKER1+1, marker_text);
761 // -----------------------------------------------------------------------------
762 void escort_create_path_to_goal(object *objp)
765 int objnum = objp-Objects;
766 ai_static *aip = &objp->ctype.ai_info;
767 ai_local *ailp = &Ai_local_info[objnum];
769 if (Escort_special_goal != -1)
770 Escort_goal_object = Escort_special_goal;
772 Escort_kill_object = -1;
774 if (Looking_for_marker != -1) {
776 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_MARKER, Escort_goal_object-ESCORT_GOAL_MARKER1, -1);
777 if (Escort_goal_index > -1)
778 goal_seg = Objects[Escort_goal_index].segnum;
780 switch (Escort_goal_object) {
781 case ESCORT_GOAL_BLUE_KEY:
782 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_KEY_BLUE, -1);
783 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
785 case ESCORT_GOAL_GOLD_KEY:
786 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_KEY_GOLD, -1);
787 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
789 case ESCORT_GOAL_RED_KEY:
790 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_KEY_RED, -1);
791 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
793 case ESCORT_GOAL_CONTROLCEN:
794 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_CNTRLCEN, -1, -1);
795 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
797 case ESCORT_GOAL_EXIT:
798 case ESCORT_GOAL_EXIT2:
799 goal_seg = find_exit_segment();
800 Escort_goal_index = goal_seg;
802 case ESCORT_GOAL_ENERGY:
803 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_ENERGY, -1);
804 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
806 case ESCORT_GOAL_ENERGYCEN:
807 goal_seg = exists_in_mine(objp->segnum, FUELCEN_CHECK, -1, -1);
808 Escort_goal_index = goal_seg;
810 case ESCORT_GOAL_SHIELD:
811 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, POW_SHIELD_BOOST, -1);
812 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
814 case ESCORT_GOAL_POWERUP:
815 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_POWERUP, -1, -1);
816 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
818 case ESCORT_GOAL_ROBOT:
819 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_ROBOT, -1, -1);
820 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
822 case ESCORT_GOAL_HOSTAGE:
823 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_HOSTAGE, -1, -1);
824 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
826 case ESCORT_GOAL_PLAYER_SPEW:
827 Escort_goal_index = exists_in_mine(objp->segnum, -1, -1, ESCORT_GOAL_PLAYER_SPEW);
828 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
830 case ESCORT_GOAL_SCRAM:
831 goal_seg = -3; // Kinda a hack.
832 Escort_goal_index = goal_seg;
834 case ESCORT_GOAL_BOSS: {
837 boss_id = get_boss_id();
838 Assert(boss_id != -1);
839 Escort_goal_index = exists_in_mine(objp->segnum, OBJ_ROBOT, boss_id, -1);
840 if (Escort_goal_index > -1) goal_seg = Objects[Escort_goal_index].segnum;
844 Int3(); // Oops, Illegal value in Escort_goal_object.
850 // -- mprintf((0, "Creating path from escort to goal #%i in segment #%i.\n", Escort_goal_object, goal_seg));
851 if ((Escort_goal_index < 0) && (Escort_goal_index != -3)) { // I apologize for this statement -- MK, 09/22/95
852 if (Escort_goal_index == -1) {
853 Last_buddy_message_time = 0; // Force this message to get through.
854 buddy_message("No %s in mine.", Escort_goal_text[Escort_goal_object-1]);
855 Looking_for_marker = -1;
856 } else if (Escort_goal_index == -2) {
857 Last_buddy_message_time = 0; // Force this message to get through.
858 buddy_message("Can't reach %s.", Escort_goal_text[Escort_goal_object-1]);
859 Looking_for_marker = -1;
863 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
864 Escort_special_goal = -1;
866 if (goal_seg == -3) {
867 create_n_segment_path(objp, 16 + d_rand() * 16, -1);
868 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
870 create_path_to_segment(objp, goal_seg, Max_escort_length, 1); // MK!: Last parm (safety_flag) used to be 1!!
871 if (aip->path_length > 3)
872 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
873 if ((aip->path_length > 0) && (Point_segs[aip->hide_index + aip->path_length - 1].segnum != goal_seg)) {
875 Last_buddy_message_time = 0; // Force this message to get through.
876 buddy_message("Can't reach %s.", Escort_goal_text[Escort_goal_object-1]);
877 Looking_for_marker = -1;
878 Escort_goal_object = ESCORT_GOAL_SCRAM;
879 dist_to_player = find_connected_distance(&objp->pos, objp->segnum, &Believed_player_pos, Believed_player_seg, 100, WID_FLY_FLAG);
880 if (dist_to_player > MIN_ESCORT_DISTANCE)
881 create_path_to_player(objp, Max_escort_length, 1); // MK!: Last parm used to be 1!
883 create_n_segment_path(objp, 8 + d_rand() * 8, -1);
884 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
889 ailp->mode = AIM_GOTO_OBJECT;
891 say_escort_goal(Escort_goal_object);
896 // -----------------------------------------------------------------------------
897 // Escort robot chooses goal object based on player's keys, location.
898 // Returns goal object.
899 int escort_set_goal_object(void)
901 if (Escort_special_goal != -1)
902 return ESCORT_GOAL_UNSPECIFIED;
903 else if (!(ConsoleObject->flags & PLAYER_FLAGS_BLUE_KEY) && (exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_BLUE, -1) != -1))
904 return ESCORT_GOAL_BLUE_KEY;
905 else if (!(ConsoleObject->flags & PLAYER_FLAGS_GOLD_KEY) && (exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_GOLD, -1) != -1))
906 return ESCORT_GOAL_GOLD_KEY;
907 else if (!(ConsoleObject->flags & PLAYER_FLAGS_RED_KEY) && (exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_RED, -1) != -1))
908 return ESCORT_GOAL_RED_KEY;
909 else if (Control_center_destroyed == 0) {
910 if (Num_boss_teleport_segs)
911 return ESCORT_GOAL_BOSS;
913 return ESCORT_GOAL_CONTROLCEN;
915 return ESCORT_GOAL_EXIT;
919 #define MAX_ESCORT_TIME_AWAY (F1_0*4)
921 fix Buddy_last_seen_player = 0, Buddy_last_player_path_created;
923 // -----------------------------------------------------------------------------
924 int time_to_visit_player(object *objp, ai_local *ailp, ai_static *aip)
926 // Note: This one has highest priority because, even if already going towards player,
927 // might be necessary to create a new path, as player can move.
928 if (GameTime - Buddy_last_seen_player > MAX_ESCORT_TIME_AWAY)
929 if (GameTime - Buddy_last_player_path_created > F1_0)
932 if (ailp->mode == AIM_GOTO_PLAYER)
935 if (objp->segnum == ConsoleObject->segnum)
938 if (aip->cur_path_index < aip->path_length/2)
945 int Buddy_dude_cheat;
946 fix Last_come_back_message_time = 0;
948 fix Buddy_last_missile_time;
950 // -----------------------------------------------------------------------------
951 void bash_buddy_weapon_info(int weapon_objnum)
953 object *objp = &Objects[weapon_objnum];
955 objp->ctype.laser_info.parent_num = ConsoleObject-Objects;
956 objp->ctype.laser_info.parent_type = OBJ_PLAYER;
957 objp->ctype.laser_info.parent_signature = ConsoleObject->signature;
960 // -----------------------------------------------------------------------------
961 int maybe_buddy_fire_mega(int objnum)
963 object *objp = &Objects[objnum];
964 object *buddy_objp = &Objects[Buddy_objnum];
966 vms_vector vec_to_robot;
969 vm_vec_sub(&vec_to_robot, &buddy_objp->pos, &objp->pos);
970 dist = vm_vec_normalize_quick(&vec_to_robot);
975 dot = vm_vec_dot(&vec_to_robot, &buddy_objp->orient.fvec);
980 if (!object_to_object_visibility(buddy_objp, objp, FQ_TRANSWALL))
983 if (Weapon_info[MEGA_ID].render_type == 0) {
984 con_printf(CON_VERBOSE, "Buddy can't fire mega (shareware)\n");
985 buddy_message("CLICK!");
989 mprintf((0, "Buddy firing mega in frame %i\n", FrameCount));
991 buddy_message("GAHOOGA!");
993 weapon_objnum = Laser_create_new_easy( &buddy_objp->orient.fvec, &buddy_objp->pos, objnum, MEGA_ID, 1);
995 if (weapon_objnum != -1)
996 bash_buddy_weapon_info(weapon_objnum);
1001 //-----------------------------------------------------------------------------
1002 int maybe_buddy_fire_smart(int objnum)
1004 object *objp = &Objects[objnum];
1005 object *buddy_objp = &Objects[Buddy_objnum];
1009 dist = vm_vec_dist_quick(&buddy_objp->pos, &objp->pos);
1014 if (!object_to_object_visibility(buddy_objp, objp, FQ_TRANSWALL))
1017 mprintf((0, "Buddy firing smart missile in frame %i\n", FrameCount));
1019 buddy_message("WHAMMO!");
1021 weapon_objnum = Laser_create_new_easy( &buddy_objp->orient.fvec, &buddy_objp->pos, objnum, SMART_ID, 1);
1023 if (weapon_objnum != -1)
1024 bash_buddy_weapon_info(weapon_objnum);
1029 // -----------------------------------------------------------------------------
1030 void do_buddy_dude_stuff(void)
1034 if (!ok_for_buddy_to_talk())
1037 if (Buddy_last_missile_time > GameTime)
1038 Buddy_last_missile_time = 0;
1040 if (Buddy_last_missile_time + F1_0*2 < GameTime) {
1041 // See if a robot potentially in view cone
1042 for (i=0; i<=Highest_object_index; i++)
1043 if ((Objects[i].type == OBJ_ROBOT) && !Robot_info[Objects[i].id].companion)
1044 if (maybe_buddy_fire_mega(i)) {
1045 Buddy_last_missile_time = GameTime;
1049 // See if a robot near enough that buddy should fire smart missile
1050 for (i=0; i<=Highest_object_index; i++)
1051 if ((Objects[i].type == OBJ_ROBOT) && !Robot_info[Objects[i].id].companion)
1052 if (maybe_buddy_fire_smart(i)) {
1053 Buddy_last_missile_time = GameTime;
1060 // -----------------------------------------------------------------------------
1061 // Called every frame (or something).
1062 void do_escort_frame(object *objp, fix dist_to_player, int player_visibility)
1064 int objnum = objp-Objects;
1065 ai_static *aip = &objp->ctype.ai_info;
1066 ai_local *ailp = &Ai_local_info[objnum];
1068 Buddy_objnum = objp-Objects;
1070 if (player_visibility) {
1071 Buddy_last_seen_player = GameTime;
1072 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
1073 if (f2i(Players[Player_num].energy) < 40)
1074 if ((f2i(Players[Player_num].energy)/2) & 2)
1075 if (!Player_is_dead)
1076 buddy_message("Hey, your headlight's on!");
1080 if (Buddy_dude_cheat)
1081 do_buddy_dude_stuff();
1083 if (Buddy_sorry_time + F1_0 > GameTime) {
1084 Last_buddy_message_time = 0; // Force this message to get through.
1085 if (Buddy_sorry_time < GameTime + F1_0*2)
1086 buddy_message("Oops, sorry 'bout that...");
1087 Buddy_sorry_time = -F1_0*2;
1090 // If buddy not allowed to talk, then he is locked in his room. Make him mostly do nothing unless you're nearby.
1091 if (!Buddy_allowed_to_talk)
1092 if (dist_to_player > F1_0*100)
1093 aip->SKIP_AI_COUNT = (F1_0/4)/FrameTime;
1095 // -- mprintf((0, "%10s: Dist to player = %7.3f, segnum = %4i\n", mode_text[ailp->mode], f2fl(dist_to_player), objp->segnum));
1097 // AIM_WANDER has been co-opted for buddy behavior (didn't want to modify aistruct.h)
1098 // It means the object has been told to get lost and has come to the end of its path.
1099 // If the player is now visible, then create a path.
1100 if (ailp->mode == AIM_WANDER)
1101 if (player_visibility) {
1102 // -- mprintf((0, "Buddy: Going from wander to path following!\n"));
1103 create_n_segment_path(objp, 16 + d_rand() * 16, -1);
1104 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1107 if (Escort_special_goal == ESCORT_GOAL_SCRAM) {
1108 if (player_visibility)
1109 if (Escort_last_path_created + F1_0*3 < GameTime) {
1110 mprintf((0, "Frame %i: Buddy creating new scram path.\n", FrameCount));
1111 create_n_segment_path(objp, 10 + d_rand() * 16, ConsoleObject->segnum);
1112 Escort_last_path_created = GameTime;
1116 // -- mprintf((0, "Buddy: Seg = %3i, dist = %7.3f\n", objp->segnum, f2fl(dist_to_player)));
1120 // Force checking for new goal every 5 seconds, and create new path, if necessary.
1121 if (((Escort_special_goal != ESCORT_GOAL_SCRAM) && ((Escort_last_path_created + F1_0*5) < GameTime)) ||
1122 ((Escort_special_goal == ESCORT_GOAL_SCRAM) && ((Escort_last_path_created + F1_0*15) < GameTime))) {
1123 Escort_goal_object = ESCORT_GOAL_UNSPECIFIED;
1124 Escort_last_path_created = GameTime;
1127 if ((Escort_special_goal != ESCORT_GOAL_SCRAM) && time_to_visit_player(objp, ailp, aip)) {
1130 Buddy_last_player_path_created = GameTime;
1131 ailp->mode = AIM_GOTO_PLAYER;
1132 if (!player_visibility) {
1133 if ((Last_come_back_message_time + F1_0 < GameTime) || (Last_come_back_message_time > GameTime)) {
1134 buddy_message("Coming back to get you.");
1135 Last_come_back_message_time = GameTime;
1138 // No point in Buddy creating very long path if he's not allowed to talk. Really kills framerate.
1139 max_len = Max_escort_length;
1140 if (!Buddy_allowed_to_talk)
1142 create_path_to_player(objp, max_len, 1); // MK!: Last parm used to be 1!
1143 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1144 // -- mprintf((0, "Creating path to player, length = %i\n", aip->path_length));
1145 ailp->mode = AIM_GOTO_PLAYER;
1146 } else if (GameTime - Buddy_last_seen_player > MAX_ESCORT_TIME_AWAY) {
1147 // This is to prevent buddy from looking for a goal, which he will do because we only allow path creation once/second.
1149 } else if ((ailp->mode == AIM_GOTO_PLAYER) && (dist_to_player < MIN_ESCORT_DISTANCE)) {
1150 Escort_goal_object = escort_set_goal_object();
1151 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
1152 escort_create_path_to_goal(objp);
1153 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1154 // mprintf((0, "Creating path to goal, length = %i\n", aip->path_length));
1155 if (aip->path_length < 3) {
1156 create_n_segment_path(objp, 5, Believed_player_seg);
1157 // mprintf((0, "Path to goal has length %i, just wandering...\n", aip->path_length));
1159 ailp->mode = AIM_GOTO_OBJECT;
1160 } else if (Escort_goal_object == ESCORT_GOAL_UNSPECIFIED) {
1161 if ((ailp->mode != AIM_GOTO_PLAYER) || (dist_to_player < MIN_ESCORT_DISTANCE)) {
1162 Escort_goal_object = escort_set_goal_object();
1163 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
1164 escort_create_path_to_goal(objp);
1165 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1166 // mprintf((0, "Creating path to goal, length = %i\n", aip->path_length));
1167 if (aip->path_length < 3) {
1168 create_n_segment_path(objp, 5, Believed_player_seg);
1169 // mprintf((0, "Path to goal has length %i, just wandering...\n", aip->path_length));
1171 ailp->mode = AIM_GOTO_OBJECT;
1174 ; // mprintf((0, "!"));
1178 void invalidate_escort_goal(void)
1180 Escort_goal_object = -1;
1183 // -------------------------------------------------------------------------------------------------
1184 void do_snipe_frame(object *objp, fix dist_to_player, int player_visibility, vms_vector *vec_to_player)
1186 int objnum = objp-Objects;
1187 ai_local *ailp = &Ai_local_info[objnum];
1188 fix connected_distance;
1190 if (dist_to_player > F1_0*500)
1193 // -- mprintf((0, "Mode: %10s, Dist: %7.3f\n", mode_text[ailp->mode], f2fl(dist_to_player)));
1195 switch (ailp->mode) {
1196 case AIM_SNIPE_WAIT:
1197 if ((dist_to_player > F1_0*50) && (ailp->next_action_time > 0))
1200 ailp->next_action_time = SNIPE_WAIT_TIME;
1202 connected_distance = find_connected_distance(&objp->pos, objp->segnum, &Believed_player_pos, Believed_player_seg, 30, WID_FLY_FLAG);
1203 if (connected_distance < F1_0*500) {
1204 // -- mprintf((0, "Object #%i entering attack mode.\n", objnum));
1205 create_path_to_player(objp, 30, 1);
1206 ailp->mode = AIM_SNIPE_ATTACK;
1207 ailp->next_action_time = SNIPE_ATTACK_TIME; // have up to 10 seconds to find player.
1211 case AIM_SNIPE_RETREAT:
1212 case AIM_SNIPE_RETREAT_BACKWARDS:
1213 if (ailp->next_action_time < 0) {
1214 ailp->mode = AIM_SNIPE_WAIT;
1215 ailp->next_action_time = SNIPE_WAIT_TIME;
1216 // -- mprintf((0, "Object #%i going from retreat to wait.\n", objnum));
1217 } else if ((player_visibility == 0) || (ailp->next_action_time > SNIPE_ABORT_RETREAT_TIME)) {
1218 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1219 ailp->mode = AIM_SNIPE_RETREAT_BACKWARDS;
1221 // -- mprintf((0, "Object #%i going from retreat to fire.\n", objnum));
1222 ailp->mode = AIM_SNIPE_FIRE;
1223 ailp->next_action_time = SNIPE_FIRE_TIME/2;
1227 case AIM_SNIPE_ATTACK:
1228 if (ailp->next_action_time < 0) {
1229 // -- mprintf((0, "Object #%i timed out from attack to retreat mode.\n", objnum));
1230 ailp->mode = AIM_SNIPE_RETREAT;
1231 ailp->next_action_time = SNIPE_WAIT_TIME;
1233 // -- mprintf((0, "Object #%i attacking: visibility = %i\n", player_visibility));
1234 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1235 if (player_visibility) {
1236 ailp->mode = AIM_SNIPE_FIRE;
1237 ailp->next_action_time = SNIPE_FIRE_TIME;
1239 ailp->mode = AIM_SNIPE_ATTACK;
1243 case AIM_SNIPE_FIRE:
1244 if (ailp->next_action_time < 0) {
1245 ai_static *aip = &objp->ctype.ai_info;
1246 // -- mprintf((0, "Object #%i going from fire to retreat.\n", objnum));
1247 create_n_segment_path(objp, 10 + d_rand()/2048, ConsoleObject->segnum);
1248 aip->path_length = polish_path(objp, &Point_segs[aip->hide_index], aip->path_length);
1249 if (d_rand() < 8192)
1250 ailp->mode = AIM_SNIPE_RETREAT_BACKWARDS;
1252 ailp->mode = AIM_SNIPE_RETREAT;
1253 ailp->next_action_time = SNIPE_RETREAT_TIME;
1259 Int3(); // Oops, illegal mode for snipe behavior.
1260 ailp->mode = AIM_SNIPE_ATTACK;
1261 ailp->next_action_time = F1_0;
1267 #define THIEF_DEPTH 20
1269 extern int pick_connected_segment(object *objp, int max_depth);
1271 // ------------------------------------------------------------------------------------------------------
1272 // Choose segment to recreate thief in.
1273 int choose_thief_recreation_segment(void)
1278 cur_drop_depth = THIEF_DEPTH;
1280 while ((segnum == -1) && (cur_drop_depth > THIEF_DEPTH/2)) {
1281 segnum = pick_connected_segment(&Objects[Players[Player_num].objnum], cur_drop_depth);
1282 if (Segment2s[segnum].special == SEGMENT_IS_CONTROLCEN)
1288 mprintf((1, "Warning: Unable to find a connected segment for thief recreation.\n"));
1289 return (d_rand() * Highest_segment_index) >> 15;
1295 extern object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id);
1297 fix Re_init_thief_time = 0x3f000000;
1299 // ----------------------------------------------------------------------
1300 void recreate_thief(object *objp)
1303 vms_vector center_point;
1306 segnum = choose_thief_recreation_segment();
1307 compute_segment_center(¢er_point, &Segments[segnum]);
1309 new_obj = create_morph_robot( &Segments[segnum], ¢er_point, objp->id);
1310 init_ai_object(new_obj-Objects, AIB_SNIPE, -1);
1311 Re_init_thief_time = GameTime + F1_0*10; // In 10 seconds, re-initialize thief.
1314 // ----------------------------------------------------------------------------
1315 #define THIEF_ATTACK_TIME (F1_0*10)
1317 fix Thief_wait_times[NDL] = {F1_0*30, F1_0*25, F1_0*20, F1_0*15, F1_0*10};
1319 // -------------------------------------------------------------------------------------------------
1320 void do_thief_frame(object *objp, fix dist_to_player, int player_visibility, vms_vector *vec_to_player)
1322 int objnum = objp-Objects;
1323 ai_local *ailp = &Ai_local_info[objnum];
1324 fix connected_distance;
1326 // -- mprintf((0, "%10s: Action Time: %7.3f\n", mode_text[ailp->mode], f2fl(ailp->next_action_time)));
1328 if ((Current_level_num < 0) && (Re_init_thief_time < GameTime)) {
1329 if (Re_init_thief_time > GameTime - F1_0*2)
1330 init_thief_for_level();
1331 Re_init_thief_time = 0x3f000000;
1334 if ((dist_to_player > F1_0*500) && (ailp->next_action_time > 0))
1338 ailp->mode = AIM_THIEF_RETREAT;
1340 switch (ailp->mode) {
1341 case AIM_THIEF_WAIT:
1342 // -- mprintf((0, "WAIT\n"));
1344 if (ailp->player_awareness_type >= PA_PLAYER_COLLISION) {
1345 ailp->player_awareness_type = 0;
1346 // -- mprintf((0, "Thief: Awareness = %i ", ailp->player_awareness_type));
1348 // -- mprintf((0, "ATTACK\n"));
1349 create_path_to_player(objp, 30, 1);
1350 ailp->mode = AIM_THIEF_ATTACK;
1351 ailp->next_action_time = THIEF_ATTACK_TIME/2;
1353 } else if (player_visibility) {
1354 // -- mprintf((0, "RETREAT\n"));
1355 create_n_segment_path(objp, 15, ConsoleObject->segnum);
1356 ailp->mode = AIM_THIEF_RETREAT;
1360 if ((dist_to_player > F1_0*50) && (ailp->next_action_time > 0))
1363 ailp->next_action_time = Thief_wait_times[Difficulty_level]/2;
1365 connected_distance = find_connected_distance(&objp->pos, objp->segnum, &Believed_player_pos, Believed_player_seg, 30, WID_FLY_FLAG);
1366 if (connected_distance < F1_0*500) {
1367 // -- mprintf((0, "Thief creating path to player.\n", objnum));
1368 create_path_to_player(objp, 30, 1);
1369 ailp->mode = AIM_THIEF_ATTACK;
1370 ailp->next_action_time = THIEF_ATTACK_TIME; // have up to 10 seconds to find player.
1375 case AIM_THIEF_RETREAT:
1376 // -- mprintf((0, "RETREAT\n"));
1378 if (ailp->next_action_time < 0) {
1379 ailp->mode = AIM_THIEF_WAIT;
1380 ailp->next_action_time = Thief_wait_times[Difficulty_level];
1381 } else if ((dist_to_player < F1_0*100) || player_visibility || (ailp->player_awareness_type >= PA_PLAYER_COLLISION)) {
1382 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1383 if ((dist_to_player < F1_0*100) || (ailp->player_awareness_type >= PA_PLAYER_COLLISION)) {
1384 ai_static *aip = &objp->ctype.ai_info;
1385 if (((aip->cur_path_index <=1) && (aip->PATH_DIR == -1)) || ((aip->cur_path_index >= aip->path_length-1) && (aip->PATH_DIR == 1))) {
1386 ailp->player_awareness_type = 0;
1387 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1389 // If path is real short, try again, allowing to go through player's segment
1390 if (aip->path_length < 4) {
1391 // -- mprintf((0, "Thief is cornered. Willing to fly through player.\n"));
1392 create_n_segment_path(objp, 10, -1);
1393 } else if (objp->shields* 4 < Robot_info[objp->id].strength) {
1394 // If robot really low on hits, will run through player with even longer path
1395 if (aip->path_length < 8) {
1396 create_n_segment_path(objp, 10, -1);
1400 ailp->mode = AIM_THIEF_RETREAT;
1401 // -- mprintf((0, "Thief creating new RETREAT path.\n"));
1404 ailp->mode = AIM_THIEF_RETREAT;
1410 // This means the thief goes from wherever he is to the player.
1411 // Note: When thief successfully steals something, his action time is forced negative and his mode is changed
1412 // to retreat to get him out of attack mode.
1413 case AIM_THIEF_ATTACK:
1414 // -- mprintf((0, "ATTACK\n"));
1416 if (ailp->player_awareness_type >= PA_PLAYER_COLLISION) {
1417 ailp->player_awareness_type = 0;
1418 if (d_rand() > 8192) {
1419 // --- mprintf((0, "RETREAT!!\n"));
1420 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1421 Ai_local_info[objp-Objects].next_action_time = Thief_wait_times[Difficulty_level]/2;
1422 Ai_local_info[objp-Objects].mode = AIM_THIEF_RETREAT;
1424 } else if (ailp->next_action_time < 0) {
1425 // This forces him to create a new path every second.
1426 ailp->next_action_time = F1_0;
1427 create_path_to_player(objp, 100, 0);
1428 ailp->mode = AIM_THIEF_ATTACK;
1429 // -- mprintf((0, "Creating path to player.\n"));
1431 if (player_visibility && (dist_to_player < F1_0*100)) {
1432 // If the player is close to looking at the thief, thief shall run away.
1433 // No more stupid thief trying to sneak up on you when you're looking right at him!
1434 if (dist_to_player > F1_0*60) {
1435 fix dot = vm_vec_dot(vec_to_player, &ConsoleObject->orient.fvec);
1436 if (dot < -F1_0/2) { // Looking at least towards thief, so thief will run!
1437 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1438 Ai_local_info[objp-Objects].next_action_time = Thief_wait_times[Difficulty_level]/2;
1439 Ai_local_info[objp-Objects].mode = AIM_THIEF_RETREAT;
1442 ai_turn_towards_vector(vec_to_player, objp, F1_0/4);
1443 move_towards_player(objp, vec_to_player);
1445 ai_static *aip = &objp->ctype.ai_info;
1446 // If path length == 0, then he will keep trying to create path, but he is probably stuck in his closet.
1447 if ((aip->path_length > 1) || ((FrameCount & 0x0f) == 0)) {
1448 ai_follow_path(objp, player_visibility, player_visibility, vec_to_player);
1449 ailp->mode = AIM_THIEF_ATTACK;
1456 mprintf ((0,"Thief mode (broken) = %d\n",ailp->mode));
1457 // -- Int3(); // Oops, illegal mode for thief behavior.
1458 ailp->mode = AIM_THIEF_ATTACK;
1459 ailp->next_action_time = F1_0;
1465 // ----------------------------------------------------------------------------
1466 // Return true if this item (whose presence is indicated by Players[player_num].flags) gets stolen.
1467 int maybe_steal_flag_item(int player_num, int flagval)
1469 if (Players[player_num].flags & flagval) {
1470 if (d_rand() < THIEF_PROBABILITY) {
1471 int powerup_index=-1;
1472 Players[player_num].flags &= (~flagval);
1473 // -- mprintf((0, "You lost your %4x capability!\n", flagval));
1475 case PLAYER_FLAGS_INVULNERABLE:
1476 powerup_index = POW_INVULNERABILITY;
1477 thief_message("Invulnerability stolen!");
1479 case PLAYER_FLAGS_CLOAKED:
1480 powerup_index = POW_CLOAK;
1481 thief_message("Cloak stolen!");
1483 case PLAYER_FLAGS_MAP_ALL:
1484 powerup_index = POW_FULL_MAP;
1485 thief_message("Full map stolen!");
1487 case PLAYER_FLAGS_QUAD_LASERS:
1488 powerup_index = POW_QUAD_FIRE;
1489 thief_message("Quad lasers stolen!");
1491 case PLAYER_FLAGS_AFTERBURNER:
1492 powerup_index = POW_AFTERBURNER;
1493 thief_message("Afterburner stolen!");
1495 // -- case PLAYER_FLAGS_AMMO_RACK:
1496 // -- powerup_index = POW_AMMO_RACK;
1497 // -- thief_message("Ammo Rack stolen!");
1499 case PLAYER_FLAGS_CONVERTER:
1500 powerup_index = POW_CONVERTER;
1501 thief_message("Converter stolen!");
1503 case PLAYER_FLAGS_HEADLIGHT:
1504 powerup_index = POW_HEADLIGHT;
1505 thief_message("Headlight stolen!");
1506 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
1509 Assert(powerup_index != -1);
1510 Stolen_items[Stolen_item_index] = powerup_index;
1512 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1520 // ----------------------------------------------------------------------------
1521 int maybe_steal_secondary_weapon(int player_num, int weapon_num)
1523 if ((Players[player_num].secondary_weapon_flags & HAS_FLAG(weapon_num)) && Players[player_num].secondary_ammo[weapon_num])
1524 if (d_rand() < THIEF_PROBABILITY) {
1525 if (weapon_num == PROXIMITY_INDEX)
1526 if (d_rand() > 8192) // Come in groups of 4, only add 1/4 of time.
1528 Players[player_num].secondary_ammo[weapon_num]--;
1530 // Smart mines and proxbombs don't get dropped because they only come in 4 packs.
1531 if ((weapon_num != PROXIMITY_INDEX) && (weapon_num != SMART_MINE_INDEX)) {
1532 Stolen_items[Stolen_item_index] = Secondary_weapon_to_powerup[weapon_num];
1535 thief_message("%s stolen!", Text_string[114+weapon_num]); // Danger! Danger! Use of literal! Danger!
1536 if (Players[Player_num].secondary_ammo[weapon_num] == 0)
1537 auto_select_weapon(1);
1539 // -- compress_stolen_items();
1540 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1547 // ----------------------------------------------------------------------------
1548 int maybe_steal_primary_weapon(int player_num, int weapon_num)
1550 if ((Players[player_num].primary_weapon_flags & HAS_FLAG(weapon_num)) && Players[player_num].primary_ammo[weapon_num]) {
1551 if (d_rand() < THIEF_PROBABILITY) {
1552 if (weapon_num == 0) {
1553 if (Players[player_num].laser_level > 0) {
1554 if (Players[player_num].laser_level > 3) {
1555 Stolen_items[Stolen_item_index] = POW_SUPER_LASER;
1557 Stolen_items[Stolen_item_index] = Primary_weapon_to_powerup[weapon_num];
1559 thief_message("%s level decreased!", Text_string[104+weapon_num]); // Danger! Danger! Use of literal! Danger!
1560 Players[player_num].laser_level--;
1561 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1564 } else if (Players[player_num].primary_weapon_flags & (1 << weapon_num)) {
1565 Players[player_num].primary_weapon_flags &= ~(1 << weapon_num);
1566 Stolen_items[Stolen_item_index] = Primary_weapon_to_powerup[weapon_num];
1568 thief_message("%s stolen!", Text_string[104+weapon_num]); // Danger! Danger! Use of literal! Danger!
1569 auto_select_weapon(0);
1570 digi_play_sample_once(SOUND_WEAPON_STOLEN, F1_0);
1581 // ----------------------------------------------------------------------------
1582 // Called for a thief-type robot.
1583 // If a item successfully stolen, returns true, else returns false.
1584 // If a wapon successfully stolen, do everything, removing it from player,
1585 // updating Stolen_items information, deselecting, etc.
1586 int attempt_to_steal_item_3(object *objp, int player_num)
1590 if (Ai_local_info[objp-Objects].mode != AIM_THIEF_ATTACK)
1593 // First, try to steal equipped items.
1595 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_INVULNERABLE))
1598 // If primary weapon = laser, first try to rip away those nasty quad lasers!
1599 if (Primary_weapon == 0)
1600 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_QUAD_LASERS))
1603 // Makes it more likely to steal primary than secondary.
1605 if (maybe_steal_primary_weapon(player_num, Primary_weapon))
1608 if (maybe_steal_secondary_weapon(player_num, Secondary_weapon))
1611 // See what the player has and try to snag something.
1612 // Try best things first.
1613 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_INVULNERABLE))
1615 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_CLOAKED))
1617 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_QUAD_LASERS))
1619 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_AFTERBURNER))
1621 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_CONVERTER))
1623 // -- 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?
1625 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_HEADLIGHT))
1627 if (maybe_steal_flag_item(player_num, PLAYER_FLAGS_MAP_ALL))
1630 for (i=MAX_SECONDARY_WEAPONS-1; i>=0; i--) {
1631 if (maybe_steal_primary_weapon(player_num, i))
1633 if (maybe_steal_secondary_weapon(player_num, i))
1640 // ----------------------------------------------------------------------------
1641 int attempt_to_steal_item_2(object *objp, int player_num)
1645 rval = attempt_to_steal_item_3(objp, player_num);
1648 Stolen_item_index = (Stolen_item_index+1) % MAX_STOLEN_ITEMS;
1649 if (d_rand() > 20000) // Occasionally, boost the value again
1650 Stolen_item_index = (Stolen_item_index+1) % MAX_STOLEN_ITEMS;
1656 // ----------------------------------------------------------------------------
1657 // Called for a thief-type robot.
1658 // If a item successfully stolen, returns true, else returns false.
1659 // If a wapon successfully stolen, do everything, removing it from player,
1660 // updating Stolen_items information, deselecting, etc.
1661 int attempt_to_steal_item(object *objp, int player_num)
1666 if (objp->ctype.ai_info.dying_start_time)
1669 rval += attempt_to_steal_item_2(objp, player_num);
1671 for (i=0; i<3; i++) {
1672 if (!rval || (d_rand() < 11000)) { // about 1/3 of time, steal another item
1673 rval += attempt_to_steal_item_2(objp, player_num);
1677 // -- mprintf((0, "%i items were stolen!\n", rval));
1679 create_n_segment_path(objp, 10, ConsoleObject->segnum);
1680 Ai_local_info[objp-Objects].next_action_time = Thief_wait_times[Difficulty_level]/2;
1681 Ai_local_info[objp-Objects].mode = AIM_THIEF_RETREAT;
1683 PALETTE_FLASH_ADD(30, 15, -20);
1684 update_laser_weapon_info();
1685 // digi_link_sound_to_pos( SOUND_NASTY_ROBOT_HIT_1, objp->segnum, 0, &objp->pos, 0 , DEFAULT_ROBOT_SOUND_VOLUME);
1686 // I removed this to make the "steal sound" more obvious -AP
1688 if (Game_mode & GM_NETWORK)
1689 multi_send_stolen_items();
1695 // --------------------------------------------------------------------------------------------------------------
1696 // Indicate no items have been stolen.
1697 void init_thief_for_level(void)
1701 for (i=0; i<MAX_STOLEN_ITEMS; i++)
1702 Stolen_items[i] = 255;
1704 Assert (MAX_STOLEN_ITEMS >= 3*2); // Oops! Loop below will overwrite memory!
1706 if (!(Game_mode & GM_MULTI))
1707 for (i=0; i<3; i++) {
1708 Stolen_items[2*i] = POW_SHIELD_BOOST;
1709 Stolen_items[2*i+1] = POW_ENERGY;
1712 Stolen_item_index = 0;
1715 // --------------------------------------------------------------------------------------------------------------
1716 void drop_stolen_items(object *objp)
1720 mprintf ((0,"Dropping thief items!\n"));
1722 // -- compress_stolen_items();
1724 for (i=0; i<MAX_STOLEN_ITEMS; i++) {
1725 if (Stolen_items[i] != 255)
1726 drop_powerup(OBJ_POWERUP, Stolen_items[i], 1, &objp->mtype.phys_info.velocity, &objp->pos, objp->segnum);
1727 Stolen_items[i] = 255;
1732 // --------------------------------------------------------------------------------------------------------------
1733 void do_escort_menu(void)
1740 char goal_str[32], tstr[32];
1742 if (Game_mode & GM_MULTI) {
1743 HUD_init_message("No Guide-Bot in Multiplayer!");
1747 for (i=0; i<=Highest_object_index; i++) {
1748 if (Objects[i].type == OBJ_ROBOT)
1749 if (Robot_info[Objects[i].id].companion)
1753 if (i > Highest_object_index) {
1755 HUD_init_message("No Guide-Bot present in mine!");
1758 // If no buddy bot, create one!
1759 HUD_init_message("Debug Version: Creating Guide-Bot!");
1766 ok_for_buddy_to_talk(); // Needed here or we might not know buddy can talk when he can.
1768 if (!Buddy_allowed_to_talk) {
1769 HUD_init_message("%s has not been released",guidebot_name);
1773 digi_pause_digi_sounds();
1777 apply_modified_palette();
1778 reset_palette_add();
1780 game_flush_inputs();
1784 // set_screen_mode( SCREEN_MENU );
1786 gr_palette_load( gr_palette );
1788 // This prevents the buddy from coming back if you've told him to scram.
1789 // If we don't set next_goal, we get garbage there.
1790 if (Escort_special_goal == ESCORT_GOAL_SCRAM) {
1791 Escort_special_goal = -1; // Else setting next goal might fail.
1792 next_goal = escort_set_goal_object();
1793 Escort_special_goal = ESCORT_GOAL_SCRAM;
1795 Escort_special_goal = -1; // Else setting next goal might fail.
1796 next_goal = escort_set_goal_object();
1799 switch (next_goal) {
1801 case ESCORT_GOAL_UNSPECIFIED:
1803 sprintf(goal_str, "ERROR");
1807 case ESCORT_GOAL_BLUE_KEY:
1808 sprintf(goal_str, "blue key");
1810 case ESCORT_GOAL_GOLD_KEY:
1811 sprintf(goal_str, "yellow key");
1813 case ESCORT_GOAL_RED_KEY:
1814 sprintf(goal_str, "red key");
1816 case ESCORT_GOAL_CONTROLCEN:
1817 sprintf(goal_str, "reactor");
1819 case ESCORT_GOAL_BOSS:
1820 sprintf(goal_str, "boss");
1822 case ESCORT_GOAL_EXIT:
1823 sprintf(goal_str, "exit");
1825 case ESCORT_GOAL_MARKER1:
1826 case ESCORT_GOAL_MARKER2:
1827 case ESCORT_GOAL_MARKER3:
1828 case ESCORT_GOAL_MARKER4:
1829 case ESCORT_GOAL_MARKER5:
1830 case ESCORT_GOAL_MARKER6:
1831 case ESCORT_GOAL_MARKER7:
1832 case ESCORT_GOAL_MARKER8:
1833 case ESCORT_GOAL_MARKER9:
1834 sprintf(goal_str, "marker %i", next_goal-ESCORT_GOAL_MARKER1+1);
1839 if (!Buddy_messages_suppressed)
1840 sprintf(tstr, "Suppress");
1842 sprintf(tstr, "Enable");
1844 sprintf(msg, "Select Guide-Bot Command:\n\n"
1845 "0. Next Goal: %s" CC_LSPACING_S "3\n"
1846 "\x84. Find Energy Powerup" CC_LSPACING_S "3\n"
1847 "2. Find Energy Center" CC_LSPACING_S "3\n"
1848 "3. Find Shield Powerup" CC_LSPACING_S "3\n"
1849 "4. Find Any Powerup" CC_LSPACING_S "3\n"
1850 "5. Find a Robot" CC_LSPACING_S "3\n"
1851 "6. Find a Hostage" CC_LSPACING_S "3\n"
1852 "7. Stay Away From Me" CC_LSPACING_S "3\n"
1853 "8. Find My Powerups" CC_LSPACING_S "3\n"
1854 "9. Find the exit\n\n"
1856 // -- "9. Find the exit" CC_LSPACING_S "3\n"
1859 show_escort_menu(msg); //TXT_PAUSE);
1863 while (!(key = key_inkey()))
1866 DoMessageStuff(&wmsg);
1883 Looking_for_marker = -1;
1884 Last_buddy_key = -1;
1885 set_escort_special_goal(key);
1886 Last_buddy_key = -1;
1892 clear_boxed_message();
1896 //--10/08/95-- Screwed up font, background. Why needed, anyway?
1897 //--10/08/95-- case KEY_F1:
1898 //--10/08/95-- clear_boxed_message();
1899 //--10/08/95-- do_show_help();
1900 //--10/08/95-- show_boxed_message(msg);
1901 //--10/08/95-- break;
1903 case KEY_PRINT_SCREEN:
1904 save_screen_shot(0);
1908 case KEY_BACKSP: Int3(); break;
1915 temp = !Buddy_messages_suppressed;
1918 strcpy(msg, "suppressed");
1920 strcpy(msg, "enabled");
1922 Buddy_messages_suppressed = 1;
1923 buddy_message("Messages %s.", msg);
1925 Buddy_messages_suppressed = temp;
1938 game_flush_inputs();
1943 digi_resume_digi_sounds();
1947 // -------------------------------------------------------------------------------
1948 // Show the Buddy menu!
1949 void show_escort_menu(char *msg)
1956 dd_gr_set_current_canvas(&dd_VR_screen_pages[0]),
1957 gr_set_current_canvas(&VR_screen_pages[0])
1960 gr_set_curfont( GAME_FONT );
1962 gr_get_string_size(msg,&w,&h,&aw);
1964 x = (grd_curscreen->sc_w-w)/2;
1965 y = (grd_curscreen->sc_h-h)/4;
1967 gr_set_fontcolor( gr_getcolor(0, 28, 0), -1 );
1969 PA_DFX (pa_set_frontbuffer_current());
1970 PA_DFX (nm_draw_background(x-15,y-15,x+w+15-1,y+h+15-1));
1971 PA_DFX (pa_set_backbuffer_current());
1972 nm_draw_background(x-15,y-15,x+w+15-1,y+h+15-1);
1974 WIN(DDGRLOCK(dd_grd_curcanv));\
1975 PA_DFX (pa_set_frontbuffer_current());
1976 PA_DFX (gr_ustring( x, y, msg ));
1977 PA_DFX (pa_set_backbuffer_current());
1978 gr_ustring( x, y, msg );
1979 WIN(DDGRUNLOCK(dd_grd_curcanv));