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.
51 int multi_add_controlled_robot(int objnum, int agitation);
52 void multi_send_release_robot(int objnum);
53 void multi_delete_controlled_robot(int objnum);
54 void multi_send_robot_position_sub(int objnum);
57 // Code for controlling robots in multiplayer games
61 #define STANDARD_EXPL_DELAY (F1_0/4)
62 #define MIN_CONTROL_TIME F1_0*1
63 #define ROBOT_TIMEOUT F1_0*2
66 #define MAX_TO_DELETE 61
68 int robot_controlled[MAX_ROBOTS_CONTROLLED];
69 int robot_agitation[MAX_ROBOTS_CONTROLLED];
70 fix robot_controlled_time[MAX_ROBOTS_CONTROLLED];
71 fix robot_last_send_time[MAX_ROBOTS_CONTROLLED];
72 fix robot_last_message_time[MAX_ROBOTS_CONTROLLED];
73 int robot_send_pending[MAX_ROBOTS_CONTROLLED];
74 int robot_fired[MAX_ROBOTS_CONTROLLED];
75 byte robot_fire_buf[MAX_ROBOTS_CONTROLLED][18+3];
77 #define MULTI_ROBOT_PRIORITY(objnum, pnum) (((objnum % 4) + pnum) % N_players)
79 extern void multi_send_stolen_items();
80 extern int multi_powerup_is_allowed (int);
82 //#define MULTI_ROBOT_PRIORITY(objnum, pnum) multi_robot_priority(objnum, pnum)
83 //int multi_robot_priority(int objnum, int pnum)
85 // return( ((objnum % 4) + pnum) % N_players);
89 multi_can_move_robot(int objnum, int agitation)
91 // Determine whether or not I am allowed to move this robot.
94 // Claim robot if necessary.
100 if ((objnum < 0) || (objnum > Highest_object_index))
106 else if (Objects[objnum].type != OBJ_ROBOT)
113 else if ((Robot_info[Objects[objnum].id].boss_flag) && (Boss_dying == 1))
116 else if (Objects[objnum].ctype.ai_info.REMOTE_OWNER == Player_num) // Already my robot!
118 int slot_num = Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM;
120 if ((slot_num < 0) || (slot_num >= MAX_ROBOTS_CONTROLLED))
122 mprintf ((0,"Not asserting in multi_can_move_robot!"));
126 if (robot_fired[slot_num]) {
127 // mprintf((0, "Preventing robot from firing again until firing complete!\n"));
131 robot_agitation[slot_num] = agitation;
132 robot_last_message_time[slot_num] = GameTime;
137 else if ((Objects[objnum].ctype.ai_info.REMOTE_OWNER != -1) || (agitation < MIN_TO_ADD))
139 if (agitation == ROBOT_FIRE_AGITATION) // Special case for firing at non-player
141 mprintf((0, "Shooting anyway.\n"));
142 rval = 1; // Try to fire at player even tho we're not in control!
148 rval = multi_add_controlled_robot(objnum, agitation);
154 multi_check_robot_timeout(void)
156 static fix lastcheck = 0;
159 if (GameTime > lastcheck + F1_0)
161 lastcheck = GameTime;
162 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
164 if ((robot_controlled[i] != -1) && (robot_last_send_time[i] + ROBOT_TIMEOUT < GameTime))
166 if (Objects[robot_controlled[i]].ctype.ai_info.REMOTE_OWNER != Player_num)
168 robot_controlled[i] = -1;
169 Int3(); // Non-terminal but Rob is interesting, step over please...
172 if (Objects[robot_controlled[i]].ctype.ai_info.REMOTE_OWNER !=Player_num)
174 mprintf ((0,"What? This ain't my bot and I'm trying to time it out!\n"));
177 mprintf((0, "Robot %d (slot %d) removed, timed out, frame %d.\n", robot_controlled[i], i, GameTime));
178 if (robot_send_pending[i])
179 multi_send_robot_position(robot_controlled[i], 1);
180 multi_send_release_robot(robot_controlled[i]);
181 // multi_delete_controlled_robot(robot_controlled[i]);
182 // robot_controlled[i] = -1;
189 multi_strip_robots(int playernum)
191 // Grab all robots away from a player
192 // (player died or exited the game)
196 if (Game_mode & GM_MULTI_ROBOTS) {
198 if (playernum == Player_num)
199 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
200 multi_delete_controlled_robot(robot_controlled[i]);
202 for (i = 1; i <= Highest_object_index; i++)
203 if ((Objects[i].type == OBJ_ROBOT) && (Objects[i].ctype.ai_info.REMOTE_OWNER == playernum)) {
204 Assert((Objects[i].control_type == CT_AI) || (Objects[i].control_type == CT_NONE) || (Objects[i].control_type == CT_MORPH));
205 Objects[i].ctype.ai_info.REMOTE_OWNER = -1;
206 if (playernum == Player_num)
207 Objects[i].ctype.ai_info.REMOTE_SLOT_NUM = 4;
209 Objects[i].ctype.ai_info.REMOTE_SLOT_NUM = 0;
212 // Note -- only call this with playernum == Player_num if all other players
213 // already know that we are clearing house. This does not send a release
214 // message for each controlled robot!!
219 multi_dump_robots(void)
222 // Dump robot control info for debug purposes
226 if (!(Game_mode & GM_MULTI_ROBOTS))
230 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
232 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));
237 multi_add_controlled_robot(int objnum, int agitation)
240 int lowest_agitation = 0x7fffffff; // MAX POSITIVE INT
241 int lowest_agitated_bot = -1;
242 int first_free_robot = -1;
244 // Try to add a new robot to the controlled list, return 1 if added, 0 if not.
246 if (Robot_info[Objects[objnum].id].boss_flag) // this is a boss, so make sure he gets a slot
247 agitation=(agitation*3)+Player_num;
249 if (Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM > 0)
251 mprintf((0, "Robot %d hands-off = %d.\n", objnum, Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM));
252 Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM -= 1;
256 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
258 if ((robot_controlled[i] == -1) || (Objects[robot_controlled[i]].type != OBJ_ROBOT)) {
259 first_free_robot = i;
263 if (robot_last_message_time[i] + ROBOT_TIMEOUT < GameTime) {
264 mprintf((0, "Robot %d replaced (timeout).\n", robot_controlled[i]));
265 if (robot_send_pending[i])
266 multi_send_robot_position(robot_controlled[i], 1);
267 multi_send_release_robot(robot_controlled[i]);
268 first_free_robot = i;
272 if ((robot_controlled[i] != -1) && (robot_agitation[i] < lowest_agitation) && (robot_controlled_time[i] + MIN_CONTROL_TIME < GameTime))
274 lowest_agitation = robot_agitation[i];
275 lowest_agitated_bot = i;
279 // mprintf ((0,"first_free_robot=%d lowest_agitated_bot=%d\n",first_free_robot,lowest_agitated_bot));
281 if (first_free_robot != -1) // Room left for new robots
282 i = first_free_robot;
284 else if ((agitation > lowest_agitation))// && (lowest_agitation <= MAX_TO_DELETE)) // Replace some old robot with a more agitated one
286 if (robot_send_pending[lowest_agitated_bot])
287 multi_send_robot_position(robot_controlled[lowest_agitated_bot], 1);
288 multi_send_release_robot(robot_controlled[lowest_agitated_bot]);
290 mprintf((0, "Replaced robot %d (agitation %d) with robot %d (agitation %d).\n", robot_controlled[lowest_agitated_bot], lowest_agitation, objnum, agitation));
292 i = lowest_agitated_bot;
295 // mprintf((0, "Cannot add robot %d agitation %d (min agitation %d)\n", objnum, agitation, lowest_agitation));
296 return(0); // Sorry, can't squeeze him in!
299 mprintf((0, "Taking control of robot %d, agitation %d.\n", objnum, agitation));
301 multi_send_claim_robot(objnum);
302 robot_controlled[i] = objnum;
303 robot_agitation[i] = agitation;
304 Objects[objnum].ctype.ai_info.REMOTE_OWNER = Player_num;
305 Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM = i;
306 robot_controlled_time[i] = GameTime;
307 robot_last_send_time[i] = robot_last_message_time[i] = GameTime;
312 multi_delete_controlled_robot(int objnum)
316 // Delete robot object number objnum from list of controlled robots because it is dead
318 if ( (objnum<0) || (objnum>Highest_object_index)) {
319 mprintf((0, "Trying to releasing control of bogus robot %d\n", objnum));
323 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
324 if (robot_controlled[i] == objnum)
327 if (i == MAX_ROBOTS_CONTROLLED)
330 mprintf((0, "Releasing control of robot %d\n", objnum));
332 if (Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM != i)
334 mprintf ((0,"Saved from asserting in multi_delete_controlled_bot!"));
335 Int3(); // can't release this bot!
339 Objects[objnum].ctype.ai_info.REMOTE_OWNER = -1;
340 Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
341 robot_controlled[i] = -1;
342 robot_send_pending[i] = 0;
347 multi_send_claim_robot(int objnum)
351 if ((objnum < 0) || (objnum > Highest_object_index))
357 if (Objects[objnum].type != OBJ_ROBOT)
363 // The AI tells us we should take control of this robot.
365 multibuf[0] = (char)MULTI_ROBOT_CLAIM;
366 multibuf[1] = Player_num;
367 s = objnum_local_to_remote(objnum, (byte *)&multibuf[4]);
368 *(short *)(multibuf+2) = INTEL_SHORT(s);
370 multi_send_data(multibuf, 5, 2);
371 multi_send_data(multibuf, 5, 2);
372 multi_send_data(multibuf, 5, 2);
377 multi_send_release_robot(int objnum)
381 if ((objnum < 0) || (objnum > Highest_object_index))
387 if (Objects[objnum].type != OBJ_ROBOT)
393 multi_delete_controlled_robot(objnum);
395 multibuf[0] = (char)MULTI_ROBOT_RELEASE;
396 multibuf[1] = Player_num;
397 s = objnum_local_to_remote(objnum, (byte *)&multibuf[4]);
398 *(short *)(multibuf+2) = INTEL_SHORT(s);
400 multi_send_data(multibuf, 5, 2);
401 multi_send_data(multibuf, 5, 2);
402 multi_send_data(multibuf, 5, 2);
405 #define MIN_ROBOT_COM_GAP F1_0/12
408 multi_send_robot_frame(int sent)
410 static int last_sent = 0;
415 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
417 int sending = (last_sent+1+i)%MAX_ROBOTS_CONTROLLED;
418 if ( (robot_controlled[sending] != -1) && ((robot_send_pending[sending] > sent) || (robot_fired[sending] > sent)) )
420 if (robot_send_pending[sending])
422 robot_send_pending[sending] = 0;
423 multi_send_robot_position_sub(robot_controlled[sending]);
426 if (robot_fired[sending])
428 robot_fired[sending] = 0;
429 multi_send_data(robot_fire_buf[sending], 18, 1);
432 if (!(Game_mode & GM_NETWORK))
439 Assert((last_sent >= 0) && (last_sent <= MAX_ROBOTS_CONTROLLED));
444 multi_send_robot_position_sub(int objnum)
452 // mprintf((0, "SENDPOS object %d, Gametime %d.\n", objnum, GameTime));
454 multibuf[loc] = MULTI_ROBOT_POSITION; loc += 1;
455 multibuf[loc] = Player_num; loc += 1;
456 s = objnum_local_to_remote(objnum, (byte *)&multibuf[loc+2]);
457 *(short *)(multibuf+loc) = INTEL_SHORT(s);
461 create_shortpos((shortpos *)(multibuf+loc), Objects+objnum,0); loc += sizeof(shortpos);
463 create_shortpos(&sp, Objects+objnum, 1);
464 memcpy(&(multibuf[loc]), (ubyte *)(sp.bytemat), 9);
466 memcpy(&(multibuf[loc]), (ubyte *)&(sp.xo), 14);
469 multi_send_data(multibuf, loc, 1);
473 multi_send_robot_position(int objnum, int force)
475 // Send robot position to other player(s). Includes a byte
476 // value describing whether or not they fired a weapon
478 if (!(Game_mode & GM_MULTI))
481 if ((objnum < 0) || (objnum > Highest_object_index))
486 if (Objects[objnum].type != OBJ_ROBOT)
492 if (Objects[objnum].ctype.ai_info.REMOTE_OWNER != Player_num)
495 // Objects[objnum].phys_info.drag = Robot_info[Objects[objnum].id].drag; // Set drag to normal
497 robot_last_send_time[Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM] = GameTime;
499 robot_send_pending[Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM] = 1+force;
501 if (force & (Game_mode & GM_NETWORK))
508 multi_send_robot_fire(int objnum, int gun_num, vms_vector *fire)
510 // Send robot fire event
514 vms_vector swapped_vec;
517 multibuf[loc] = MULTI_ROBOT_FIRE; loc += 1;
518 multibuf[loc] = Player_num; loc += 1;
519 s = objnum_local_to_remote(objnum, (byte *)&multibuf[loc+2]);
520 *(short *)(multibuf+loc) = INTEL_SHORT(s);
522 multibuf[loc] = gun_num; loc += 1;
524 *(vms_vector *)(multibuf+loc) = *fire; loc += sizeof(vms_vector); // 12
525 // --------------------------
528 swapped_vec.x = (fix)INTEL_INT((int)fire->x);
529 swapped_vec.y = (fix)INTEL_INT((int)fire->y);
530 swapped_vec.z = (fix)INTEL_INT((int)fire->z);
531 *(vms_vector *)(multibuf+loc) = swapped_vec; loc += sizeof(vms_vector);
534 if (Objects[objnum].ctype.ai_info.REMOTE_OWNER == Player_num)
536 int slot = Objects[objnum].ctype.ai_info.REMOTE_SLOT_NUM;
537 if (slot<0 || slot>=MAX_ROBOTS_CONTROLLED)
539 mprintf ((0,"Saved from asserting in robofire\n"));
542 if (robot_fired[slot] != 0)
544 mprintf ((0,"Couldn't find an open slot for robo firing!\n"));
548 memcpy(robot_fire_buf[slot], multibuf, loc);
549 robot_fired[slot] = 1;
550 if (Game_mode & GM_NETWORK)
554 multi_send_data(multibuf, loc, 2); // Not our robot, send ASAP
558 multi_send_robot_explode(int objnum, int killer,char isthief)
560 // Send robot explosion event to the other players
565 multibuf[loc] = MULTI_ROBOT_EXPLODE; loc += 1;
566 multibuf[loc] = Player_num; loc += 1;
567 s = (short)objnum_local_to_remote(killer, (byte *)&multibuf[loc+2]);
568 *(short *)(multibuf+loc) = INTEL_SHORT(s);
570 s = (short)objnum_local_to_remote(objnum, (byte *)&multibuf[loc+2]);
571 *(short *)(multibuf+loc) = INTEL_SHORT(s); loc += 3;
573 multibuf[loc]=isthief; loc++;
575 multi_send_data(multibuf, loc, 1);
577 multi_delete_controlled_robot(objnum);
581 multi_send_create_robot(int station, int objnum, int type)
583 // Send create robot information
587 multibuf[loc] = MULTI_CREATE_ROBOT; loc += 1;
588 multibuf[loc] = Player_num; loc += 1;
589 multibuf[loc] = (byte)station; loc += 1;
590 *(short *)(multibuf+loc) = INTEL_SHORT((short)objnum); loc += 2;
591 multibuf[loc] = type; loc += 1;
593 map_objnum_local_to_local((short)objnum);
595 multi_send_data(multibuf, loc, 2);
599 multi_send_boss_actions(int bossobjnum, int action, int secondary, int objnum)
601 // Send special boss behavior information
605 multibuf[loc] = MULTI_BOSS_ACTIONS; loc += 1;
606 multibuf[loc] = Player_num; loc += 1; // Which player is controlling the boss
607 *(short *)(multibuf+loc) = INTEL_SHORT(bossobjnum); loc += 2; // We won't network map this objnum since its the boss
608 multibuf[loc] = (byte)action; loc += 1; // What is the boss doing?
609 multibuf[loc] = (byte)secondary; loc += 1; // More info for what he is doing
610 *(short *)(multibuf+loc) = INTEL_SHORT(objnum); loc += 2; // Objnum of object created by gate-in action
612 *(short *)(multibuf+loc) = INTEL_SHORT(Objects[objnum].segnum); loc += 2; // Segment number object created in (for gate only)
617 if (action == 1) { // Teleport releases robot
618 // Boss is up for grabs after teleporting
619 mprintf((0, "Boss teleporting, removed from my list.\n"));
620 Assert((Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM >= 0) && (Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM < MAX_ROBOTS_CONTROLLED));
621 multi_delete_controlled_robot(bossobjnum);
622 // robot_controlled[Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM] = -1;
623 // Objects[bossobjnum].ctype.ai_info.REMOTE_OWNER = -1;
624 // Objects[bossobjnum].ctype.ai_info.REMOTE_SLOT_NUM = 5; // Hands-off period!
627 mprintf((0, "LOCAL:Boss gating in robot id %d, objnum %d (%d).\n", secondary, objnum, objnum));
629 multi_send_data(multibuf, loc, 1);
632 #define MAX_ROBOT_POWERUPS 4
635 multi_send_create_robot_powerups(object *del_obj)
637 // Send create robot information
642 vms_vector swapped_vec;
645 multibuf[loc] = MULTI_CREATE_ROBOT_POWERUPS; loc += 1;
646 multibuf[loc] = Player_num; loc += 1;
647 multibuf[loc] = del_obj->contains_count; loc += 1;
648 multibuf[loc] = del_obj->contains_type; loc += 1;
649 multibuf[loc] = del_obj->contains_id; loc += 1;
650 *(short *)(multibuf+loc) = INTEL_SHORT(del_obj->segnum); loc += 2;
652 *(vms_vector *)(multibuf+loc) = del_obj->pos; loc += 12;
654 swapped_vec.x = (fix)INTEL_INT((int)del_obj->pos.x);
655 swapped_vec.y = (fix)INTEL_INT((int)del_obj->pos.y);
656 swapped_vec.z = (fix)INTEL_INT((int)del_obj->pos.z);
657 *(vms_vector *)(multibuf+loc) = swapped_vec; loc += 12;
660 memset(multibuf+loc, -1, MAX_ROBOT_POWERUPS*sizeof(short));
662 if (del_obj->contains_count!=Net_create_loc)
663 Int3(); //Get Jason, a bad thing happened
665 if ((Net_create_loc > MAX_ROBOT_POWERUPS) || (Net_create_loc < 1))
669 for (i = 0; i < Net_create_loc; i++)
671 *(short *)(multibuf+loc) = INTEL_SHORT(Net_create_objnums[i]);
673 map_objnum_local_to_local(Net_create_objnums[i]);
678 multi_send_data(multibuf, 27, 2);
682 multi_do_claim_robot(char *buf)
690 remote_botnum = INTEL_SHORT(*(short *)(buf+2));
691 botnum = objnum_remote_to_local(remote_botnum, (byte)buf[4]);
693 if ((botnum > Highest_object_index) || (botnum < 0)) {
694 mprintf((1, "Ignoring claim message for object I don't have.\n"));
695 // Int3(); // See rob
699 if (Objects[botnum].type != OBJ_ROBOT) {
700 mprintf((1, "Got MYBOT message for non-Robot!\n"));
704 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER != -1)
706 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));
707 if (MULTI_ROBOT_PRIORITY(remote_botnum, pnum) <= MULTI_ROBOT_PRIORITY(remote_botnum, Objects[botnum].ctype.ai_info.REMOTE_OWNER))
711 // Perform the requested change
713 mprintf((0, "Player %d taking control of robot %d (%d).\n", pnum, botnum, remote_botnum));
715 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER == Player_num)
717 multi_delete_controlled_robot(botnum);
720 Objects[botnum].ctype.ai_info.REMOTE_OWNER = pnum;
721 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
725 multi_do_release_robot(char *buf)
732 botnum = objnum_remote_to_local( INTEL_SHORT( *(short *)(buf+2) ), (byte)buf[4] );
734 if ((botnum < 0) || (botnum > Highest_object_index)) {
735 mprintf((1, "Ignoring release message for object I don't have.\n"));
736 // Int3(); // See rob
740 if (Objects[botnum].type != OBJ_ROBOT) {
741 mprintf((1, "Got RELEASE message for non-Robot!\n"));
745 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER != pnum)
747 mprintf((0, "Got a RELEASE message for bot %d not controlled by player %d.\n", botnum, pnum));
751 // Perform the requested change
753 mprintf((0, "Player %d releasing control of robot %d (%d).\n", pnum, botnum, *(short *)(buf+2)));
755 Objects[botnum].ctype.ai_info.REMOTE_OWNER = -1;
756 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
760 multi_do_robot_position(char *buf)
762 // Process robot movement sent by another player
771 pnum = buf[loc]; loc += 1;
773 botnum = objnum_remote_to_local( INTEL_SHORT( *(short *)(buf+loc) ), (byte)buf[loc+2] );
776 if ((botnum < 0) || (botnum > Highest_object_index)) {
777 mprintf((1, "Got robot position for object I don't have.\n"));
778 // Int3(); // See rob
782 if ((Objects[botnum].type != OBJ_ROBOT) || (Objects[botnum].flags & OF_EXPLODING)) {
783 // mprintf((0, "Ignoring position packet for non-robot or exploding robot.\n"));
787 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER != pnum)
789 if (Objects[botnum].ctype.ai_info.REMOTE_OWNER == -1)
791 // Robot claim packet must have gotten lost, let this player claim it.
792 if (Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM > 3) {
793 mprintf((0, "Player %d taking control of robot %d WITHOUT claim message.\n", pnum, botnum));
794 Objects[botnum].ctype.ai_info.REMOTE_OWNER = pnum;
795 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM = 0;
798 Objects[botnum].ctype.ai_info.REMOTE_SLOT_NUM++;
802 mprintf((0, "Ignoring position for robot %d not controlled by player %d.\n", botnum, pnum));
807 set_thrust_from_velocity(&Objects[botnum]); // Try to smooth out movement
808 // Objects[botnum].phys_info.drag = Robot_info[Objects[botnum].id].drag >> 4; // Set drag to low
811 extract_shortpos(&Objects[botnum], (shortpos *)(buf+loc), 0);
813 memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + loc), 9); loc += 9;
814 memcpy((ubyte *)&(sp.xo), (ubyte *)(buf + loc), 14);
815 extract_shortpos(&Objects[botnum], &sp, 1);
820 multi_do_robot_fire(char *buf)
822 // Send robot fire event
824 int botnum, pnum, gun_num;
825 vms_vector fire, gun_point;
828 pnum = buf[loc]; loc += 1;
829 botnum = objnum_remote_to_local( INTEL_SHORT( *(short *)(buf+loc) ), (byte)buf[loc+2]);
831 gun_num = (byte)buf[loc]; loc += 1;
832 fire = *(vms_vector *)(buf+loc);
833 fire.x = (fix)INTEL_INT((int)fire.x);
834 fire.y = (fix)INTEL_INT((int)fire.y);
835 fire.z = (fix)INTEL_INT((int)fire.z);
837 if ((botnum < 0) || (botnum > Highest_object_index) || (Objects[botnum].type != OBJ_ROBOT) || (Objects[botnum].flags & OF_EXPLODING))
839 // mprintf((1, "Ignored robot fire from deleted robot.\n"));
840 // Int3(); // See Rob, probably not serious tho
846 if (gun_num == -1 || gun_num==-2)
848 // Drop proximity bombs
849 vm_vec_add(&gun_point, &Objects[botnum].pos, &fire);
853 calc_gun_point(&gun_point, &Objects[botnum], gun_num);
855 robptr = &Robot_info[Objects[botnum].id];
858 Laser_create_new_easy( &fire, &gun_point, botnum, PROXIMITY_ID, 1);
859 else if (gun_num == -2)
860 Laser_create_new_easy( &fire, &gun_point, botnum, SUPERPROX_ID, 1);
862 Laser_create_new_easy( &fire, &gun_point, botnum, robptr->weapon_type, 1);
865 extern void drop_stolen_items (object *);
868 multi_explode_robot_sub(int botnum, int killer,char isthief)
874 if ((botnum < 0) || (botnum > Highest_object_index)) { // Objnum in range?
879 if (Objects[botnum].type != OBJ_ROBOT) { // Object is robot?
880 mprintf((1, "Non-robot explosion ignored.\n"));
881 // Int3(); // See rob
885 if (Objects[botnum].flags & OF_EXPLODING) { // Object not already exploding
889 // Data seems valid, explode the sucker
891 if (Network_send_objects && network_objnum_is_past(botnum))
893 mprintf((0, "Resetting object sync due to object removal.\n"));
894 Network_send_objnum = -1;
897 robot = &Objects[botnum];
899 mprintf((0, "Robot %d controlled by player %d exploded.\n", botnum, robot->ctype.ai_info.REMOTE_OWNER));
901 // Drop non-random KEY powerups locally only!
902 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))
904 object_create_egg(robot);
906 else if (robot->ctype.ai_info.REMOTE_OWNER == Player_num)
908 multi_drop_robot_powerups(robot-Objects);
909 multi_delete_controlled_robot(robot-Objects);
911 else if (robot->ctype.ai_info.REMOTE_OWNER == -1 && network_i_am_master())
913 multi_drop_robot_powerups(robot-Objects);
914 //multi_delete_controlled_robot(robot-Objects);
917 if (isthief || Robot_info[robot->id].thief)
918 drop_stolen_items(robot);
920 if (Robot_info[robot->id].boss_flag) {
922 start_boss_death_sequence(robot);
925 } else if (Robot_info[robot->id].death_roll) {
926 start_robot_death_sequence(robot);
928 if (robot->id == SPECIAL_REACTOR_ROBOT)
929 special_reactor_stuff();
930 if (Robot_info[robot->id].kamikaze)
931 explode_object(robot,1); // Kamikaze, explode right away, IN YOUR FACE!
933 explode_object(robot,STANDARD_EXPL_DELAY);
940 multi_do_robot_explode(char *buf)
942 // Explode robot controlled by other player
951 pnum = buf[loc]; loc += 1;
952 killer = objnum_remote_to_local( INTEL_SHORT( *(short *)(buf+loc) ), (byte)buf[loc+2]);
954 botnum = objnum_remote_to_local( INTEL_SHORT( *(short *)(buf+loc) ), (byte)buf[loc+2]);
958 if ((botnum < 0) || (botnum > Highest_object_index)) {
960 mprintf((0, "Ignored explode message for robot I don't have.\n"));
964 rval = multi_explode_robot_sub(botnum, killer,thief);
966 if (rval && (killer == Players[Player_num].objnum))
967 add_points_to_score(Robot_info[Objects[botnum].id].score_value);
970 extern fix EnergyToCreateOneRobot; // From fuelcen.c
971 extern object *create_morph_robot(segment *segp, vms_vector *object_pos, int object_id); // from fuelcen.c
974 multi_do_create_robot(char *buf)
977 int fuelcen_num = buf[2];
979 short objnum = INTEL_SHORT( *(short *)(buf+3) );
982 FuelCenter *robotcen;
983 vms_vector cur_object_loc, direction;
986 if ((pnum < 0) || (objnum < 0) || (fuelcen_num < 0) || (fuelcen_num >= Num_fuelcenters) || (pnum >= N_players))
988 Int3(); // Bogus data
992 robotcen = &Station[fuelcen_num];
994 mprintf((1, "NETWORK: Creating morph robot from matcen %d.\n", fuelcen_num)); // DEBUG
996 // Play effect and sound
998 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
999 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT);
1001 extract_orient_from_segment(&obj->orient, &Segments[robotcen->segnum]);
1002 if (Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1)
1003 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
1005 // Set robot center flags, in case we become the master for the next one
1008 robotcen->Capacity -= EnergyToCreateOneRobot;
1009 robotcen->Timer = 0;
1011 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type);
1013 return; // Cannot create object!
1015 obj->matcen_creator = (robotcen-Station) | 0x80;
1016 // extract_orient_from_segment(&obj->orient, &Segments[robotcen->segnum]);
1017 vm_vec_sub( &direction, &ConsoleObject->pos, &obj->pos );
1018 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
1021 mprintf((1, "matcen created robot %d (remote %d)\n", obj-Objects, objnum));
1022 map_objnum_local_to_remote(obj-Objects, objnum, pnum);
1024 Assert(obj->ctype.ai_info.REMOTE_OWNER == -1);
1028 multi_do_boss_actions(char *buf)
1030 // Code to handle remote-controlled boss actions
1035 int action, secondary;
1037 short remote_objnum, segnum;
1039 pnum = buf[loc]; loc += 1;
1040 boss_objnum = INTEL_SHORT( *(short *)(buf+loc) ); loc += 2;
1041 action = buf[loc]; loc += 1;
1042 secondary = buf[loc]; loc += 1;
1043 remote_objnum = INTEL_SHORT( *(short *)(buf+loc) ); loc += 2;
1044 segnum = INTEL_SHORT( *(short *)(buf+loc) ); loc += 2;
1046 if ((boss_objnum < 0) || (boss_objnum > Highest_object_index))
1052 boss_obj = &Objects[boss_objnum];
1054 if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[boss_obj->id].boss_flag))
1056 Int3(); // Got boss actions for a robot who's not a boss?
1060 mprintf((0, "REMOTE: performing boss action %d.\n", action));
1066 int teleport_segnum;
1067 vms_vector boss_dir;
1069 if ((secondary < 0) || (secondary > Num_boss_teleport_segs))
1071 Int3(); // Bad segnum for boss teleport, ROB!!
1074 teleport_segnum = Boss_teleport_segs[secondary];
1075 mprintf((0, "Boss is teleporting, remove from other's list.\n"));
1076 if ((teleport_segnum < 0) || (teleport_segnum > Highest_segment_index))
1081 compute_segment_center(&boss_obj->pos, &Segments[teleport_segnum]);
1082 obj_relink(boss_obj-Objects, teleport_segnum);
1083 Last_teleport_time = GameTime;
1085 vm_vec_sub(&boss_dir, &Objects[Players[pnum].objnum].pos, &boss_obj->pos);
1086 vm_vector_2_matrix(&boss_obj->orient, &boss_dir, NULL, NULL);
1088 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, teleport_segnum, 0, &boss_obj->pos, 0 , F1_0);
1089 digi_kill_sound_linked_to_object( boss_obj-Objects);
1090 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
1091 Ai_local_info[boss_obj-Objects].next_fire = 0;
1093 if (boss_obj->ctype.ai_info.REMOTE_OWNER == Player_num)
1095 mprintf((1, "WARNING: Accepted teleport message for boss when I controlled him!\n"));
1096 multi_delete_controlled_robot(boss_objnum);
1097 // robot_controlled[boss_obj->ctype.ai_info.REMOTE_SLOT_NUM] = -1;
1100 boss_obj->ctype.ai_info.REMOTE_OWNER = -1; // Boss is up for grabs again!
1101 boss_obj->ctype.ai_info.REMOTE_SLOT_NUM = 0; // Available immediately!
1105 Boss_hit_time = -F1_0*10;
1106 Boss_cloak_start_time = GameTime;
1107 Boss_cloak_end_time = GameTime + Boss_cloak_duration;
1108 boss_obj->ctype.ai_info.CLOAKED = 1;
1110 case 3: // Gate in robots!
1112 // Do some validity checking
1113 if ( (remote_objnum >= MAX_OBJECTS) || (remote_objnum < 0) || (segnum < 0) || (segnum > Highest_segment_index) )
1115 Int3(); // See Rob, bad data in boss gate action message
1120 if (gate_in_robot(secondary, segnum))
1121 map_objnum_local_to_remote(Net_create_objnums[0], remote_objnum, pnum);
1122 mprintf((0, "REMOTE: Boss gating in robot id %d, objnum %d (%d).\n", secondary, Net_create_objnums[0], remote_objnum));
1125 case 4: // Start effect
1126 restart_effect(BOSS_ECLIP_NUM);
1128 case 5: // Stop effect
1129 stop_effect(BOSS_ECLIP_NUM);
1132 Int3(); // Illegal type to boss actions
1137 multi_do_create_robot_powerups(char *buf)
1139 // Code to drop remote-controlled robot powerups
1143 int pnum, egg_objnum, i;
1145 pnum = buf[loc]; loc += 1;
1146 del_obj.contains_count = buf[loc]; loc += 1;
1147 del_obj.contains_type = buf[loc]; loc += 1;
1148 del_obj.contains_id = buf[loc]; loc += 1;
1149 del_obj.segnum = INTEL_SHORT( *(short *)(buf+loc) ); loc += 2;
1150 del_obj.pos = *(vms_vector *)(buf+loc); loc += 12;
1152 vm_vec_zero(&del_obj.mtype.phys_info.velocity);
1154 del_obj.pos.x = (fix)INTEL_INT((int)del_obj.pos.x);
1155 del_obj.pos.y = (fix)INTEL_INT((int)del_obj.pos.y);
1156 del_obj.pos.z = (fix)INTEL_INT((int)del_obj.pos.z);
1158 Assert((pnum >= 0) && (pnum < N_players));
1159 Assert (pnum!=Player_num); // What? How'd we send ourselves this?
1164 egg_objnum = object_create_egg(&del_obj);
1166 if (egg_objnum == -1)
1167 return; // Object buffer full
1169 // Assert(egg_objnum > -1);
1170 Assert((Net_create_loc > 0) && (Net_create_loc <= MAX_ROBOT_POWERUPS));
1172 for (i = 0; i < Net_create_loc; i++)
1176 s = INTEL_SHORT( *(short *)(buf+loc) );
1178 map_objnum_local_to_remote((short)Net_create_objnums[i], s, pnum);
1180 Objects[Net_create_objnums[i]].flags |= OF_SHOULD_BE_DEAD; // Delete objects other guy didn't create one of
1186 multi_drop_robot_powerups(int objnum)
1188 // Code to handle dropped robot powerups in network mode ONLY!
1191 int egg_objnum = -1;
1194 if ((objnum < 0) || (objnum > Highest_object_index))
1200 del_obj = &Objects[objnum];
1202 if (del_obj->type != OBJ_ROBOT)
1204 Int3(); // dropping powerups for non-robot, Rob's fault
1208 robptr = &Robot_info[del_obj->id];
1212 if (del_obj->contains_count > 0) {
1213 // If dropping a weapon that the player has, drop energy instead, unless it's vulcan, in which case drop vulcan ammo.
1214 if (del_obj->contains_type == OBJ_POWERUP) {
1215 maybe_replace_powerup_with_energy(del_obj);
1216 if (!multi_powerup_is_allowed(del_obj->contains_id))
1217 del_obj->contains_id=POW_SHIELD_BOOST;
1219 // No key drops in non-coop games!
1220 if (!(Game_mode & GM_MULTI_COOP)) {
1221 if ((del_obj->contains_id >= POW_KEY_BLUE) && (del_obj->contains_id <= POW_KEY_GOLD))
1222 del_obj->contains_count = 0;
1226 if (del_obj->contains_count > 0)
1227 egg_objnum = object_create_egg(del_obj);
1230 else if (del_obj->ctype.ai_info.REMOTE_OWNER == -1) // No random goodies for robots we weren't in control of
1233 else if (robptr->contains_count) {
1234 d_srand(timer_get_approx_seconds());
1235 if (((d_rand() * 16) >> 15) < robptr->contains_prob) {
1236 del_obj->contains_count = ((d_rand() * robptr->contains_count) >> 15) + 1;
1237 del_obj->contains_type = robptr->contains_type;
1238 del_obj->contains_id = robptr->contains_id;
1239 if (del_obj->contains_type == OBJ_POWERUP)
1241 maybe_replace_powerup_with_energy(del_obj);
1242 if (!multi_powerup_is_allowed(del_obj->contains_id))
1243 del_obj->contains_id=POW_SHIELD_BOOST;
1247 if (del_obj->contains_count > 0)
1248 egg_objnum = object_create_egg(del_obj);
1252 if (egg_objnum >= 0) {
1253 // Transmit the object creation to the other players
1254 mprintf((0, "Dropped %d powerups for robot %d.\n", Net_create_loc, del_obj-Objects));
1255 multi_send_create_robot_powerups(del_obj);
1259 // -----------------------------------------------------------------------------
1260 // Robot *robot got whacked by player player_num and requests permission to do something about it.
1261 // Note: This function will be called regardless of whether Game_mode is a multiplayer mode, so it
1262 // should quick-out if not in a multiplayer mode. On the other hand, it only gets called when a
1263 // player or player weapon whacks a robot, so it happens rarely.
1264 void multi_robot_request_change(object *robot, int player_num)
1266 int slot, remote_objnum;
1269 if (!(Game_mode & GM_MULTI_ROBOTS))
1272 // if (robot->ctype.ai_info.REMOTE_OWNER == Player_num)
1275 slot = robot->ctype.ai_info.REMOTE_SLOT_NUM;
1277 if ((slot < 0) || (slot >= MAX_ROBOTS_CONTROLLED)) {
1282 remote_objnum = objnum_local_to_remote(robot-Objects, &dummy);
1283 if (remote_objnum < 0)
1286 mprintf((0, "request_change(): my pri %d, player %d's pri %d.\n", MULTI_ROBOT_PRIORITY(remote_objnum, Player_num),
1287 player_num, MULTI_ROBOT_PRIORITY(remote_objnum, player_num)));
1289 if ( (robot_agitation[slot] < 70) || (MULTI_ROBOT_PRIORITY(remote_objnum, player_num) > MULTI_ROBOT_PRIORITY(remote_objnum, Player_num)) || (d_rand() > 0x4400))
1291 mprintf((0, "Robot %d (%d) released because it got hit by Player %d.\n", robot-Objects, remote_objnum, player_num));
1292 if (robot_send_pending[slot])
1293 multi_send_robot_position(robot_controlled[slot], -1);
1294 multi_send_release_robot(robot_controlled[slot]);
1295 robot->ctype.ai_info.REMOTE_SLOT_NUM = 5; // Hands-off period