Server only function to clear a Guidebot for a disconnected player
| 9303 | |
| 9304 | // Server only function to clear a Guidebot for a disconnected player |
| 9305 | void MultiClearGuidebot(int slot) { |
| 9306 | if (!(Game_mode & GM_MULTI)) |
| 9307 | return; |
| 9308 | if (Netgame.local_role != LR_SERVER) |
| 9309 | return; |
| 9310 | if (!(Netgame.flags & NF_ALLOWGUIDEBOT)) |
| 9311 | return; |
| 9312 | |
| 9313 | // Kill off the old buddy bot |
| 9314 | object *buddy = ObjGet(Buddy_handle[slot]); |
| 9315 | if (buddy) { |
| 9316 | SetObjectDeadFlag(buddy, true, false); |
| 9317 | } |
| 9318 | Buddy_handle[slot] = OBJECT_HANDLE_NONE; |
| 9319 | |
| 9320 | // Recreate a buddy bot |
| 9321 | int parent_handle; |
| 9322 | if (Players[slot].objnum < 0 || Players[slot].objnum > Highest_object_index || |
| 9323 | Objects[Players[slot].objnum].type == OBJ_NONE) { |
| 9324 | parent_handle = OBJECT_HANDLE_NONE; |
| 9325 | } else { |
| 9326 | parent_handle = Objects[Players[slot].objnum].handle; |
| 9327 | } |
| 9328 | |
| 9329 | // BLACKPYRO |
| 9330 | int objnum = ObjCreate(OBJ_ROBOT, ROBOT_GUIDEBOT, Player_object->roomnum, &Player_object->pos, NULL, parent_handle); |
| 9331 | |
| 9332 | ASSERT(objnum != -1); |
| 9333 | if (objnum == -1) |
| 9334 | return; |
| 9335 | |
| 9336 | // tell the client about the new buddy |
| 9337 | MultiSendObject(&Objects[objnum], 0); |
| 9338 | |
| 9339 | InitObjectScripts(&Objects[objnum], true); |
| 9340 | |
| 9341 | Buddy_handle[slot] = Objects[objnum].handle; |
| 9342 | ObjGhostObject(objnum); |
| 9343 | |
| 9344 | MultiSendGhostObject(&Objects[objnum], true); |
| 9345 | |
| 9346 | // now update the buddy handle list of the clients |
| 9347 | int count = 0; |
| 9348 | int size_offset; |
| 9349 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 9350 | |
| 9351 | mprintf(0, "Sending Buddy_handle update to clients for Buddy#%d\n", slot); |
| 9352 | |
| 9353 | size_offset = START_DATA(MP_WORLD_STATES, data, &count); |
| 9354 | |
| 9355 | MultiAddByte(WS_BUDDYBOTUPDATE, data, &count); |
| 9356 | MultiAddByte(slot, data, &count); |
| 9357 | MultiAddUshort(Buddy_handle[slot] & HANDLE_OBJNUM_MASK, data, &count); |
| 9358 | |
| 9359 | MultiAddByte(WS_END, data, &count); |
| 9360 | END_DATA(count, data, size_offset); |
| 9361 | |
| 9362 | // Send it out |
no test coverage detected