From 4a562bf0989c66c2eb078a6cf45b8865e89cfa52 Mon Sep 17 00:00:00 2001 From: zico Date: Thu, 3 Sep 2015 15:13:56 +0200 Subject: [PATCH] Added multi_send_theif_frame() function to update thief bot more frequently (by PPS) and even if it is not controlled by a player to counter discrepancies caused by client side AI movement of the bot --- common/main/multibot.h | 3 +++ similar/main/multibot.cpp | 28 ++++++++++++++++++++++++++++ similar/main/net_udp.cpp | 3 +++ 3 files changed, 34 insertions(+) diff --git a/common/main/multibot.h b/common/main/multibot.h index 3a26acc89..72cd52ec9 100644 --- a/common/main/multibot.h +++ b/common/main/multibot.h @@ -52,6 +52,9 @@ void multi_send_boss_start_gate(objnum_t bossobjnum); void multi_send_boss_stop_gate(objnum_t bossobjnum); void multi_send_boss_create_robot(objnum_t bossobjnum, int robot_type, vobjptridx_t objnum); int multi_send_robot_frame(int sent); +#if defined(DXX_BUILD_DESCENT_II) +void multi_send_thief_frame(); +#endif void multi_do_robot_explode(const ubyte *buf); void multi_do_robot_position(playernum_t pnum, const ubyte *buf); diff --git a/similar/main/multibot.cpp b/similar/main/multibot.cpp index 9a9f0a6b4..d1f01180b 100644 --- a/similar/main/multibot.cpp +++ b/similar/main/multibot.cpp @@ -391,6 +391,34 @@ multi_send_robot_frame(int sent) return(rval); } +#if defined(DXX_BUILD_DESCENT_II) +/* + * The thief bot moves around even when not controlled by a player. Due to its erratic and random behaviour, it's movement will diverge heavily between players and cause it to teleport when a player takes over. + * To counter this, let host update positions when no one controls it OR the client which does. + * Seperated this function to allow the positions being updated more frequently then multi_send_robot_frame (see net_udp_do_frame()). + */ +void multi_send_thief_frame() +{ + if (!(Game_mode & GM_MULTI_ROBOTS)) + return; + + range_for (const auto i, highest_valid(Objects)) + { + if (Objects[i].type == OBJ_ROBOT) + { + if (robot_is_thief(&Robot_info[get_robot_id(&Objects[i])])) + { + if ((multi_i_am_master() && (Objects[i].ctype.ai_info.REMOTE_OWNER == -1)) || (Objects[i].ctype.ai_info.REMOTE_OWNER == Player_num)) + { + multi_send_robot_position_sub(i,1); + } + return; + } + } + } +} +#endif + void multi_send_robot_position_sub(const vobjptridx_t objnum, int now) { int loc = 0; diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 881403314..f31a2c869 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -4626,6 +4626,9 @@ void net_udp_do_frame(int force, int listen) { last_pdata_time = time; net_udp_send_pdata(); +#if defined(DXX_BUILD_DESCENT_II) + multi_send_thief_frame(); +#endif } if (force || (time >= (last_mdata_time+(F1_0/10))))