1 /* $Id: multibot.c,v 1.7 2004-08-01 16:28:33 schaffner 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.
17 * Multiplayer robot code
58 int multi_add_controlled_robot(int objnum, int agitation);
59 void multi_send_release_robot(int objnum);
60 void multi_delete_controlled_robot(int objnum);
61 void multi_send_robot_position_sub(int objnum);
64 // Code for controlling robots in multiplayer games
68 #define STANDARD_EXPL_DELAY (F1_0/4)
69 #define MIN_CONTROL_TIME F1_0*1
70 #define ROBOT_TIMEOUT F1_0*2
73 #define MAX_TO_DELETE 61
75 int robot_controlled[MAX_ROBOTS_CONTROLLED];
76 int robot_agitation[MAX_ROBOTS_CONTROLLED];
77 fix robot_controlled_time[MAX_ROBOTS_CONTROLLED];
78 fix robot_last_send_time[MAX_ROBOTS_CONTROLLED];
79 fix robot_last_message_time[MAX_ROBOTS_CONTROLLED];
80 int robot_send_pending[MAX_ROBOTS_CONTROLLED];
81 int robot_fired[MAX_ROBOTS_CONTROLLED];
82 sbyte robot_fire_buf[MAX_ROBOTS_CONTROLLED][18+3];
84 #define MULTI_ROBOT_PRIORITY(objnum, pnum) (((objnum % 4) + pnum) % N_players)
86 extern void multi_send_stolen_items();
87 extern int multi_powerup_is_allowed (int);
89 //#define MULTI_ROBOT_PRIORITY(objnum, pnum) multi_robot_priority(objnum, pnum)
90 //int multi_robot_priority(int objnum, int pnum)
92 // return( ((objnum % 4) + pnum) % N_players);
96 multi_can_move_robot(int objnum, int agitation)
98 // Determine whether or not I am allowed to move this robot.
101 // Claim robot if necessary.
107 if ((objnum < 0) || (objnum > Highest_object_index))
113 else if (Objects[objnum].type != OBJ_ROBOT)
120 else if ((Robot_info[Objects[objnum].id].boss_flag) && (Boss_dying == 1))
123 else if (Objects[objnum].ctype.ai_info.REMOTE_OWNER == Player_num) // Already my robot!
125 int slot_num = Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM;
127 if ((slot_num < 0) || (slot_num >= MAX_ROBOTS_CONTROLLED))
129 mprintf ((0,"Not asserting in multi_can_move_robot!"));
133 if (robot_fired[slot_num]) {
134 // mprintf((0, "Preventing robot from firing again until firing complete!\n"));
138 robot_agitation[slot_num] = agitation;
139 robot_last_message_time[slot_num] = GameTime;
144 else if ((Objects[objnum].ctype.ai_info.REMOTE_OWNER != -1) || (agitation < MIN_TO_ADD))
146 if (agitation == ROBOT_FIRE_AGITATION) // Special case for firing at non-player
148 mprintf((0, "Shooting anyway.\n"));
149 rval = 1; // Try to fire at player even tho we're not in control!
155 rval = multi_add_controlled_robot(objnum, agitation);
161 multi_check_robot_timeout(void)
163 static fix lastcheck = 0;
166 if (GameTime > lastcheck + F1_0)
168 lastcheck = GameTime;
169 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
171 if ((robot_controlled[i] != -1) && (robot_last_send_time[i] + ROBOT_TIMEOUT < GameTime))
173 if (Objects[robot_controlled[i]].ctype.ai_info.REMOTE_OWNER != Player_num)
175 robot_controlled[i] = -1;
176 Int3(); // Non-terminal but Rob is interesting, step over please...
179 if (Objects[robot_controlled[i]].ctype.ai_info.REMOTE_OWNER !=Player_num)
181 mprintf ((0,"What? This ain't my bot and I'm trying to time it out!\n"));
184 mprintf((0, "Robot %d (slot %d) removed, timed out, frame %d.\n", robot_controlled[i], i, GameTime));
185 if (robot_send_pending[i])
186 multi_send_robot_position(robot_controlled[i], 1);
187 multi_send_release_robot(robot_controlled[i]);
188 // multi_delete_controlled_robot(robot_controlled[i]);
189 // robot_controlled[i] = -1;
196 multi_strip_robots(int playernum)
198 // Grab all robots away from a player
199 // (player died or exited the game)
203 if (Game_mode & GM_MULTI_ROBOTS) {
205 if (playernum == Player_num)
206 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
207 multi_delete_controlled_robot(robot_controlled[i]);
209 for (i = 1; i <= Highest_object_index; i++)
210 if ((Objects[i].type == OBJ_ROBOT) && (Objects[i].ctype.ai_info.REMOTE_OWNER == playernum)) {
211 Assert((Objects[i].control_type == CT_AI) || (Objects[i].control_type == CT_NONE) || (Objects[i].control_type == CT_MORPH));
212 Objects[i].ctype.ai_info.REMOTE_OWNER = -1;
213 if (playernum == Player_num)
214 Objects[i].ctype.ai_info.REMOTE_SLOT_NUM = 4;
216 Objects[i].ctype.ai_info.REMOTE_SLOT_NUM = 0;
219 // Note -- only call this with playernum == Player_num if all other players
220 // already know that we are clearing house. This does not send a release
221 // message for each controlled robot!!
226 multi_dump_robots(void)
229 // Dump robot control info for debug purposes
233 if (!(Game_mode & GM_MULTI_ROBOTS))
237 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
239 mprintf((0, "Robot %d) objnum=%d, anger=%d, last_message=%d, last move=%d, gametime=%d\n", i, robot_controlled[i], robot_agitation[i], robot_last_message_time[i], robot_last_send_time[i], GameTime));
244 multi_add_controlled_robot(int objnum, int agitation)
247 int lowest_agitation = 0x7fffffff; // MAX POSITIVE INT
248 int lowest_agitated_bot = -1;
249 int first_free_robot = -1;
251 // Try to add a new robot to the controlled list, return 1 if added, 0 if not.
253 if (Robot_info[Objects[objnum].id].boss_flag) // this is a boss, so make sure he gets a slot
254 agitation=(agitation*3)+Player_num;
256 if (Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM > 0)
258 mprintf((0, "Robot %d hands-off = %d.\n", objnum, Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM));
259 Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM -= 1;
263 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
265 if ((robot_controlled[i] == -1) || (Objects[robot_controlled[i]].type != OBJ_ROBOT)) {
266 first_free_robot = i;
270 if (robot_last_message_time[i] + ROBOT_TIMEOUT < GameTime) {
271 mprintf((0, "Robot %d replaced (timeout).\n", robot_controlled[i]));
272 if (robot_send_pending[i])
273 multi_send_robot_position(robot_controlled[i], 1);
274 multi_send_release_robot(robot_controlled[i]);
275 first_free_robot = i;
279 if ((robot_controlled[i] != -1) && (robot_agitation[i] < lowest_agitation) && (robot_controlled_time[i] + MIN_CONTROL_TIME < GameTime))
281 lowest_agitation = robot_agitation[i];
282 lowest_agitated_bot = i;
286 // mprintf ((0,"first_free_robot=%d lowest_agitated_bot=%d\n",first_free_robot,lowest_agitated_bot));
288 if (first_free_robot != -1) // Room left for new robots
289 i = first_free_robot;
291 else if ((agitation > lowest_agitation))// && (lowest_agitation <= MAX_TO_DELETE)) // Replace some old robot with a more agitated one
293 if (robot_send_pending[lowest_agitated_bot])
294 multi_send_robot_position(robot_controlled[lowest_agitated_bot], 1);
295 multi_send_release_robot(robot_controlled[lowest_agitated_bot]);
297 mprintf((0, "Replaced robot %d (agitation %d) with robot %d (agitation %d).\n", robot_controlled[lowest_agitated_bot], lowest_agitation, objnum, agitation));
299 i = lowest_agitated_bot;
302 // mprintf((0, "Cannot add robot %d agitation %d (min agitation %d)\n", objnum, agitation, lowest_agitation));
303 return(0); // Sorry, can't squeeze him in!
306 mprintf((0, "Taking control of robot %d, agitation %d.\n", objnum, agitation));
308 multi_send_claim_robot(objnum);
309 robot_controlled[i] = objnum;
310 robot_agitation[i] = agitation;
311 Objects[objnum].ctype.ai_info.REMOTE_OWNER = Player_num;
312 Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM = i;
313 robot_controlled_time[i] = GameTime;
314 robot_last_send_time[i] = robot_last_message_time[i] = GameTime;
319 multi_delete_controlled_robot(int objnum)
323 // Delete robot object number objnum from list of controlled robots because it is dead
325 if ( (objnum<0) || (objnum>Highest_object_index)) {
326 mprintf((0, "Trying to releasing control of bogus robot %d\n", objnum));
330 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
331 if (robot_controlled[i] == objnum)
334 if (i == MAX_ROBOTS_CONTROLLED)
337 mprintf((0, "Releasing control of robot %d\n", objnum));
339 if (Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM != i)
341 mprintf ((0,"Saved from asserting in multi_delete_controlled_bot!"));
342 Int3(); // can't release this bot!
346 Objects[objnum].ctype.ai_info.REMOTE_OWNER = -1;
347 Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
348 robot_controlled[i] = -1;
349 robot_send_pending[i] = 0;
354 multi_send_claim_robot(int objnum)
358 if ((objnum < 0) || (objnum > Highest_object_index))
364 if (Objects[objnum].type != OBJ_ROBOT)
370 // The AI tells us we should take control of this robot.
372 multibuf[0] = (char)MULTI_ROBOT_CLAIM;
373 multibuf[1] = Player_num;
374 s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[4]);
375 PUT_INTEL_SHORT(multibuf+2, s);
377 multi_send_data(multibuf, 5, 2);
378 multi_send_data(multibuf, 5, 2);
379 multi_send_data(multibuf, 5, 2);
384 multi_send_release_robot(int objnum)
388 if ((objnum < 0) || (objnum > Highest_object_index))
394 if (Objects[objnum].type != OBJ_ROBOT)
400 multi_delete_controlled_robot(objnum);
402 multibuf[0] = (char)MULTI_ROBOT_RELEASE;
403 multibuf[1] = Player_num;
404 s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[4]);
405 PUT_INTEL_SHORT(multibuf+2, s);
407 multi_send_data(multibuf, 5, 2);
408 multi_send_data(multibuf, 5, 2);
409 multi_send_data(multibuf, 5, 2);
412 #define MIN_ROBOT_COM_GAP F1_0/12
415 multi_send_robot_frame(int sent)
417 static int last_sent = 0;
422 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
424 int sending = (last_sent+1+i)%MAX_ROBOTS_CONTROLLED;
425 if ( (robot_controlled[sending] != -1) && ((robot_send_pending[sending] > sent) || (robot_fired[sending] > sent)) )
427 if (robot_send_pending[sending])
429 robot_send_pending[sending] = 0;
430 multi_send_robot_position_sub(robot_controlled[sending]);
433 if (robot_fired[sending])
435 robot_fired[sending] = 0;
436 multi_send_data((char *)robot_fire_buf[sending], 18, 1);
439 if (!(Game_mode & GM_NETWORK))
446 Assert((last_sent >= 0) && (last_sent <= MAX_ROBOTS_CONTROLLED));
451 multi_send_robot_position_sub(int objnum)
455 #ifdef WORDS_BIGENDIAN
459 // mprintf((0, "SENDPOS object %d, Gametime %d.\n", objnum, GameTime));
461 multibuf[loc] = MULTI_ROBOT_POSITION; loc += 1;
462 multibuf[loc] = Player_num; loc += 1;
463 s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]);
464 PUT_INTEL_SHORT(multibuf+loc, s);
467 #ifndef WORDS_BIGENDIAN
468 create_shortpos((shortpos *)(multibuf+loc), Objects+objnum,0); loc += sizeof(shortpos);
470 create_shortpos(&sp, Objects+objnum, 1);
471 memcpy(&(multibuf[loc]), (ubyte *)(sp.bytemat), 9);
473 memcpy(&(multibuf[loc]), (ubyte *)&(sp.xo), 14);
476 multi_send_data(multibuf, loc, 1);
480 multi_send_robot_position(int objnum, int force)
482 // Send robot position to other player(s). Includes a byte
483 // value describing whether or not they fired a weapon
485 if (!(Game_mode & GM_MULTI))
488 if ((objnum < 0) || (objnum > Highest_object_index))
493 if (Objects[objnum].type != OBJ_ROBOT)
499 if (Objects[objnum].ctype.ai_info.REMOTE_OWNER != Player_num)
502 // Objects[objnum].phys_info.drag = Robot_info[Objects[objnum].id].drag; // Set drag to normal
504 robot_last_send_time[Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM] = GameTime;
506 robot_send_pending[Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM] = 1+force;
508 if (force & (Game_mode & GM_NETWORK))
515 multi_send_robot_fire(int objnum, int gun_num, vms_vector *fire)
517 // Send robot fire event
520 #ifdef WORDS_BIGENDIAN
521 vms_vector swapped_vec;
524 multibuf[loc] = MULTI_ROBOT_FIRE; loc += 1;
525 multibuf[loc] = Player_num; loc += 1;
526 s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]);
527 PUT_INTEL_SHORT(multibuf+loc, s);
529 multibuf[loc] = gun_num; loc += 1;
530 #ifndef WORDS_BIGENDIAN
531 memcpy(multibuf+loc, fire, sizeof(vms_vector)); loc += sizeof(vms_vector); // 12
532 // --------------------------
535 swapped_vec.x = (fix)INTEL_INT((int)fire->x);
536 swapped_vec.y = (fix)INTEL_INT((int)fire->y);
537 swapped_vec.z = (fix)INTEL_INT((int)fire->z);
538 memcpy(multibuf+loc, &swapped_vec, sizeof(vms_vector)); loc += sizeof(vms_vector);
541 if (Objects[objnum].ctype.ai_info.REMOTE_OWNER == Player_num)
543 int slot = Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM;
544 if (slot<0 || slot>=MAX_ROBOTS_CONTROLLED)
546 mprintf ((0,"Saved from asserting in robofire\n"));
549 if (robot_fired[slot] != 0)
551 mprintf ((0,"Couldn't find an open slot for robo firing!\n"));
555 memcpy(robot_fire_buf[slot], multibuf, loc);
556 robot_fired[slot] = 1;
557 if (Game_mode & GM_NETWORK)
561 multi_send_data(multibuf, loc, 2); // Not our robot, send ASAP
565 multi_send_robot_explode(int objnum, int killer,char isthief)
567 // Send robot explosion event to the other players
572 multibuf[loc] = MULTI_ROBOT_EXPLODE; loc += 1;
573 multibuf[loc] = Player_num; loc += 1;
574 s = (short)objnum_local_to_remote(killer, (sbyte *)&multibuf[loc+2]);
575 PUT_INTEL_SHORT(multibuf+loc, s); loc += 3;
577 s = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]);
578 PUT_INTEL_SHORT(multibuf+loc, s); loc += 3;
580 multibuf[loc]=isthief; loc++;
582 multi_send_data(multibuf, loc, 1);
584 multi_delete_controlled_robot(objnum);
588 multi_send_create_robot(int station, int objnum, int type)
590 // Send create robot information
594 multibuf[loc] = MULTI_CREATE_ROBOT; loc += 1;
595 multibuf[loc] = Player_num; loc += 1;
596 multibuf[loc] = (sbyte)station; loc += 1;
597 PUT_INTEL_SHORT(multibuf+loc, objnum); loc += 2;
598 multibuf[loc] = type; loc += 1;
600 map_objnum_local_to_local((short)objnum);
602 multi_send_data(multibuf, loc, 2);
606 multi_send_boss_actions(int bossobjnum, int action, int secondary, int objnum)
608 // Send special boss behavior information
612 multibuf[loc] = MULTI_BOSS_ACTIONS; loc += 1;
613 multibuf[loc] = Player_num; loc += 1; // Which player is controlling the boss
614 PUT_INTEL_SHORT(multibuf+loc, bossobjnum); loc += 2; // We won't network map this objnum since it's the boss
615 multibuf[loc] = (sbyte)action; loc += 1; // What is the boss doing?
616 multibuf[loc] = (sbyte)secondary; loc += 1; // More info for what he is doing
617 PUT_INTEL_SHORT(multibuf+loc, objnum); loc += 2; // Objnum of object created by gate-in action
619 PUT_INTEL_SHORT(multibuf+loc, Objects[objnum].segnum); loc += 2; // Segment number object created in (for gate only)
624 if (action == 1) { // Teleport releases robot
625 // Boss is up for grabs after teleporting
626 mprintf((0, "Boss teleporting, removed from my list.\n"));
627 Assert((Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM >= 0) && (Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM < MAX_ROBOTS_CONTROLLED));
628 multi_delete_controlled_robot(bossobjnum);
629 // robot_controlled[Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM] = -1;
630 // Objects[bossobjnum].ctype.ai_info.REMOTE_OWNER = -1;
631 // Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM = 5; // Hands-off period!
634 mprintf((0, "LOCAL:Boss gating in robot id %d, objnum %d (%d).\n", secondary, objnum, objnum));
636 multi_send_data(multibuf, loc, 1);
639 #define MAX_ROBOT_POWERUPS 4
642 multi_send_create_robot_powerups(object *del_obj)
644 // Send create robot information
648 #ifdef WORDS_BIGENDIAN
649 vms_vector swapped_vec;
652 multibuf[loc] = MULTI_CREATE_ROBOT_POWERUPS; loc += 1;
653 multibuf[loc] = Player_num; loc += 1;
654 multibuf[loc] = del_obj->contains_count; loc += 1;
655 multibuf[loc] = del_obj->contains_type; loc += 1;
656 multibuf[loc] = del_obj->contains_id; loc += 1;
657 PUT_INTEL_SHORT(multibuf+loc, del_obj->segnum); loc += 2;
658 #ifndef WORDS_BIGENDIAN
659 memcpy(multibuf+loc, &del_obj->pos, sizeof(vms_vector)); loc += 12;
661 swapped_vec.x = (fix)INTEL_INT((int)del_obj->pos.x);
662 swapped_vec.y = (fix)INTEL_INT((int)del_obj->pos.y);
663 swapped_vec.z = (fix)INTEL_INT((int)del_obj->pos.z);
664 memcpy(multibuf+loc, &swapped_vec, sizeof(vms_vector)); loc += 12;
667 memset(multibuf+loc, -1, MAX_ROBOT_POWERUPS*sizeof(short));
669 if (del_obj->contains_count!=Net_create_loc)
670 Int3(); //Get Jason, a bad thing happened
672 if ((Net_create_loc > MAX_ROBOT_POWERUPS) || (Net_create_loc < 1))
676 for (i = 0; i < Net_create_loc; i++)
678 PUT_INTEL_SHORT(multibuf+loc, Net_create_objnums[i]);
680 map_objnum_local_to_local(Net_create_objnums[i]);
685 multi_send_data(multibuf, 27, 2);
689 multi_do_claim_robot(char *buf)
691 short botnum, remote_botnum;
696 remote_botnum = GET_INTEL_SHORT(buf + 2);
697 botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[4]);
699 if ((botnum > Highest_object_index) || (botnum < 0)) {
700 mprintf((1, "Ignoring claim message for object I don't have.\n"));
701 // Int3(); // See rob
705 if (Objects[botnum].type != OBJ_ROBOT) {
706 mprintf((1, "Got MYBOT message for non-Robot!\n"));
710 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER != -1)
712 mprintf((0, "Got a MYBOT message bot %d (%d) currently controlled by player %d.\n", botnum, remote_botnum, Objects[botnum].ctype.ai_info.REMOTE_OWNER));
713 if (MULTI_ROBOT_PRIORITY(remote_botnum, pnum) <= MULTI_ROBOT_PRIORITY(remote_botnum, Objects[botnum].ctype.ai_info.REMOTE_OWNER))
717 // Perform the requested change
719 mprintf((0, "Player %d taking control of robot %d (%d).\n", pnum, botnum, remote_botnum));
721 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER == Player_num)
723 multi_delete_controlled_robot(botnum);
726 Objects[botnum].ctype.ai_info.REMOTE_OWNER = pnum;
727 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
731 multi_do_release_robot(char *buf)
733 short botnum, remote_botnum;
738 remote_botnum = GET_INTEL_SHORT(buf + 2);
739 botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[4]);
741 if ((botnum < 0) || (botnum > Highest_object_index)) {
742 mprintf((1, "Ignoring release message for object I don't have.\n"));
743 // Int3(); // See rob
747 if (Objects[botnum].type != OBJ_ROBOT) {
748 mprintf((1, "Got RELEASE message for non-Robot!\n"));
752 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER != pnum)
754 mprintf((0, "Got a RELEASE message for bot %d not controlled by player %d.\n", botnum, pnum));
758 // Perform the requested change
760 mprintf((0, "Player %d releasing control of robot %d (%d).\n", pnum, botnum, remote_botnum));
762 Objects[botnum].ctype.ai_info.REMOTE_OWNER = -1;
763 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
767 multi_do_robot_position(char *buf)
769 // Process robot movement sent by another player
771 short botnum, remote_botnum;
774 #ifdef WORDS_BIGENDIAN
778 pnum = buf[loc]; loc += 1;
780 remote_botnum = GET_INTEL_SHORT(buf + loc);
781 botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3;
783 if ((botnum < 0) || (botnum > Highest_object_index)) {
784 mprintf((1, "Got robot position for object I don't have.\n"));
785 // Int3(); // See rob
789 if ((Objects[botnum].type != OBJ_ROBOT) || (Objects[botnum].flags & OF_EXPLODING)) {
790 // mprintf((0, "Ignoring position packet for non-robot or exploding robot.\n"));
794 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER != pnum)
796 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER == -1)
798 // Robot claim packet must have gotten lost, let this player claim it.
799 if (Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM > 3) {
800 mprintf((0, "Player %d taking control of robot %d WITHOUT claim message.\n", pnum, botnum));
801 Objects[botnum].ctype.ai_info.REMOTE_OWNER = pnum;
802 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
805 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM++;
809 mprintf((0, "Ignoring position for robot %d not controlled by player %d.\n", botnum, pnum));
814 set_thrust_from_velocity(&Objects[botnum]); // Try to smooth out movement
815 // Objects[botnum].phys_info.drag = Robot_info[Objects[botnum].id].drag >> 4; // Set drag to low
817 #ifndef WORDS_BIGENDIAN
818 extract_shortpos(&Objects[botnum], (shortpos *)(buf+loc), 0);
820 memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + loc), 9); loc += 9;
821 memcpy((ubyte *)&(sp.xo), (ubyte *)(buf + loc), 14);
822 extract_shortpos(&Objects[botnum], &sp, 1);
827 multi_do_robot_fire(char *buf)
829 // Send robot fire event
834 vms_vector fire, gun_point;
837 pnum = buf[loc]; loc += 1;
838 remote_botnum = GET_INTEL_SHORT(buf + loc);
839 botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3;
840 gun_num = (sbyte)buf[loc]; loc += 1;
841 memcpy(&fire, buf+loc, sizeof(vms_vector));
842 fire.x = (fix)INTEL_INT((int)fire.x);
843 fire.y = (fix)INTEL_INT((int)fire.y);
844 fire.z = (fix)INTEL_INT((int)fire.z);
846 if ((botnum < 0) || (botnum > Highest_object_index) || (Objects[botnum].type != OBJ_ROBOT) || (Objects[botnum].flags & OF_EXPLODING))
848 // mprintf((1, "Ignored robot fire from deleted robot.\n"));
849 // Int3(); // See Rob, probably not serious tho
855 if (gun_num == -1 || gun_num==-2)
857 // Drop proximity bombs
858 vm_vec_add(&gun_point, &Objects[botnum].pos, &fire);
862 calc_gun_point(&gun_point, &Objects[botnum], gun_num);
864 robptr = &Robot_info[Objects[botnum].id];
867 Laser_create_new_easy( &fire, &gun_point, botnum, PROXIMITY_ID, 1);
868 else if (gun_num == -2)
869 Laser_create_new_easy( &fire, &gun_point, botnum, SUPERPROX_ID, 1);
871 Laser_create_new_easy( &fire, &gun_point, botnum, robptr->weapon_type, 1);
874 extern void drop_stolen_items (object *);
877 multi_explode_robot_sub(int botnum, int killer,char isthief)
883 if ((botnum < 0) || (botnum > Highest_object_index)) { // Objnum in range?
888 if (Objects[botnum].type != OBJ_ROBOT) { // Object is robot?
889 mprintf((1, "Non-robot explosion ignored.\n"));
890 // Int3(); // See rob
894 if (Objects[botnum].flags & OF_EXPLODING) { // Object not already exploding
898 // Data seems valid, explode the sucker
900 if (Network_send_objects && network_objnum_is_past(botnum))
902 mprintf((0, "Resetting object sync due to object removal.\n"));
903 Network_send_objnum = -1;
906 robot = &Objects[botnum];
908 mprintf((0, "Robot %d controlled by player %d exploded.\n", botnum, robot->ctype.ai_info.REMOTE_OWNER));
910 // Drop non-random KEY powerups locally only!
911 if ((robot->contains_count > 0) && (robot->contains_type == OBJ_POWERUP) && (Game_mode & GM_MULTI_COOP) && (robot->contains_id >= POW_KEY_BLUE) && (robot->contains_id <= POW_KEY_GOLD))
913 object_create_egg(robot);
915 else if (robot->ctype.ai_info.REMOTE_OWNER == Player_num)
917 multi_drop_robot_powerups(robot-Objects);
918 multi_delete_controlled_robot(robot-Objects);
920 else if (robot->ctype.ai_info.REMOTE_OWNER == -1 && network_i_am_master())
922 multi_drop_robot_powerups(robot-Objects);
923 //multi_delete_controlled_robot(robot-Objects);
926 if (isthief || Robot_info[robot->id].thief)
927 drop_stolen_items(robot);
929 if (Robot_info[robot->id].boss_flag) {
931 start_boss_death_sequence(robot);
934 } else if (Robot_info[robot->id].death_roll) {
935 start_robot_death_sequence(robot);
937 if (robot->id == SPECIAL_REACTOR_ROBOT)
938 special_reactor_stuff();
939 if (Robot_info[robot->id].kamikaze)
940 explode_object(robot,1); // Kamikaze, explode right away, IN YOUR FACE!
942 explode_object(robot,STANDARD_EXPL_DELAY);
949 multi_do_robot_explode(char *buf)
951 // Explode robot controlled by other player
956 short killer, remote_killer;
961 pnum = buf[loc]; loc += 1;
962 remote_killer = GET_INTEL_SHORT(buf + loc);
963 killer = objnum_remote_to_local(remote_killer, (sbyte)buf[loc+2]); loc += 3;
964 remote_botnum = GET_INTEL_SHORT(buf + loc);
965 botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3;
968 if ((botnum < 0) || (botnum > Highest_object_index)) {
970 mprintf((0, "Ignored explode message for robot I don't have.\n"));
974 rval = multi_explode_robot_sub(botnum, killer,thief);
976 if (rval && (killer == Players[Player_num].objnum))
977 add_points_to_score(Robot_info[Objects[botnum].id].score_value);
980 extern fix EnergyToCreateOneRobot; // From fuelcen.c
981 extern object *create_morph_robot(segment *segp, vms_vector *object_pos, int object_id); // from fuelcen.c
984 multi_do_create_robot(char *buf)
987 int fuelcen_num = buf[2];
992 FuelCenter *robotcen;
993 vms_vector cur_object_loc, direction;
996 objnum = GET_INTEL_SHORT(buf + 3);
998 if ((pnum < 0) || (objnum < 0) || (fuelcen_num < 0) || (fuelcen_num >= Num_fuelcenters) || (pnum >= N_players))
1000 Int3(); // Bogus data
1004 robotcen = &Station[fuelcen_num];
1006 mprintf((1, "NETWORK: Creating morph robot from matcen %d.\n", fuelcen_num)); // DEBUG
1008 // Play effect and sound
1010 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
1011 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT);
1013 extract_orient_from_segment(&obj->orient, &Segments[robotcen->segnum]);
1014 if (Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1)
1015 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
1017 // Set robot center flags, in case we become the master for the next one
1020 robotcen->Capacity -= EnergyToCreateOneRobot;
1021 robotcen->Timer = 0;
1023 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type);
1025 return; // Cannot create object!
1027 obj->matcen_creator = (robotcen-Station) | 0x80;
1028 // extract_orient_from_segment(&obj->orient, &Segments[robotcen->segnum]);
1029 vm_vec_sub( &direction, &ConsoleObject->pos, &obj->pos );
1030 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
1033 mprintf((1, "matcen created robot %d (remote %d)\n", obj-Objects, objnum));
1034 map_objnum_local_to_remote(obj-Objects, objnum, pnum);
1036 Assert(obj->ctype.ai_info.REMOTE_OWNER == -1);
1040 multi_do_boss_actions(char *buf)
1042 // Code to handle remote-controlled boss actions
1047 int action, secondary;
1049 short remote_objnum, segnum;
1051 pnum = buf[loc]; loc += 1;
1052 boss_objnum = GET_INTEL_SHORT(buf + loc); loc += 2;
1053 action = buf[loc]; loc += 1;
1054 secondary = buf[loc]; loc += 1;
1055 remote_objnum = GET_INTEL_SHORT(buf + loc); loc += 2;
1056 segnum = GET_INTEL_SHORT(buf + loc); loc += 2;
1058 if ((boss_objnum < 0) || (boss_objnum > Highest_object_index))
1064 boss_obj = &Objects[boss_objnum];
1066 if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[boss_obj->id].boss_flag))
1068 Int3(); // Got boss actions for a robot who's not a boss?
1072 mprintf((0, "REMOTE: performing boss action %d.\n", action));
1078 int teleport_segnum;
1079 vms_vector boss_dir;
1081 if ((secondary < 0) || (secondary > Num_boss_teleport_segs))
1083 Int3(); // Bad segnum for boss teleport, ROB!!
1086 teleport_segnum = Boss_teleport_segs[secondary];
1087 mprintf((0, "Boss is teleporting, remove from other's list.\n"));
1088 if ((teleport_segnum < 0) || (teleport_segnum > Highest_segment_index))
1093 compute_segment_center(&boss_obj->pos, &Segments[teleport_segnum]);
1094 obj_relink(boss_obj-Objects, teleport_segnum);
1095 Last_teleport_time = GameTime;
1097 vm_vec_sub(&boss_dir, &Objects[Players[pnum].objnum].pos, &boss_obj->pos);
1098 vm_vector_2_matrix(&boss_obj->orient, &boss_dir, NULL, NULL);
1100 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, teleport_segnum, 0, &boss_obj->pos, 0 , F1_0);
1101 digi_kill_sound_linked_to_object( boss_obj-Objects);
1102 digi_link_sound_to_object2( SOUND_BOSS_SHARE_SEE, boss_obj-Objects, 1, F1_0, F1_0*512 ); // F1_0*512 means play twice as loud
1103 Ai_local_info[boss_obj-Objects].next_fire = 0;
1105 if (boss_obj->ctype.ai_info.REMOTE_OWNER == Player_num)
1107 mprintf((1, "WARNING: Accepted teleport message for boss when I controlled him!\n"));
1108 multi_delete_controlled_robot(boss_objnum);
1109 // robot_controlled[boss_obj->ctype.ai_info.REMOTE_SLOT_NUM] = -1;
1112 boss_obj->ctype.ai_info.REMOTE_OWNER = -1; // Boss is up for grabs again!
1113 boss_obj->ctype.ai_info.REMOTE_SLOT_NUM = 0; // Available immediately!
1117 Boss_hit_time = -F1_0*10;
1118 Boss_cloak_start_time = GameTime;
1119 Boss_cloak_end_time = GameTime + Boss_cloak_duration;
1120 boss_obj->ctype.ai_info.CLOAKED = 1;
1122 case 3: // Gate in robots!
1124 // Do some validity checking
1125 if ( (remote_objnum >= MAX_OBJECTS) || (remote_objnum < 0) || (segnum < 0) || (segnum > Highest_segment_index) )
1127 Int3(); // See Rob, bad data in boss gate action message
1132 if (gate_in_robot(secondary, segnum))
1133 map_objnum_local_to_remote(Net_create_objnums[0], remote_objnum, pnum);
1134 mprintf((0, "REMOTE: Boss gating in robot id %d, objnum %d (%d).\n", secondary, Net_create_objnums[0], remote_objnum));
1137 case 4: // Start effect
1138 restart_effect(BOSS_ECLIP_NUM);
1140 case 5: // Stop effect
1141 stop_effect(BOSS_ECLIP_NUM);
1144 Int3(); // Illegal type to boss actions
1149 multi_do_create_robot_powerups(char *buf)
1151 // Code to drop remote-controlled robot powerups
1155 int pnum, egg_objnum, i;
1157 pnum = buf[loc]; loc += 1;
1158 del_obj.contains_count = buf[loc]; loc += 1;
1159 del_obj.contains_type = buf[loc]; loc += 1;
1160 del_obj.contains_id = buf[loc]; loc += 1;
1161 del_obj.segnum = GET_INTEL_SHORT(buf + loc); loc += 2;
1162 memcpy(&del_obj.pos, buf+loc, sizeof(vms_vector)); loc += 12;
1164 vm_vec_zero(&del_obj.mtype.phys_info.velocity);
1166 del_obj.pos.x = (fix)INTEL_INT((int)del_obj.pos.x);
1167 del_obj.pos.y = (fix)INTEL_INT((int)del_obj.pos.y);
1168 del_obj.pos.z = (fix)INTEL_INT((int)del_obj.pos.z);
1170 Assert((pnum >= 0) && (pnum < N_players));
1171 Assert (pnum!=Player_num); // What? How'd we send ourselves this?
1176 egg_objnum = object_create_egg(&del_obj);
1178 if (egg_objnum == -1)
1179 return; // Object buffer full
1181 // Assert(egg_objnum > -1);
1182 Assert((Net_create_loc > 0) && (Net_create_loc <= MAX_ROBOT_POWERUPS));
1184 for (i = 0; i < Net_create_loc; i++)
1188 s = GET_INTEL_SHORT(buf + loc);
1190 map_objnum_local_to_remote((short)Net_create_objnums[i], s, pnum);
1192 Objects[Net_create_objnums[i]].flags |= OF_SHOULD_BE_DEAD; // Delete objects other guy didn't create one of
1198 multi_drop_robot_powerups(int objnum)
1200 // Code to handle dropped robot powerups in network mode ONLY!
1203 int egg_objnum = -1;
1206 if ((objnum < 0) || (objnum > Highest_object_index))
1212 del_obj = &Objects[objnum];
1214 if (del_obj->type != OBJ_ROBOT)
1216 Int3(); // dropping powerups for non-robot, Rob's fault
1220 robptr = &Robot_info[del_obj->id];
1224 if (del_obj->contains_count > 0) {
1225 // If dropping a weapon that the player has, drop energy instead, unless it's vulcan, in which case drop vulcan ammo.
1226 if (del_obj->contains_type == OBJ_POWERUP) {
1227 maybe_replace_powerup_with_energy(del_obj);
1228 if (!multi_powerup_is_allowed(del_obj->contains_id))
1229 del_obj->contains_id=POW_SHIELD_BOOST;
1231 // No key drops in non-coop games!
1232 if (!(Game_mode & GM_MULTI_COOP)) {
1233 if ((del_obj->contains_id >= POW_KEY_BLUE) && (del_obj->contains_id <= POW_KEY_GOLD))
1234 del_obj->contains_count = 0;
1238 if (del_obj->contains_count > 0)
1239 egg_objnum = object_create_egg(del_obj);
1242 else if (del_obj->ctype.ai_info.REMOTE_OWNER == -1) // No random goodies for robots we weren't in control of
1245 else if (robptr->contains_count) {
1246 d_srand(timer_get_approx_seconds());
1247 if (((d_rand() * 16) >> 15) < robptr->contains_prob) {
1248 del_obj->contains_count = ((d_rand() * robptr->contains_count) >> 15) + 1;
1249 del_obj->contains_type = robptr->contains_type;
1250 del_obj->contains_id = robptr->contains_id;
1251 if (del_obj->contains_type == OBJ_POWERUP)
1253 maybe_replace_powerup_with_energy(del_obj);
1254 if (!multi_powerup_is_allowed(del_obj->contains_id))
1255 del_obj->contains_id=POW_SHIELD_BOOST;
1259 if (del_obj->contains_count > 0)
1260 egg_objnum = object_create_egg(del_obj);
1264 if (egg_objnum >= 0) {
1265 // Transmit the object creation to the other players
1266 mprintf((0, "Dropped %d powerups for robot %d.\n", Net_create_loc, del_obj-Objects));
1267 multi_send_create_robot_powerups(del_obj);
1271 // -----------------------------------------------------------------------------
1272 // Robot *robot got whacked by player player_num and requests permission to do something about it.
1273 // Note: This function will be called regardless of whether Game_mode is a multiplayer mode, so it
1274 // should quick-out if not in a multiplayer mode. On the other hand, it only gets called when a
1275 // player or player weapon whacks a robot, so it happens rarely.
1276 void multi_robot_request_change(object *robot, int player_num)
1278 int slot, remote_objnum;
1281 if (!(Game_mode & GM_MULTI_ROBOTS))
1284 // if (robot->ctype.ai_info.REMOTE_OWNER == Player_num)
1287 slot = robot->ctype.ai_info.REMOTE_SLOT_NUM;
1289 if ((slot < 0) || (slot >= MAX_ROBOTS_CONTROLLED)) {
1294 remote_objnum = objnum_local_to_remote(robot-Objects, &dummy);
1295 if (remote_objnum < 0)
1298 mprintf((0, "request_change(): my pri %d, player %d's pri %d.\n", MULTI_ROBOT_PRIORITY(remote_objnum, Player_num),
1299 player_num, MULTI_ROBOT_PRIORITY(remote_objnum, player_num)));
1301 if ( (robot_agitation[slot] < 70) || (MULTI_ROBOT_PRIORITY(remote_objnum, player_num) > MULTI_ROBOT_PRIORITY(remote_objnum, Player_num)) || (d_rand() > 0x4400))
1303 mprintf((0, "Robot %d (%d) released because it got hit by Player %d.\n", robot-Objects, remote_objnum, player_num));
1304 if (robot_send_pending[slot])
1305 multi_send_robot_position(robot_controlled[slot], -1);
1306 multi_send_release_robot(robot_controlled[slot]);
1307 robot->ctype.ai_info.REMOTE_SLOT_NUM = 5; // Hands-off period