| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Multiplayer code for network play. |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "dxxsconf.h" |
| 27 |
#include <bitset> |
| 28 |
#include <new> |
| 29 |
#include <stdexcept> |
| 30 |
#include <random> |
| 31 |
#include <stdio.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <string.h> |
| 34 |
#include <time.h> |
| 35 |
#include <ctype.h> |
| 36 |
#include <inttypes.h> |
| 37 |
#include <ranges> |
| 38 |
|
| 39 |
#include "u_mem.h" |
| 40 |
#include "strutil.h" |
| 41 |
#include "game.h" |
| 42 |
#include "multi.h" |
| 43 |
#include "multiinternal.h" |
| 44 |
#include "object.h" |
| 45 |
#include "player.h" |
| 46 |
#include "laser.h" |
| 47 |
#include "gauges.h" |
| 48 |
#include "gameseg.h" |
| 49 |
#include "weapon.h" |
| 50 |
#include "collide.h" |
| 51 |
#include "dxxerror.h" |
| 52 |
#include "fireball.h" |
| 53 |
#include "newmenu.h" |
| 54 |
#include "console.h" |
| 55 |
#include "wall.h" |
| 56 |
#include "cntrlcen.h" |
| 57 |
#include "powerup.h" |
| 58 |
#include "polyobj.h" |
| 59 |
#include "bm.h" |
| 60 |
#include "key.h" |
| 61 |
#include "playsave.h" |
| 62 |
#include "timer.h" |
| 63 |
#include "digi.h" |
| 64 |
#include "sounds.h" |
| 65 |
#include "kconfig.h" |
| 66 |
#include "hudmsg.h" |
| 67 |
#include "newdemo.h" |
| 68 |
#include "text.h" |
| 69 |
#include "kmatrix.h" |
| 70 |
#include "multibot.h" |
| 71 |
#include "gameseq.h" |
| 72 |
#include "physics.h" |
| 73 |
#include "switch.h" |
| 74 |
#include "textures.h" |
| 75 |
#include "sounds.h" |
| 76 |
#include "args.h" |
| 77 |
#include "effects.h" |
| 78 |
#include "iff.h" |
| 79 |
#include "state.h" |
| 80 |
#include "automap.h" |
| 81 |
#include "event.h" |
| 82 |
#include "d_array.h" |
| 83 |
#include "d_enumerate.h" |
| 84 |
#include "d_levelstate.h" |
| 85 |
#include "d_range.h" |
| 86 |
#include "d_underlying_value.h" |
| 87 |
#include "d_zip.h" |
| 88 |
|
| 89 |
#include "partial_range.h" |
| 90 |
#include <utility> |
| 91 |
|
| 92 |
#define array_snprintf(array,fmt,arg1,...) std::snprintf(array.data(), array.size(), fmt, arg1, ## __VA_ARGS__) |
| 93 |
|
| 94 |
constexpr std::integral_constant<int8_t, -1> owner_none{}; |
| 95 |
|
| 96 |
namespace dsx { |
| 97 |
|
| 98 |
namespace { |
| 99 |
|
| 100 |
static void MultiLevelInv_Repopulate(fix frequency); |
| 101 |
void multi_new_bounty_target_with_sound(playernum_t, const char *callsign); |
| 102 |
static void multi_reset_object_texture(object_base &objp); |
| 103 |
static void multi_process_data(const d_level_shared_robot_info_state &LevelSharedRobotInfoState, playernum_t pnum, std::span<const uint8_t> data, multiplayer_command_t type); |
| 104 |
static void multi_update_objects_for_non_cooperative(); |
| 105 |
static void multi_restore_game(unsigned slot, unsigned id); |
| 106 |
static void multi_save_game(unsigned slot, unsigned id, const d_game_unique_state::savegame_description &desc); |
| 107 |
static void multi_add_lifetime_killed(); |
| 108 |
#if !(!defined(RELEASE) && DXX_BUILD_DESCENT == 2) |
| 109 |
static void multi_add_lifetime_kills(int count); |
| 110 |
#endif |
| 111 |
|
| 112 |
static constexpr netflag_flag operator~(const netflag_flag a) |
| 113 |
{ |
| 114 |
return static_cast<netflag_flag>(~static_cast<uint32_t>(a)); |
| 115 |
} |
| 116 |
|
| 117 |
static constexpr netflag_flag operator|(const netflag_flag a, const netflag_flag b) |
| 118 |
{ |
| 119 |
return static_cast<netflag_flag>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); |
| 120 |
} |
| 121 |
|
| 122 |
static constexpr netflag_flag operator&(const netflag_flag a, const netflag_flag b) |
| 123 |
{ |
| 124 |
return static_cast<netflag_flag>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); |
| 125 |
} |
| 126 |
|
| 127 |
static constexpr netgrant_flag operator|(const netgrant_flag a, const netgrant_flag b) |
| 128 |
{ |
| 129 |
return static_cast<netgrant_flag>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); |
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
namespace { |
| 137 |
|
| 138 |
static void multi_send_heartbeat(); |
| 139 |
static void multi_send_ranking(netplayer_info::player_rank); |
| 140 |
static void multi_send_gmode_update(); |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
#if DXX_BUILD_DESCENT == 2 |
| 145 |
namespace dsx { |
| 146 |
|
| 147 |
namespace { |
| 148 |
|
| 149 |
static char hoard_ham_basename[]{"hoard.ham"}; |
| 150 |
|
| 151 |
static void multi_do_capture_bonus(const playernum_t pnum); |
| 152 |
static void multi_do_orb_bonus(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_ORB_BONUS> buf); |
| 153 |
static void multi_send_drop_flag(vmobjptridx_t objnum,int seed); |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
} |
| 158 |
#endif |
| 159 |
namespace dcx { |
| 160 |
namespace { |
| 161 |
static int imulti_new_game; // to prep stuff for level only when starting new game |
| 162 |
static std::size_t multi_message_index; |
| 163 |
static per_player_array<std::array<objnum_t, MAX_OBJECTS>> remote_to_local; // Remote object number for each local object |
| 164 |
static std::array<uint16_t, MAX_OBJECTS> local_to_remote; |
| 165 |
static per_player_array<unsigned> sorted_kills; |
| 166 |
static void multi_send_quit(); |
| 167 |
void multi_new_bounty_target(playernum_t, const char *callsign); |
| 168 |
|
| 169 |
using kill_name_storage = std::array<char, (CALLSIGN_LEN * 2) + 4>; |
| 170 |
|
| 171 |
[[nodiscard]] |
| 172 |
static const char *prepare_kill_name(fvcplayerptr &vcplayerptr, const game_mode_flags Game_mode, const netgame_info &Netgame, const vcplayeridx_t pnum, kill_name_storage &buf) |
| 173 |
{ |
| 174 |
const char *const callsign = vcplayerptr(pnum)->callsign; |
| 175 |
if (Game_mode & GM_TEAM) |
| 176 |
{ |
| 177 |
const auto r = std::data(buf); |
| 178 |
snprintf(r, std::size(buf), "%s (%s)", callsign, Netgame.team_name[multi_get_team_from_player(Netgame, pnum)].operator const char *()); |
| 179 |
return r; |
| 180 |
} |
| 181 |
else |
| 182 |
return callsign; |
| 183 |
} |
| 184 |
|
| 185 |
constexpr vms_angvec build_native_endian_angvec_from_little_endian(const vms_angvec &v) |
| 186 |
{ |
| 187 |
return vms_angvec{ |
| 188 |
.p = INTEL_SHORT(v.p), |
| 189 |
.b = INTEL_SHORT(v.b), |
| 190 |
.h = INTEL_SHORT(v.h), |
| 191 |
}; |
| 192 |
} |
| 193 |
|
| 194 |
constexpr vms_vector build_native_endian_vector_from_little_endian(const vms_vector &v) |
| 195 |
{ |
| 196 |
return vms_vector{ |
| 197 |
.x = INTEL_INT(v.x), |
| 198 |
.y = INTEL_INT(v.y), |
| 199 |
.z = INTEL_INT(v.z), |
| 200 |
}; |
| 201 |
} |
| 202 |
|
| 203 |
constexpr vms_matrix build_native_endian_matrix_from_little_endian(const vms_matrix &v) |
| 204 |
{ |
| 205 |
return vms_matrix{ |
| 206 |
.rvec = build_native_endian_vector_from_little_endian(v.rvec), |
| 207 |
.uvec = build_native_endian_vector_from_little_endian(v.uvec), |
| 208 |
.fvec = build_native_endian_vector_from_little_endian(v.fvec), |
| 209 |
}; |
| 210 |
} |
| 211 |
|
| 212 |
#define build_little_endian_angvec_from_native_endian build_native_endian_angvec_from_little_endian |
| 213 |
#define build_little_endian_matrix_from_native_endian build_native_endian_matrix_from_little_endian |
| 214 |
#define build_little_endian_vector_from_native_endian build_native_endian_vector_from_little_endian |
| 215 |
|
| 216 |
} |
| 217 |
DEFINE_SERIAL_UDT_TO_MESSAGE(shortpos, s, (s.bytemat, s.xo, s.yo, s.zo, s.segment, s.velx, s.vely, s.velz)); |
| 218 |
|
| 219 |
std::optional<network_state> build_network_state_from_untrusted(const uint8_t untrusted) |
| 220 |
{ |
| 221 |
switch (untrusted) |
| 222 |
{ |
| 223 |
case static_cast<uint8_t>(network_state::menu): |
| 224 |
case static_cast<uint8_t>(network_state::playing): |
| 225 |
case static_cast<uint8_t>(network_state::browsing): |
| 226 |
case static_cast<uint8_t>(network_state::waiting): |
| 227 |
case static_cast<uint8_t>(network_state::starting): |
| 228 |
case static_cast<uint8_t>(network_state::endlevel): |
| 229 |
return network_state{untrusted}; |
| 230 |
default: |
| 231 |
return std::nullopt; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
vms_vector multi_get_vector(const std::span<const uint8_t, 12> buf) |
| 236 |
{ |
| 237 |
return vms_vector{ |
| 238 |
GET_INTEL_INT<int32_t>(&buf[0]), |
| 239 |
GET_INTEL_INT<int32_t>(&buf[4]), |
| 240 |
GET_INTEL_INT<int32_t>(&buf[8]), |
| 241 |
}; |
| 242 |
} |
| 243 |
|
| 244 |
void multi_put_vector(uint8_t *const buf, const vms_vector &v) |
| 245 |
{ |
| 246 |
/* Copy the vms_vector into a local so that the compiler can prove that |
| 247 |
* `buf` does not alias the bytes of the vector. Optimizing builds will |
| 248 |
* eliminate this needless copy. |
| 249 |
* |
| 250 |
* With no aliasing, the compiler can use word-sized load/store |
| 251 |
* instructions. |
| 252 |
* |
| 253 |
* With possible aliasing, the compiler uses `fix` sized load/store, since |
| 254 |
* a store to `buf` may change the result of a subsequent load from an |
| 255 |
* aliased vms_vector. |
| 256 |
*/ |
| 257 |
const auto lv{v}; |
| 258 |
PUT_INTEL_INT(&buf[0], lv.x); |
| 259 |
PUT_INTEL_INT(&buf[4], lv.y); |
| 260 |
PUT_INTEL_INT(&buf[8], lv.z); |
| 261 |
} |
| 262 |
|
| 263 |
team_number multi_get_team_from_player(uint8_t team_vector, const playernum_t pnum) |
| 264 |
{ |
| 265 |
if (team_vector & (1 << pnum)) |
| 266 |
return team_number::red; |
| 267 |
else |
| 268 |
return team_number::blue; |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
namespace { |
| 273 |
static playernum_t multi_who_is_master(); |
| 274 |
static void multi_show_player_list(); |
| 275 |
static void multi_send_message(); |
| 276 |
} |
| 277 |
|
| 278 |
// |
| 279 |
// Global variables |
| 280 |
// |
| 281 |
|
| 282 |
namespace dcx { |
| 283 |
|
| 284 |
//do we draw the kill list on the HUD? |
| 285 |
show_kill_list_mode Show_kill_list = show_kill_list_mode::_1; |
| 286 |
bool Show_reticle_name{true}; |
| 287 |
fix Show_kill_list_timer{0}; |
| 288 |
|
| 289 |
} |
| 290 |
|
| 291 |
#if DXX_BUILD_DESCENT == 2 |
| 292 |
namespace dsx { |
| 293 |
hoard_highest_record hoard_highest_record_stats; |
| 294 |
} |
| 295 |
#endif |
| 296 |
|
| 297 |
namespace dcx { |
| 298 |
|
| 299 |
network_state Network_status; |
| 300 |
playernum_t Bounty_target; |
| 301 |
|
| 302 |
|
| 303 |
per_player_array<msgsend_state> multi_sending_message; |
| 304 |
multi_macro_message_index multi_defining_message{multi_macro_message_index::None}; |
| 305 |
|
| 306 |
std::array<sbyte, MAX_OBJECTS> object_owner; // Who created each object in my universe, -1 = loaded at start |
| 307 |
|
| 308 |
unsigned Net_create_loc; // pointer into previous array |
| 309 |
std::array<objnum_t, MAX_NET_CREATE_OBJECTS> Net_create_objnums; // For tracking object creation that will be sent to remote |
| 310 |
ntstring<MAX_MESSAGE_LEN - 1> Network_message; |
| 311 |
int Network_message_reciever=-1; |
| 312 |
per_player_array<per_player_array<uint16_t>> kill_matrix; |
| 313 |
per_team_array<int16_t> team_kills; |
| 314 |
int multi_quit_game{0}; |
| 315 |
|
| 316 |
} |
| 317 |
|
| 318 |
namespace dsx { |
| 319 |
|
| 320 |
const GMNames_array GMNames = {{ |
| 321 |
"Anarchy", |
| 322 |
"Team Anarchy", |
| 323 |
"Robo Anarchy", |
| 324 |
"Cooperative", |
| 325 |
#if DXX_BUILD_DESCENT == 1 |
| 326 |
"Unknown", |
| 327 |
"Unknown", |
| 328 |
"Unknown", |
| 329 |
#elif DXX_BUILD_DESCENT == 2 |
| 330 |
"Capture the Flag", |
| 331 |
"Hoard", |
| 332 |
"Team Hoard", |
| 333 |
#endif |
| 334 |
"Bounty" |
| 335 |
}}; |
| 336 |
const std::array<char[8], MULTI_GAME_TYPE_COUNT> GMNamesShrt = {{ |
| 337 |
"ANRCHY", |
| 338 |
"TEAM", |
| 339 |
"ROBO", |
| 340 |
"COOP", |
| 341 |
#if DXX_BUILD_DESCENT == 1 |
| 342 |
"UNKNOWN", |
| 343 |
"UNKNOWN", |
| 344 |
"UNKNOWN", |
| 345 |
#elif DXX_BUILD_DESCENT == 2 |
| 346 |
"FLAG", |
| 347 |
"HOARD", |
| 348 |
"TMHOARD", |
| 349 |
#endif |
| 350 |
"BOUNTY" |
| 351 |
}}; |
| 352 |
|
| 353 |
} |
| 354 |
|
| 355 |
namespace dcx { |
| 356 |
|
| 357 |
// For rejoin object syncing (used here and all protocols - globally) |
| 358 |
|
| 359 |
int Network_send_objects{0}; // Are we in the process of sending objects to a player? |
| 360 |
int Network_send_object_mode{0}; // What type of objects are we sending, static or dynamic? |
| 361 |
int Network_send_objnum = -1; // What object are we sending next? |
| 362 |
int Network_rejoined{0}; // Did WE rejoin this game? |
| 363 |
int Network_sending_extras{0}; |
| 364 |
int VerifyPlayerJoined=-1; // Player (num) to enter game before any ingame/extra stuff is being sent |
| 365 |
int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to. |
| 366 |
|
| 367 |
ushort my_segments_checksum{0}; |
| 368 |
|
| 369 |
|
| 370 |
per_player_array<std::array<bitmap_index, N_PLAYER_SHIP_TEXTURES>> multi_player_textures; |
| 371 |
|
| 372 |
// Globals for protocol-bound Refuse-functions |
| 373 |
char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam,RefusePlayerName[12]; |
| 374 |
fix64 RefuseTimeLimit{0}; |
| 375 |
|
| 376 |
namespace { |
| 377 |
constexpr int message_length[] = { |
| 378 |
#define define_message_length(NAME,SIZE) (SIZE), |
| 379 |
for_each_multiplayer_command(define_message_length) |
| 380 |
}; |
| 381 |
|
| 382 |
} |
| 383 |
|
| 384 |
} |
| 385 |
|
| 386 |
namespace dsx { |
| 387 |
|
| 388 |
netgame_info Netgame; |
| 389 |
multi_level_inv MultiLevelInv; |
| 390 |
|
| 391 |
} |
| 392 |
|
| 393 |
namespace dcx { |
| 394 |
const enumerated_array<char[16], 10, netplayer_info::player_rank> RankStrings{{{ |
| 395 |
"(unpatched)", |
| 396 |
"Cadet", |
| 397 |
"Ensign", |
| 398 |
"Lieutenant", |
| 399 |
"Lt.Commander", |
| 400 |
"Commander", |
| 401 |
"Captain", |
| 402 |
"Vice Admiral", |
| 403 |
"Admiral", |
| 404 |
"Demigod" |
| 405 |
}}}; |
| 406 |
|
| 407 |
netplayer_info::player_rank build_rank_from_untrusted(const uint8_t untrusted) |
| 408 |
{ |
| 409 |
switch (untrusted) |
| 410 |
{ |
| 411 |
case static_cast<uint8_t>(netplayer_info::player_rank::None): |
| 412 |
case static_cast<uint8_t>(netplayer_info::player_rank::Cadet): |
| 413 |
case static_cast<uint8_t>(netplayer_info::player_rank::Ensign): |
| 414 |
case static_cast<uint8_t>(netplayer_info::player_rank::Lieutenant): |
| 415 |
case static_cast<uint8_t>(netplayer_info::player_rank::LtCommander): |
| 416 |
case static_cast<uint8_t>(netplayer_info::player_rank::Commander): |
| 417 |
case static_cast<uint8_t>(netplayer_info::player_rank::Captain): |
| 418 |
case static_cast<uint8_t>(netplayer_info::player_rank::ViceAdmiral): |
| 419 |
case static_cast<uint8_t>(netplayer_info::player_rank::Admiral): |
| 420 |
case static_cast<uint8_t>(netplayer_info::player_rank::Demigod): |
| 421 |
return netplayer_info::player_rank{untrusted}; |
| 422 |
default: |
| 423 |
return netplayer_info::player_rank::None; |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
namespace dsx { |
| 429 |
const multi_allow_powerup_text_array multi_allow_powerup_text = {{ |
| 430 |
#define define_netflag_string(NAME,STR) STR, |
| 431 |
for_each_netflag_value(define_netflag_string) |
| 432 |
}}; |
| 433 |
} |
| 434 |
|
| 435 |
netplayer_info::player_rank GetMyNetRanking() |
| 436 |
{ |
| 437 |
int rank, eff; |
| 438 |
|
| 439 |
if (PlayerCfg.NetlifeKills + PlayerCfg.NetlifeKilled <= 0) |
| 440 |
return netplayer_info::player_rank::Cadet; |
| 441 |
|
| 442 |
rank=static_cast<int>((static_cast<float>(PlayerCfg.NetlifeKills)/3000.0)*8.0); |
| 443 |
|
| 444 |
eff = static_cast<int>( |
| 445 |
( |
| 446 |
static_cast<float>(PlayerCfg.NetlifeKills) / ( |
| 447 |
static_cast<float>(PlayerCfg.NetlifeKilled) + static_cast<float>(PlayerCfg.NetlifeKills) |
| 448 |
) |
| 449 |
) * 100.0 |
| 450 |
); |
| 451 |
|
| 452 |
if (rank>8) |
| 453 |
rank=8; |
| 454 |
|
| 455 |
if (eff<0) |
| 456 |
eff=0; |
| 457 |
|
| 458 |
if (eff<60) |
| 459 |
rank-=((59-eff)/10); |
| 460 |
|
| 461 |
if (rank<0) |
| 462 |
rank=0; |
| 463 |
if (rank>8) |
| 464 |
rank=8; |
| 465 |
|
| 466 |
return static_cast<netplayer_info::player_rank>(rank + 1); |
| 467 |
} |
| 468 |
|
| 469 |
// |
| 470 |
// Functions that replace what used to be macros |
| 471 |
// |
| 472 |
|
| 473 |
objnum_t objnum_remote_to_local(const uint16_t remote_objnum, const int8_t owner) |
| 474 |
{ |
| 475 |
if (owner == owner_none) |
| 476 |
return(remote_objnum); |
| 477 |
// Map a remote object number from owner to a local object number |
| 478 |
if ((owner >= N_players) || (owner < -1)) { |
| 479 |
Int3(); // Illegal! |
| 480 |
return(remote_objnum); |
| 481 |
} |
| 482 |
|
| 483 |
if (remote_objnum >= MAX_OBJECTS) |
| 484 |
return(object_none); |
| 485 |
|
| 486 |
auto result = remote_to_local[owner][remote_objnum]; |
| 487 |
return(result); |
| 488 |
} |
| 489 |
|
| 490 |
owned_remote_objnum objnum_local_to_remote(objnum_t local_objnum) |
| 491 |
{ |
| 492 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 493 |
// Map a local object number to a remote + owner |
| 494 |
if (local_objnum > Highest_object_index) |
| 495 |
{ |
| 496 |
return {owner_none, 0xffff}; |
| 497 |
} |
| 498 |
auto owner = object_owner[local_objnum]; |
| 499 |
if (owner == owner_none) |
| 500 |
return {owner, local_objnum}; |
| 501 |
auto result = local_to_remote[local_objnum]; |
| 502 |
const char *emsg; |
| 503 |
if ( |
| 504 |
((owner >= N_players || owner < -1) && (emsg = "illegal object owner", true)) || |
| 505 |
(result >= MAX_OBJECTS && (emsg = "illegal object remote number", true)) // See Rob, object has no remote number! |
| 506 |
) |
| 507 |
throw std::runtime_error(emsg); |
| 508 |
return {owner, result}; |
| 509 |
} |
| 510 |
|
| 511 |
void map_objnum_local_to_remote(const objnum_t local_objnum, const int remote_objnum, const int owner) |
| 512 |
{ |
| 513 |
// Add a mapping from a network remote object number to a local one |
| 514 |
Assert(local_objnum < MAX_OBJECTS); |
| 515 |
Assert(remote_objnum > -1); |
| 516 |
Assert(remote_objnum < MAX_OBJECTS); |
| 517 |
Assert(owner > -1); |
| 518 |
Assert(owner != Player_num); |
| 519 |
|
| 520 |
object_owner[local_objnum] = owner; |
| 521 |
|
| 522 |
remote_to_local[owner][remote_objnum] = local_objnum; |
| 523 |
local_to_remote[local_objnum] = remote_objnum; |
| 524 |
|
| 525 |
return; |
| 526 |
} |
| 527 |
|
| 528 |
void map_objnum_local_to_local(objnum_t local_objnum) |
| 529 |
{ |
| 530 |
// Add a mapping for our locally created objects |
| 531 |
Assert(local_objnum < MAX_OBJECTS); |
| 532 |
|
| 533 |
object_owner[local_objnum] = Player_num; |
| 534 |
remote_to_local[Player_num][local_objnum] = local_objnum; |
| 535 |
local_to_remote[local_objnum] = local_objnum; |
| 536 |
|
| 537 |
return; |
| 538 |
} |
| 539 |
|
| 540 |
void reset_network_objects() |
| 541 |
{ |
| 542 |
local_to_remote.fill(-1); |
| 543 |
range_for (auto &i, remote_to_local) |
| 544 |
i.fill(object_none); |
| 545 |
object_owner.fill(-1); |
| 546 |
} |
| 547 |
|
| 548 |
namespace dsx { |
| 549 |
|
| 550 |
namespace { |
| 551 |
|
| 552 |
void update_bounty_target() |
| 553 |
{ |
| 554 |
std::array<std::pair<playernum_t, const char *>, std::size(Players)> candidates{}; |
| 555 |
const auto b = candidates.begin(); |
| 556 |
auto iter = b; |
| 557 |
for (auto &&[idx, plr] : enumerate(Players)) |
| 558 |
if (plr.connected != player_connection_status::disconnected) |
| 559 |
*iter++ = {idx, plr.callsign}; |
| 560 |
const auto n = std::distance(b, iter); |
| 561 |
if (!n) |
| 562 |
return; |
| 563 |
auto &choice = candidates[d_rand() % n]; |
| 564 |
multi_new_bounty_target_with_sound(choice.first, choice.second); |
| 565 |
} |
| 566 |
|
| 567 |
} |
| 568 |
|
| 569 |
// |
| 570 |
// Part 1 : functions whose main purpose in life is to divert the flow |
| 571 |
// of execution to either network specific code based |
| 572 |
// on the curretn Game_mode value. |
| 573 |
// |
| 574 |
|
| 575 |
// Show a score list to end of net players |
| 576 |
kmatrix_result multi_endlevel_score() |
| 577 |
{ |
| 578 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 579 |
auto &vmobjptr = Objects.vmptr; |
| 580 |
player_connection_status old_connect{}; |
| 581 |
|
| 582 |
// Save connect state and change to new connect state |
| 583 |
if (Game_mode & GM_NETWORK) |
| 584 |
{ |
| 585 |
auto &plr = get_local_player(); |
| 586 |
old_connect = plr.connected; |
| 587 |
if (plr.connected != player_connection_status::died_in_mine) |
| 588 |
plr.connected = player_connection_status::end_menu; |
| 589 |
Network_status = network_state::endlevel; |
| 590 |
} |
| 591 |
|
| 592 |
// Do the actual screen we wish to show |
| 593 |
const auto rval = kmatrix_view(static_cast<kmatrix_network>(Game_mode & GM_NETWORK), Controls); |
| 594 |
|
| 595 |
// Restore connect state |
| 596 |
|
| 597 |
if (Game_mode & GM_NETWORK) |
| 598 |
{ |
| 599 |
get_local_player().connected = old_connect; |
| 600 |
} |
| 601 |
|
| 602 |
/* Door key flags should only be cleared in cooperative games, not |
| 603 |
* in other games. |
| 604 |
* |
| 605 |
* The capture-the-flag marker can be cleared unconditionally, but |
| 606 |
* would never have been set in a cooperative game. |
| 607 |
* |
| 608 |
* The kill goal count can be cleared unconditionally. |
| 609 |
* |
| 610 |
* For Descent 1, the only flags to clear are the door key flags. |
| 611 |
* Use a no-op mask in non-cooperative games, since there are no |
| 612 |
* flags to clear there. |
| 613 |
* |
| 614 |
* For Descent 2, clear door key flags or the capture-the-flag |
| 615 |
* flag, depending on game type. This version has the advantage of |
| 616 |
* making only one pass when in cooperative mode, where the previous |
| 617 |
* version would make one pass if in a cooperative game, then make |
| 618 |
* an unconditional pass to try to clear PLAYER_FLAGS_FLAG. |
| 619 |
*/ |
| 620 |
const auto clear_flags = (Game_mode & GM_MULTI_COOP) |
| 621 |
// Reset keys |
| 622 |
? ~player_flags(PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_GOLD_KEY | PLAYER_FLAGS_RED_KEY) |
| 623 |
: |
| 624 |
#if DXX_BUILD_DESCENT == 1 |
| 625 |
/* Nothing to clear. Set a mask that has no effect when |
| 626 |
* applied, so that the loop does not need to retest the |
| 627 |
* conditional on each pass. |
| 628 |
*/ |
| 629 |
player_flags(~0u) |
| 630 |
#elif DXX_BUILD_DESCENT == 2 |
| 631 |
// Clear capture flag |
| 632 |
~player_flags(PLAYER_FLAGS_FLAG) |
| 633 |
#endif |
| 634 |
; |
| 635 |
range_for (auto &i, partial_const_range(Players, Netgame.max_numplayers)) |
| 636 |
{ |
| 637 |
auto &obj = *vmobjptr(i.objnum); |
| 638 |
auto &player_info = obj.ctype.player_info; |
| 639 |
player_info.powerup_flags &= clear_flags; |
| 640 |
player_info.KillGoalCount = 0; |
| 641 |
} |
| 642 |
return rval; |
| 643 |
} |
| 644 |
|
| 645 |
} |
| 646 |
|
| 647 |
void multi_new_game() |
| 648 |
{ |
| 649 |
// Reset variables for a new net game |
| 650 |
reset_globals_for_new_game(); |
| 651 |
|
| 652 |
LevelUniqueObjectState.accumulated_robots = 0; |
| 653 |
LevelUniqueObjectState.total_hostages = 0; |
| 654 |
GameUniqueState.accumulated_robots = 0; |
| 655 |
GameUniqueState.total_hostages = 0; |
| 656 |
for (uint_fast32_t i = 0; i < MAX_PLAYERS; i++) |
| 657 |
init_player_stats_game(i); |
| 658 |
|
| 659 |
kill_matrix = {}; // Clear kill matrix |
| 660 |
|
| 661 |
for (playernum_t i = 0; i < MAX_PLAYERS; ++i) |
| 662 |
{ |
| 663 |
sorted_kills[i] = i; |
| 664 |
vmplayerptr(i)->connected = player_connection_status::disconnected; |
| 665 |
} |
| 666 |
multi_sending_message.fill(msgsend_state::none); |
| 667 |
|
| 668 |
robot_controlled.fill(-1); |
| 669 |
robot_agitation = {}; |
| 670 |
robot_fired = {}; |
| 671 |
|
| 672 |
team_kills = {}; |
| 673 |
imulti_new_game=1; |
| 674 |
multi_quit_game = 0; |
| 675 |
Show_kill_list = show_kill_list_mode::_1; |
| 676 |
game_disable_cheats(); |
| 677 |
} |
| 678 |
|
| 679 |
namespace dsx { |
| 680 |
|
| 681 |
void multi_make_player_ghost(const playernum_t playernum) |
| 682 |
{ |
| 683 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 684 |
auto &vmobjptridx = Objects.vmptridx; |
| 685 |
if (playernum == Player_num || playernum >= MAX_PLAYERS) |
| 686 |
{ |
| 687 |
Int3(); // Non-terminal, see Rob |
| 688 |
return; |
| 689 |
} |
| 690 |
const auto &&obj = vmobjptridx(vcplayerptr(playernum)->objnum); |
| 691 |
obj->type = OBJ_GHOST; |
| 692 |
obj->render_type = render_type::RT_NONE; |
| 693 |
obj->movement_source = object::movement_type::None; |
| 694 |
multi_reset_player_object(obj); |
| 695 |
multi_strip_robots(playernum); |
| 696 |
} |
| 697 |
|
| 698 |
void multi_make_ghost_player(const playernum_t playernum) |
| 699 |
{ |
| 700 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 701 |
auto &vmobjptridx = Objects.vmptridx; |
| 702 |
if ((playernum == Player_num) || (playernum >= MAX_PLAYERS)) |
| 703 |
{ |
| 704 |
Int3(); // Non-terminal, see rob |
| 705 |
return; |
| 706 |
} |
| 707 |
const auto &&obj = vmobjptridx(vcplayerptr(playernum)->objnum); |
| 708 |
obj->type = OBJ_PLAYER; |
| 709 |
obj->movement_source = object::movement_type::physics; |
| 710 |
multi_reset_player_object(obj); |
| 711 |
if (playernum != Player_num) |
| 712 |
init_player_stats_new_ship(playernum); |
| 713 |
} |
| 714 |
|
| 715 |
} |
| 716 |
|
| 717 |
int multi_get_kill_list(playernum_array_t &plist) |
| 718 |
{ |
| 719 |
// Returns the number of active net players and their |
| 720 |
// sorted order of kills |
| 721 |
int n{0}; |
| 722 |
|
| 723 |
range_for (const auto i, partial_const_range(sorted_kills, N_players)) |
| 724 |
//if (Players[sorted_kills[i]].connected) |
| 725 |
plist[n++] = i; |
| 726 |
|
| 727 |
if (n == 0) |
| 728 |
Int3(); // SEE ROB OR MATT |
| 729 |
|
| 730 |
//memcpy(plist, sorted_kills, N_players*sizeof(int)); |
| 731 |
|
| 732 |
return(n); |
| 733 |
} |
| 734 |
|
| 735 |
namespace dsx { |
| 736 |
|
| 737 |
void multi_sort_kill_list() |
| 738 |
{ |
| 739 |
const auto n_players{N_players}; |
| 740 |
if (n_players > std::size(sorted_kills)) |
| 741 |
return; |
| 742 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 743 |
// Sort the kills list each time a new kill is added |
| 744 |
const auto build_kill_list_sort_key{[](fvcobjptr &vcobjptr, const game_mode_flags game_mode, |
| 745 |
#if DXX_BUILD_DESCENT == 2 |
| 746 |
const show_kill_list_mode show_kill_list, |
| 747 |
#endif |
| 748 |
const player &plr) -> int { |
| 749 |
const auto o{plr.objnum}; |
| 750 |
if (o == object_none) |
| 751 |
return -1; |
| 752 |
auto &player_info = vcobjptr(o)->ctype.player_info; |
| 753 |
if (game_mode & GM_MULTI_COOP) |
| 754 |
return {player_info.mission.score}; |
| 755 |
const auto net_kills_total{player_info.net_kills_total}; |
| 756 |
#if DXX_BUILD_DESCENT == 2 |
| 757 |
if (show_kill_list == show_kill_list_mode::efficiency) |
| 758 |
{ |
| 759 |
const auto kk{player_info.net_killed_total + net_kills_total}; |
| 760 |
if (kk <= 0) |
| 761 |
// always draw the ones without any ratio last |
| 762 |
return kk - 1; |
| 763 |
const float net_kills_total_f = net_kills_total; |
| 764 |
return static_cast<int>(net_kills_total_f / ( |
| 765 |
static_cast<float>(player_info.net_killed_total) + net_kills_total_f |
| 766 |
) * 100.0f); |
| 767 |
} |
| 768 |
#endif |
| 769 |
return {net_kills_total}; |
| 770 |
}}; |
| 771 |
const auto build_kill_list_sort_keys{[build_kill_list_sort_key](fvcobjptr &vcobjptr, const game_mode_flags game_mode, |
| 772 |
#if DXX_BUILD_DESCENT == 2 |
| 773 |
const show_kill_list_mode show_kill_list, |
| 774 |
#endif |
| 775 |
fvcplayerptr &vcplayerptr) -> per_player_array<int> { |
| 776 |
per_player_array<int> kills; |
| 777 |
for (auto &&[k, plr] : zip(kills, vcplayerptr)) |
| 778 |
k = build_kill_list_sort_key(vcobjptr, game_mode, |
| 779 |
#if DXX_BUILD_DESCENT == 2 |
| 780 |
show_kill_list, |
| 781 |
#endif |
| 782 |
plr); |
| 783 |
return kills; |
| 784 |
}}; |
| 785 |
const auto projection{[keys = build_kill_list_sort_keys(Objects.vcptr, Game_mode, |
| 786 |
#if DXX_BUILD_DESCENT == 2 |
| 787 |
Show_kill_list, |
| 788 |
#endif |
| 789 |
vcplayerptr)](const unsigned sk) { |
| 790 |
return keys[sk]; |
| 791 |
}}; |
| 792 |
std::ranges::sort(std::span(sorted_kills).first(n_players), std::ranges::greater{}, std::ref(projection)); |
| 793 |
} |
| 794 |
|
| 795 |
namespace { |
| 796 |
|
| 797 |
static void print_kill_goal_tables(fvcobjptr &vcobjptr) |
| 798 |
{ |
| 799 |
const auto &local_player = get_local_player(); |
| 800 |
const auto pnum{Player_num}; |
| 801 |
con_printf(CON_NORMAL, "Kill goal statistics: player #%u \"%s\"", pnum, static_cast<const char *>(local_player.callsign)); |
| 802 |
for (auto &&[idx, i] : enumerate(Players)) |
| 803 |
{ |
| 804 |
if (i.connected == player_connection_status::disconnected) |
| 805 |
continue; |
| 806 |
auto &plrobj = *vcobjptr(i.objnum); |
| 807 |
auto &player_info = plrobj.ctype.player_info; |
| 808 |
con_printf(CON_NORMAL, "\t#%" DXX_PRI_size_type " \"%s\"\tdeaths=%i\tkills=%i\tmatrix=%hu/%hu", idx, static_cast<const char *>(i.callsign), player_info.net_killed_total, player_info.net_kills_total, kill_matrix[pnum][idx], kill_matrix[idx][pnum]); |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
static void net_destroy_controlcen(object_array &Objects, const d_robot_info_array &Robot_info) |
| 813 |
{ |
| 814 |
print_kill_goal_tables(Objects.vcptr); |
| 815 |
HUD_init_message_literal(HM_MULTI, "The control center has been destroyed!"); |
| 816 |
net_destroy_controlcen_object(Robot_info, obj_find_first_of_type(Objects.vmptridx, OBJ_CNTRLCEN)); |
| 817 |
} |
| 818 |
|
| 819 |
static void multi_compute_kill(const d_robot_info_array &Robot_info, const imobjptridx_t killer, object &killed) |
| 820 |
{ |
| 821 |
#if DXX_BUILD_DESCENT == 2 |
| 822 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 823 |
#endif |
| 824 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 825 |
auto &vmobjptr = Objects.vmptr; |
| 826 |
// Figure out the results of a network kills and add it to the |
| 827 |
// appropriate player's tally. |
| 828 |
|
| 829 |
playernum_t killed_pnum, killer_pnum; |
| 830 |
|
| 831 |
// Both object numbers are localized already! |
| 832 |
|
| 833 |
const auto killed_type{killed.type}; |
| 834 |
if ((killed_type != OBJ_PLAYER) && (killed_type != OBJ_GHOST)) |
| 835 |
{ |
| 836 |
Int3(); // compute_kill passed non-player object! |
| 837 |
return; |
| 838 |
} |
| 839 |
|
| 840 |
killed_pnum = get_player_id(killed); |
| 841 |
|
| 842 |
Assert (killed_pnum < N_players); |
| 843 |
|
| 844 |
kill_name_storage killed_buf; |
| 845 |
const auto killed_name = prepare_kill_name(vcplayerptr, Game_mode, Netgame, killed_pnum, killed_buf); |
| 846 |
|
| 847 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 848 |
newdemo_record_multi_death(killed_pnum); |
| 849 |
|
| 850 |
digi_play_sample( sound_effect::SOUND_HUD_KILL, F3_0 ); |
| 851 |
|
| 852 |
#if DXX_BUILD_DESCENT == 2 |
| 853 |
if (LevelUniqueControlCenterState.Control_center_destroyed) |
| 854 |
vmplayerptr(killed_pnum)->connected = player_connection_status::died_in_mine; |
| 855 |
#endif |
| 856 |
|
| 857 |
if (killer == object_none) |
| 858 |
return; |
| 859 |
const auto killer_type = killer->type; |
| 860 |
if (killer_type == OBJ_CNTRLCEN) |
| 861 |
{ |
| 862 |
if (Game_mode & GM_TEAM) |
| 863 |
-- team_kills[multi_get_team_from_player(Netgame, killed_pnum)]; |
| 864 |
++ killed.ctype.player_info.net_killed_total; |
| 865 |
-- killed.ctype.player_info.net_kills_total; |
| 866 |
-- killed.ctype.player_info.KillGoalCount; |
| 867 |
|
| 868 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 869 |
newdemo_record_multi_kill(killed_pnum, -1); |
| 870 |
|
| 871 |
if (killed_pnum == Player_num) |
| 872 |
{ |
| 873 |
HUD_init_message(HM_MULTI, "%s %s.", TXT_YOU_WERE, TXT_KILLED_BY_NONPLAY); |
| 874 |
multi_add_lifetime_killed (); |
| 875 |
} |
| 876 |
else |
| 877 |
HUD_init_message(HM_MULTI, "%s %s %s.", killed_name, TXT_WAS, TXT_KILLED_BY_NONPLAY ); |
| 878 |
return; |
| 879 |
} |
| 880 |
|
| 881 |
else if ((killer_type != OBJ_PLAYER) && (killer_type != OBJ_GHOST)) |
| 882 |
{ |
| 883 |
#if DXX_BUILD_DESCENT == 2 |
| 884 |
if (killer_type == OBJ_WEAPON && get_weapon_id(killer) == weapon_id_type::PMINE_ID) |
| 885 |
{ |
| 886 |
if (killed_pnum == Player_num) |
| 887 |
HUD_init_message_literal(HM_MULTI, "You were killed by a mine!"); |
| 888 |
else |
| 889 |
HUD_init_message(HM_MULTI, "%s was killed by a mine!",killed_name); |
| 890 |
} |
| 891 |
else |
| 892 |
#endif |
| 893 |
{ |
| 894 |
if (killed_pnum == Player_num) |
| 895 |
{ |
| 896 |
HUD_init_message(HM_MULTI, "%s %s.", TXT_YOU_WERE, TXT_KILLED_BY_ROBOT); |
| 897 |
multi_add_lifetime_killed(); |
| 898 |
} |
| 899 |
else |
| 900 |
HUD_init_message(HM_MULTI, "%s %s %s.", killed_name, TXT_WAS, TXT_KILLED_BY_ROBOT ); |
| 901 |
} |
| 902 |
++ killed.ctype.player_info.net_killed_total; |
| 903 |
return; |
| 904 |
} |
| 905 |
|
| 906 |
killer_pnum = get_player_id(killer); |
| 907 |
|
| 908 |
kill_name_storage killer_buf; |
| 909 |
const auto killer_name = prepare_kill_name(vcplayerptr, Game_mode, Netgame, killer_pnum, killer_buf); |
| 910 |
|
| 911 |
// Beyond this point, it was definitely a player-player kill situation |
| 912 |
|
| 913 |
if (killer_pnum >= N_players) |
| 914 |
Int3(); // See rob, tracking down bug with kill HUD messages |
| 915 |
if (killed_pnum >= N_players) |
| 916 |
Int3(); // See rob, tracking down bug with kill HUD messages |
| 917 |
|
| 918 |
kill_matrix[killer_pnum][killed_pnum] += 1; |
| 919 |
if (killer_pnum == killed_pnum) |
| 920 |
{ |
| 921 |
if (!game_mode_hoard(Game_mode)) |
| 922 |
{ |
| 923 |
if (Game_mode & GM_TEAM) |
| 924 |
{ |
| 925 |
team_kills[multi_get_team_from_player(Netgame, killed_pnum)] -= 1; |
| 926 |
} |
| 927 |
|
| 928 |
++ killed.ctype.player_info.net_killed_total; |
| 929 |
-- killed.ctype.player_info.net_kills_total; |
| 930 |
-- killed.ctype.player_info.KillGoalCount; |
| 931 |
|
| 932 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 933 |
newdemo_record_multi_kill(killed_pnum, -1); |
| 934 |
} |
| 935 |
if (killer_pnum == Player_num) |
| 936 |
{ |
| 937 |
HUD_init_message(HM_MULTI, "%s %s %s!", TXT_YOU, TXT_KILLED, TXT_YOURSELF ); |
| 938 |
multi_add_lifetime_killed(); |
| 939 |
} |
| 940 |
else |
| 941 |
HUD_init_message(HM_MULTI, "%s %s", killed_name, TXT_SUICIDE); |
| 942 |
|
| 943 |
/* Bounty mode needs some lovin' */ |
| 944 |
if( Game_mode & GM_BOUNTY && killed_pnum == Bounty_target && multi_i_am_master() ) |
| 945 |
{ |
| 946 |
update_bounty_target(); |
| 947 |
} |
| 948 |
} |
| 949 |
|
| 950 |
else |
| 951 |
{ |
| 952 |
short adjust{1}; |
| 953 |
/* Dead stores to prevent bogus -Wmaybe-uninitialized warnings |
| 954 |
* when the optimization level prevents the compiler from |
| 955 |
* recognizing that these are written in a team game and only |
| 956 |
* read in a team game. |
| 957 |
*/ |
| 958 |
team_number killed_team{}, killer_team{}; |
| 959 |
DXX_MAKE_VAR_UNDEFINED(killed_team); |
| 960 |
DXX_MAKE_VAR_UNDEFINED(killer_team); |
| 961 |
const auto is_team_game = Game_mode & GM_TEAM; |
| 962 |
if (is_team_game) |
| 963 |
{ |
| 964 |
killed_team = multi_get_team_from_player(Netgame, killed_pnum); |
| 965 |
killer_team = multi_get_team_from_player(Netgame, killer_pnum); |
| 966 |
if (killed_team == killer_team) |
| 967 |
adjust = -1; |
| 968 |
} |
| 969 |
if (!game_mode_hoard(Game_mode)) |
| 970 |
{ |
| 971 |
if (is_team_game) |
| 972 |
{ |
| 973 |
team_kills[killer_team] += adjust; |
| 974 |
killer->ctype.player_info.net_kills_total += adjust; |
| 975 |
killer->ctype.player_info.KillGoalCount += adjust; |
| 976 |
} |
| 977 |
else if( Game_mode & GM_BOUNTY ) |
| 978 |
{ |
| 979 |
/* Did the target die? Did the target get a kill? */ |
| 980 |
if( killed_pnum == Bounty_target || killer_pnum == Bounty_target ) |
| 981 |
{ |
| 982 |
/* Increment kill counts */ |
| 983 |
++ killer->ctype.player_info.net_kills_total; |
| 984 |
++ killer->ctype.player_info.KillGoalCount; |
| 985 |
|
| 986 |
/* If the target died, the new one is set! */ |
| 987 |
if( killed_pnum == Bounty_target ) |
| 988 |
multi_new_bounty_target_with_sound(killer_pnum, vcplayerptr(get_player_id(killer))->callsign); |
| 989 |
} |
| 990 |
} |
| 991 |
else |
| 992 |
{ |
| 993 |
++ killer->ctype.player_info.net_kills_total; |
| 994 |
++ killer->ctype.player_info.KillGoalCount; |
| 995 |
} |
| 996 |
|
| 997 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 998 |
newdemo_record_multi_kill(killer_pnum, 1); |
| 999 |
} |
| 1000 |
|
| 1001 |
++ killed.ctype.player_info.net_killed_total; |
| 1002 |
const char *name0, *name1; |
| 1003 |
if (killer_pnum == Player_num) { |
| 1004 |
if (Game_mode & GM_MULTI_COOP) |
| 1005 |
{ |
| 1006 |
auto &player_info = get_local_plrobj().ctype.player_info; |
| 1007 |
const auto local_player_score = player_info.mission.score; |
| 1008 |
add_points_to_score(player_info, local_player_score >= 1000 ? -1000 : -local_player_score, Game_mode); |
| 1009 |
} |
| 1010 |
else |
| 1011 |
multi_add_lifetime_kills(adjust); |
| 1012 |
name0 = TXT_YOU; |
| 1013 |
name1 = killed_name; |
| 1014 |
} |
| 1015 |
else if (name0 = killer_name, killed_pnum == Player_num) |
| 1016 |
{ |
| 1017 |
multi_add_lifetime_killed(); |
| 1018 |
name1 = TXT_YOU; |
| 1019 |
} |
| 1020 |
else |
| 1021 |
name1 = killed_name; |
| 1022 |
HUD_init_message(HM_MULTI, "%s %s %s!", name0, TXT_KILLED, name1); |
| 1023 |
} |
| 1024 |
|
| 1025 |
if (Netgame.KillGoal>0) |
| 1026 |
{ |
| 1027 |
const auto TheGoal = Netgame.KillGoal * 5; |
| 1028 |
if (((Game_mode & GM_TEAM) |
| 1029 |
? team_kills[multi_get_team_from_player(Netgame, killer_pnum)] |
| 1030 |
: killer->ctype.player_info.KillGoalCount |
| 1031 |
) >= TheGoal) |
| 1032 |
{ |
| 1033 |
if (killer_pnum==Player_num) |
| 1034 |
{ |
| 1035 |
HUD_init_message_literal(HM_MULTI, "You reached the kill goal!"); |
| 1036 |
get_local_plrobj().shields = i2f(200); |
| 1037 |
} |
| 1038 |
else |
| 1039 |
{ |
| 1040 |
kill_name_storage buf; |
| 1041 |
HUD_init_message(HM_MULTI, "%s has reached the kill goal!", prepare_kill_name(vcplayerptr, Game_mode, Netgame, killer_pnum, buf)); |
| 1042 |
} |
| 1043 |
net_destroy_controlcen(Objects, Robot_info); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
multi_sort_kill_list(); |
| 1048 |
multi_show_player_list(); |
| 1049 |
#if DXX_BUILD_DESCENT == 2 |
| 1050 |
// clear the killed guys flags/headlights |
| 1051 |
killed.ctype.player_info.powerup_flags &= ~(PLAYER_FLAGS_HEADLIGHT_ON); |
| 1052 |
#endif |
| 1053 |
} |
| 1054 |
|
| 1055 |
} |
| 1056 |
|
| 1057 |
} |
| 1058 |
|
| 1059 |
window_event_result multi_do_frame() |
| 1060 |
{ |
| 1061 |
static d_time_fix lasttime; |
| 1062 |
static fix64 last_gmode_time = 0, last_inventory_time = 0, last_repo_time = 0; |
| 1063 |
|
| 1064 |
if (!(Game_mode & GM_MULTI) || Newdemo_state == ND_STATE_PLAYBACK) |
| 1065 |
{ |
| 1066 |
Int3(); |
| 1067 |
return window_event_result::ignored; |
| 1068 |
} |
| 1069 |
|
| 1070 |
if ((Game_mode & GM_NETWORK) && Netgame.PlayTimeAllowed.count() && lasttime != ThisLevelTime) |
| 1071 |
{ |
| 1072 |
for (unsigned i = 0; i < N_players; ++i) |
| 1073 |
if (vcplayerptr(i)->connected != player_connection_status::disconnected) |
| 1074 |
{ |
| 1075 |
if (i==Player_num) |
| 1076 |
{ |
| 1077 |
multi_send_heartbeat(); |
| 1078 |
lasttime = ThisLevelTime; |
| 1079 |
} |
| 1080 |
break; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
|
| 1084 |
// Send update about our game mode-specific variables every 2 secs (to keep in sync since delayed kills can invalidate these infos on Clients) |
| 1085 |
if (multi_i_am_master() && timer_query() >= last_gmode_time + (F1_0*2)) |
| 1086 |
{ |
| 1087 |
multi_send_gmode_update(); |
| 1088 |
last_gmode_time = timer_query(); |
| 1089 |
} |
| 1090 |
|
| 1091 |
if (Network_status == network_state::playing) |
| 1092 |
{ |
| 1093 |
// Send out inventory three times per second |
| 1094 |
if (timer_query() >= last_inventory_time + (F1_0/3)) |
| 1095 |
{ |
| 1096 |
multi_send_player_inventory(multiplayer_data_priority::_0); |
| 1097 |
last_inventory_time = timer_query(); |
| 1098 |
} |
| 1099 |
// Repopulate the level if necessary |
| 1100 |
if (timer_query() >= last_repo_time + (F1_0/2)) |
| 1101 |
{ |
| 1102 |
MultiLevelInv_Repopulate((F1_0/2)); |
| 1103 |
last_repo_time = timer_query(); |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
multi_send_message(); // Send any waiting messages |
| 1108 |
|
| 1109 |
if (Game_mode & GM_MULTI_ROBOTS) |
| 1110 |
{ |
| 1111 |
multi_check_robot_timeout(); |
| 1112 |
} |
| 1113 |
|
| 1114 |
multi::dispatch->do_protocol_frame(0, 1); |
| 1115 |
|
| 1116 |
return multi_quit_game ? window_event_result::close : window_event_result::handled; |
| 1117 |
} |
| 1118 |
|
| 1119 |
namespace { |
| 1120 |
|
| 1121 |
template <multiplayer_command_t C> |
| 1122 |
#ifndef __clang__ |
| 1123 |
/* udp::dispatch_table::send_data_direct copies `buf` into a buffer sized from |
| 1124 |
* `UDP_mdata_info`. Require that no overflow will occur. |
| 1125 |
* |
| 1126 |
* Guard this with `#ifndef __clang__` because clang-14 rejects this constraint |
| 1127 |
* with the error: |
| 1128 |
|
| 1129 |
similar/main/multi.cpp:1068:22: note: because '(std::size(buf) + 6 <= sizeof(UDP_mdata_info))' would be invalid: constraint variable 'buf' cannot be used in an evaluated context |
| 1130 |
|
| 1131 |
* gcc accepts this requires() constraint and enforces it as intended. Raising |
| 1132 |
* the `6` to `6000` correctly provokes a rejection. |
| 1133 |
*/ |
| 1134 |
requires( |
| 1135 |
requires(multi_command<C> buf) { |
| 1136 |
requires(std::size(buf) + 6 <= sizeof(UDP_mdata_info)); |
| 1137 |
} |
| 1138 |
) |
| 1139 |
#endif |
| 1140 |
static inline void multi_send_data_direct(const multi_command<C> &buf, const playernum_t pnum, const int priority) |
| 1141 |
{ |
| 1142 |
multi::dispatch->send_data_direct(buf, pnum, priority); |
| 1143 |
} |
| 1144 |
|
| 1145 |
} |
| 1146 |
|
| 1147 |
namespace dsx { |
| 1148 |
|
| 1149 |
void multi_leave_game() |
| 1150 |
{ |
| 1151 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 1152 |
auto &vmobjptridx = Objects.vmptridx; |
| 1153 |
|
| 1154 |
if (!(Game_mode & GM_MULTI)) |
| 1155 |
return; |
| 1156 |
|
| 1157 |
if (!multi_i_am_master()) |
| 1158 |
{ |
| 1159 |
/* The host does not need to send item drops, because the game will end |
| 1160 |
* when the host quits. The multi_send_quit after this block will |
| 1161 |
* cause all guests to be ejected from the game, so no players would |
| 1162 |
* have time to pick up any items dropped by this block. |
| 1163 |
*/ |
| 1164 |
Net_create_loc = 0; |
| 1165 |
const auto cobjp = vmobjptridx(get_local_player().objnum); |
| 1166 |
multi_send_position(cobjp); |
| 1167 |
auto &player_info = cobjp->ctype.player_info; |
| 1168 |
if (!player_info.Player_eggs_dropped) |
| 1169 |
{ |
| 1170 |
player_info.Player_eggs_dropped = true; |
| 1171 |
drop_player_eggs(cobjp); |
| 1172 |
} |
| 1173 |
multi_send_player_deres(deres_drop); |
| 1174 |
} |
| 1175 |
|
| 1176 |
multi_send_quit(); |
| 1177 |
multi::dispatch->leave_game(); |
| 1178 |
|
| 1179 |
#if DXX_BUILD_DESCENT == 1 |
| 1180 |
plyr_save_stats(InterfaceUniqueState.PilotName, PlayerCfg.NetlifeKills, PlayerCfg.NetlifeKilled); |
| 1181 |
#endif |
| 1182 |
|
| 1183 |
multi_quit_game = 0; // quit complete |
| 1184 |
} |
| 1185 |
|
| 1186 |
} |
| 1187 |
|
| 1188 |
namespace { |
| 1189 |
|
| 1190 |
void multi_show_player_list() |
| 1191 |
{ |
| 1192 |
if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI_COOP)) |
| 1193 |
return; |
| 1194 |
|
| 1195 |
if (Show_kill_list != show_kill_list_mode::None) |
| 1196 |
return; |
| 1197 |
|
| 1198 |
Show_kill_list_timer = F1_0*5; // 5 second timer |
| 1199 |
Show_kill_list = show_kill_list_mode::_1; |
| 1200 |
} |
| 1201 |
|
| 1202 |
} |
| 1203 |
|
| 1204 |
// |
| 1205 |
// Part 2 : functions that act on network messages and change the |
| 1206 |
// the state of the game in some way. |
| 1207 |
// |
| 1208 |
|
| 1209 |
void multi_define_macro(const int key) |
| 1210 |
{ |
| 1211 |
if (!(Game_mode & GM_MULTI)) |
| 1212 |
return; |
| 1213 |
|
| 1214 |
switch (key & ~KEY_SHIFTED) |
| 1215 |
{ |
| 1216 |
case KEY_F9: |
| 1217 |
multi_defining_message = multi_macro_message_index::_0; |
| 1218 |
break; |
| 1219 |
case KEY_F10: |
| 1220 |
multi_defining_message = multi_macro_message_index::_1; |
| 1221 |
break; |
| 1222 |
case KEY_F11: |
| 1223 |
multi_defining_message = multi_macro_message_index::_2; |
| 1224 |
break; |
| 1225 |
case KEY_F12: |
| 1226 |
multi_defining_message = multi_macro_message_index::_3; |
| 1227 |
break; |
| 1228 |
default: |
| 1229 |
Int3(); |
| 1230 |
return; |
| 1231 |
} |
| 1232 |
{ |
| 1233 |
key_toggle_repeat(1); |
| 1234 |
multi_message_index = 0; |
| 1235 |
Network_message = {}; |
| 1236 |
} |
| 1237 |
} |
| 1238 |
|
| 1239 |
namespace { |
| 1240 |
|
| 1241 |
static void multi_message_feedback(void) |
| 1242 |
{ |
| 1243 |
char *colon; |
| 1244 |
int found{0}; |
| 1245 |
char feedback_result[200]; |
| 1246 |
|
| 1247 |
if (!(!(colon = strstr(Network_message.data(), ": ")) || colon == Network_message.data() || colon - Network_message.data() > CALLSIGN_LEN)) |
| 1248 |
{ |
| 1249 |
std::size_t feedlen = snprintf(feedback_result, sizeof(feedback_result), "%s ", TXT_MESSAGE_SENT_TO); |
| 1250 |
if (Game_mode & GM_TEAM) |
| 1251 |
{ |
| 1252 |
if (const auto o = Netgame.team_name.valid_index(Network_message[0u] - '1')) |
| 1253 |
{ |
| 1254 |
snprintf(feedback_result + feedlen, sizeof(feedback_result) - feedlen, "%s '%s'", TXT_TEAM, Netgame.team_name[*o].operator const char *()); |
| 1255 |
found = 1; |
| 1256 |
} |
| 1257 |
range_for (auto &i, Netgame.team_name) |
| 1258 |
{ |
| 1259 |
if (!d_strnicmp(i, Network_message.data(), colon - Network_message.data())) |
| 1260 |
{ |
| 1261 |
const char *comma = found ? ", " : ""; |
| 1262 |
found++; |
| 1263 |
const char *newline = (!(found % 4)) ? "\n" : ""; |
| 1264 |
size_t l = strlen(feedback_result); |
| 1265 |
snprintf(feedback_result + l, sizeof(feedback_result) - l, "%s%s%s '%s'", comma, newline, TXT_TEAM, static_cast<const char *>(i)); |
| 1266 |
} |
| 1267 |
} |
| 1268 |
} |
| 1269 |
const player *const local_player = &get_local_player(); |
| 1270 |
range_for (auto &i, partial_const_range(Players, N_players)) |
| 1271 |
{ |
| 1272 |
if (&i != local_player && i.connected != player_connection_status::disconnected && !d_strnicmp(static_cast<const char *>(i.callsign), Network_message.data(), colon - Network_message.data())) |
| 1273 |
{ |
| 1274 |
const char *comma = found ? ", " : ""; |
| 1275 |
found++; |
| 1276 |
const char *newline = (!(found % 4)) ? "\n" : ""; |
| 1277 |
size_t l = strlen(feedback_result); |
| 1278 |
snprintf(feedback_result + l, sizeof(feedback_result) - l, "%s%s%s", comma, newline, static_cast<const char *>(i.callsign)); |
| 1279 |
} |
| 1280 |
} |
| 1281 |
if (!found) |
| 1282 |
strcat(feedback_result, TXT_NOBODY); |
| 1283 |
else |
| 1284 |
strcat(feedback_result, "."); |
| 1285 |
|
| 1286 |
digi_play_sample(sound_effect::SOUND_HUD_MESSAGE, F1_0); |
| 1287 |
|
| 1288 |
Assert(strlen(feedback_result) < 200); |
| 1289 |
|
| 1290 |
HUD_init_message_literal(HM_MULTI, feedback_result); |
| 1291 |
} |
| 1292 |
} |
| 1293 |
|
| 1294 |
} |
| 1295 |
|
| 1296 |
void multi_send_macro(const int fkey) |
| 1297 |
{ |
| 1298 |
if (! (Game_mode & GM_MULTI) ) |
| 1299 |
return; |
| 1300 |
|
| 1301 |
multi_macro_message_index key; |
| 1302 |
switch (fkey) |
| 1303 |
{ |
| 1304 |
case KEY_F9: |
| 1305 |
key = multi_macro_message_index::_0; |
| 1306 |
break; |
| 1307 |
case KEY_F10: |
| 1308 |
key = multi_macro_message_index::_1; |
| 1309 |
break; |
| 1310 |
case KEY_F11: |
| 1311 |
key = multi_macro_message_index::_2; |
| 1312 |
break; |
| 1313 |
case KEY_F12: |
| 1314 |
key = multi_macro_message_index::_3; |
| 1315 |
break; |
| 1316 |
default: |
| 1317 |
Int3(); |
| 1318 |
return; |
| 1319 |
} |
| 1320 |
|
| 1321 |
if (!PlayerCfg.NetworkMessageMacro[key][0u]) |
| 1322 |
{ |
| 1323 |
const auto &&m = TXT_NO_MACRO; |
| 1324 |
HUD_init_message_literal(HM_MULTI, {m, strlen(m)}); |
| 1325 |
return; |
| 1326 |
} |
| 1327 |
|
| 1328 |
Network_message = PlayerCfg.NetworkMessageMacro[key]; |
| 1329 |
Network_message_reciever = 100; |
| 1330 |
|
| 1331 |
HUD_init_message(HM_MULTI, "%s '%s'", TXT_SENDING, Network_message.data()); |
| 1332 |
multi_message_feedback(); |
| 1333 |
} |
| 1334 |
|
| 1335 |
void multi_send_message_start() |
| 1336 |
{ |
| 1337 |
if (Game_mode&GM_MULTI) { |
| 1338 |
multi_sending_message[Player_num] = msgsend_state::typing; |
| 1339 |
multi_send_msgsend_state(msgsend_state::typing); |
| 1340 |
multi_message_index = 0; |
| 1341 |
Network_message = {}; |
| 1342 |
key_toggle_repeat(1); |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
namespace dsx { |
| 1347 |
|
| 1348 |
namespace { |
| 1349 |
|
| 1350 |
static void kick_player(const player &plr, netplayer_info &nplr) |
| 1351 |
{ |
| 1352 |
multi::dispatch->kick_player(nplr.protocol.udp.addr, kick_player_reason::kicked); |
| 1353 |
HUD_init_message(HM_MULTI, "Dumping %s...", static_cast<const char *>(plr.callsign)); |
| 1354 |
multi_message_index = 0; |
| 1355 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1356 |
#if DXX_BUILD_DESCENT == 2 |
| 1357 |
multi_send_msgsend_state(msgsend_state::none); |
| 1358 |
#endif |
| 1359 |
} |
| 1360 |
|
| 1361 |
static void multi_send_message_end(const d_robot_info_array &Robot_info, fvmobjptr &vmobjptr, control_info &Controls) |
| 1362 |
{ |
| 1363 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 1364 |
#if DXX_BUILD_DESCENT == 1 |
| 1365 |
multi_message_index = 0; |
| 1366 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1367 |
multi_send_msgsend_state(msgsend_state::none); |
| 1368 |
key_toggle_repeat(0); |
| 1369 |
#elif DXX_BUILD_DESCENT == 2 |
| 1370 |
Network_message_reciever = 100; |
| 1371 |
#endif |
| 1372 |
|
| 1373 |
if (!d_strnicmp(Network_message.data(), "/Handicap: ")) |
| 1374 |
{ |
| 1375 |
constexpr auto minimum_allowed_shields = 10ul; |
| 1376 |
constexpr auto maximum_allowed_shields = 100ul; |
| 1377 |
auto &plr = get_local_player(); |
| 1378 |
const char *const callsign = plr.callsign; |
| 1379 |
const auto requested_handicap = strtoul(&Network_message[11u], 0, 10); |
| 1380 |
const auto clamped_handicap_max = std::max(minimum_allowed_shields, requested_handicap); |
| 1381 |
const auto clamped_handicap_min = std::min(maximum_allowed_shields, clamped_handicap_max); |
| 1382 |
StartingShields = i2f(clamped_handicap_min); |
| 1383 |
if (clamped_handicap_min != clamped_handicap_max) |
| 1384 |
snprintf(Network_message.data(), Network_message.size(), "%s has tried to cheat!", callsign); |
| 1385 |
else |
| 1386 |
snprintf(Network_message.data(), Network_message.size(), "%s handicap is now %lu", callsign, clamped_handicap_min); |
| 1387 |
HUD_init_message(HM_MULTI, "Telling others of your handicap of %lu!",clamped_handicap_min); |
| 1388 |
} |
| 1389 |
else if (!d_strnicmp(Network_message.data(), "/move: ")) |
| 1390 |
{ |
| 1391 |
if ((Game_mode & GM_NETWORK) && (Game_mode & GM_TEAM)) |
| 1392 |
{ |
| 1393 |
if (!multi_i_am_master()) |
| 1394 |
{ |
| 1395 |
HUD_init_message(HM_MULTI, "Only %s can move players!",static_cast<const char *>(Players[multi_who_is_master()].callsign)); |
| 1396 |
return; |
| 1397 |
} |
| 1398 |
|
| 1399 |
unsigned name_index{7}; |
| 1400 |
const auto nlen = strlen(Network_message.data()); |
| 1401 |
if (nlen > 7) |
| 1402 |
while (Network_message[name_index] == ' ') |
| 1403 |
name_index++; |
| 1404 |
|
| 1405 |
if (nlen <= name_index) |
| 1406 |
{ |
| 1407 |
HUD_init_message_literal(HM_MULTI, "You must specify a name to move"); |
| 1408 |
return; |
| 1409 |
} |
| 1410 |
|
| 1411 |
for (unsigned i = 0; i < N_players; ++i) |
| 1412 |
if (vcplayerptr(i)->connected != player_connection_status::disconnected && !d_strnicmp(static_cast<const char *>(vcplayerptr(i)->callsign), &Network_message[name_index], nlen - name_index)) |
| 1413 |
{ |
| 1414 |
#if DXX_BUILD_DESCENT == 2 |
| 1415 |
if (game_mode_capture_flag(Game_mode) && (vmobjptr(vcplayerptr(i)->objnum)->ctype.player_info.powerup_flags & PLAYER_FLAGS_FLAG)) |
| 1416 |
{ |
| 1417 |
HUD_init_message_literal(HM_MULTI, "Can't move player because s/he has a flag!"); |
| 1418 |
return; |
| 1419 |
} |
| 1420 |
#endif |
| 1421 |
if (Netgame.team_vector & (1<<i)) |
| 1422 |
Netgame.team_vector&=(~(1<<i)); |
| 1423 |
else |
| 1424 |
Netgame.team_vector|=(1<<i); |
| 1425 |
|
| 1426 |
range_for (auto &t, partial_const_range(Players, N_players)) |
| 1427 |
if (t.connected != player_connection_status::disconnected) |
| 1428 |
multi_reset_object_texture(vmobjptr(t.objnum)); |
| 1429 |
reset_cockpit(); |
| 1430 |
|
| 1431 |
multi_send_gmode_update(); |
| 1432 |
|
| 1433 |
snprintf(Network_message.data(), Network_message.size(), "%s has changed teams!", static_cast<const char *>(vcplayerptr(i)->callsign)); |
| 1434 |
if (i==Player_num) |
| 1435 |
{ |
| 1436 |
HUD_init_message_literal(HM_MULTI, "You have changed teams!"); |
| 1437 |
reset_cockpit(); |
| 1438 |
} |
| 1439 |
else |
| 1440 |
HUD_init_message(HM_MULTI, "Moving %s to other team.", static_cast<const char *>(vcplayerptr(i)->callsign)); |
| 1441 |
break; |
| 1442 |
} |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
else if (!d_strnicmp(Network_message.data(), "/kick: ") && (Game_mode & GM_NETWORK)) |
| 1447 |
{ |
| 1448 |
if (!multi_i_am_master()) |
| 1449 |
{ |
| 1450 |
HUD_init_message(HM_MULTI, "Only %s can kick others out!", static_cast<const char *>(Players[multi_who_is_master()].callsign)); |
| 1451 |
multi_message_index = 0; |
| 1452 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1453 |
#if DXX_BUILD_DESCENT == 2 |
| 1454 |
multi_send_msgsend_state(msgsend_state::none); |
| 1455 |
#endif |
| 1456 |
return; |
| 1457 |
} |
| 1458 |
unsigned name_index{7}; |
| 1459 |
const auto nlen = strlen(Network_message.data()); |
| 1460 |
if (nlen > 7) |
| 1461 |
while (Network_message[name_index] == ' ') |
| 1462 |
name_index++; |
| 1463 |
|
| 1464 |
if (nlen <= name_index) |
| 1465 |
{ |
| 1466 |
HUD_init_message_literal(HM_MULTI, "You must specify a name to kick"); |
| 1467 |
multi_message_index = 0; |
| 1468 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1469 |
#if DXX_BUILD_DESCENT == 2 |
| 1470 |
multi_send_msgsend_state(msgsend_state::none); |
| 1471 |
#endif |
| 1472 |
return; |
| 1473 |
} |
| 1474 |
|
| 1475 |
if (Network_message[name_index] == '#' && isdigit(Network_message[name_index+1])) { |
| 1476 |
playernum_array_t players; |
| 1477 |
int listpos = Network_message[name_index+1] - '0'; |
| 1478 |
|
| 1479 |
if (Show_kill_list == show_kill_list_mode::_1 || Show_kill_list == show_kill_list_mode::efficiency) |
| 1480 |
{ |
| 1481 |
if (listpos == 0 || listpos >= N_players) { |
| 1482 |
HUD_init_message_literal(HM_MULTI, "Invalid player number for kick."); |
| 1483 |
multi_message_index = 0; |
| 1484 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1485 |
#if DXX_BUILD_DESCENT == 2 |
| 1486 |
multi_send_msgsend_state(msgsend_state::none); |
| 1487 |
#endif |
| 1488 |
return; |
| 1489 |
} |
| 1490 |
multi_get_kill_list(players); |
| 1491 |
const auto i = players[listpos]; |
| 1492 |
if (i != Player_num && vcplayerptr(i)->connected != player_connection_status::disconnected) |
| 1493 |
{ |
| 1494 |
kick_player(*vcplayerptr(i), Netgame.players[i]); |
| 1495 |
return; |
| 1496 |
} |
| 1497 |
} |
| 1498 |
else HUD_init_message_literal(HM_MULTI, "You cannot use # kicking with in team display."); |
| 1499 |
|
| 1500 |
|
| 1501 |
multi_message_index = 0; |
| 1502 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1503 |
#if DXX_BUILD_DESCENT == 2 |
| 1504 |
multi_send_msgsend_state(msgsend_state::none); |
| 1505 |
#endif |
| 1506 |
return; |
| 1507 |
} |
| 1508 |
|
| 1509 |
for (unsigned i = 0; i < N_players; i++) |
| 1510 |
if (i != Player_num && vcplayerptr(i)->connected != player_connection_status::disconnected && !d_strnicmp(static_cast<const char *>(vcplayerptr(i)->callsign), &Network_message[name_index], nlen - name_index)) |
| 1511 |
{ |
| 1512 |
kick_player(*vcplayerptr(i), Netgame.players[i]); |
| 1513 |
return; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
else if (!d_stricmp (Network_message.data(), "/killreactor") && (Game_mode & GM_NETWORK) && !LevelUniqueControlCenterState.Control_center_destroyed) |
| 1517 |
{ |
| 1518 |
if (!multi_i_am_master()) |
| 1519 |
HUD_init_message(HM_MULTI, "Only %s can kill the reactor this way!", static_cast<const char *>(Players[multi_who_is_master()].callsign)); |
| 1520 |
else |
| 1521 |
{ |
| 1522 |
net_destroy_controlcen_object(Robot_info, object_none); |
| 1523 |
multi_send_destroy_controlcen(object_none,Player_num); |
| 1524 |
} |
| 1525 |
multi_message_index = 0; |
| 1526 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1527 |
#if DXX_BUILD_DESCENT == 2 |
| 1528 |
multi_send_msgsend_state(msgsend_state::none); |
| 1529 |
#endif |
| 1530 |
return; |
| 1531 |
} |
| 1532 |
|
| 1533 |
#if DXX_BUILD_DESCENT == 2 |
| 1534 |
else |
| 1535 |
#endif |
| 1536 |
HUD_init_message(HM_MULTI, "%s '%s'", TXT_SENDING, Network_message.data()); |
| 1537 |
|
| 1538 |
multi_send_message(); |
| 1539 |
multi_message_feedback(); |
| 1540 |
|
| 1541 |
#if DXX_BUILD_DESCENT == 1 |
| 1542 |
Network_message_reciever = 100; |
| 1543 |
#elif DXX_BUILD_DESCENT == 2 |
| 1544 |
multi_message_index = 0; |
| 1545 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1546 |
multi_send_msgsend_state(msgsend_state::none); |
| 1547 |
key_toggle_repeat(0); |
| 1548 |
#endif |
| 1549 |
game_flush_inputs(Controls); |
| 1550 |
} |
| 1551 |
|
| 1552 |
static void multi_define_macro_end(control_info &Controls) |
| 1553 |
{ |
| 1554 |
const auto defining{multi_defining_message}; |
| 1555 |
if (!PlayerCfg.NetworkMessageMacro.valid_index(defining)) |
| 1556 |
return; |
| 1557 |
multi_defining_message = multi_macro_message_index::None; |
| 1558 |
PlayerCfg.NetworkMessageMacro[defining] = Network_message; |
| 1559 |
write_player_file(); |
| 1560 |
|
| 1561 |
multi_message_index = 0; |
| 1562 |
key_toggle_repeat(0); |
| 1563 |
game_flush_inputs(Controls); |
| 1564 |
} |
| 1565 |
|
| 1566 |
} |
| 1567 |
|
| 1568 |
window_event_result multi_message_input_sub(const d_robot_info_array &Robot_info, const int key, control_info &Controls) |
| 1569 |
{ |
| 1570 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 1571 |
auto &vmobjptr = Objects.vmptr; |
| 1572 |
switch( key ) |
| 1573 |
{ |
| 1574 |
case KEY_F8: |
| 1575 |
case KEY_ESC: |
| 1576 |
multi_sending_message[Player_num] = msgsend_state::none; |
| 1577 |
multi_send_msgsend_state(msgsend_state::none); |
| 1578 |
multi_defining_message = multi_macro_message_index::None; |
| 1579 |
key_toggle_repeat(0); |
| 1580 |
game_flush_inputs(Controls); |
| 1581 |
return window_event_result::handled; |
| 1582 |
case KEY_LEFT: |
| 1583 |
case KEY_BACKSP: |
| 1584 |
case KEY_PAD4: |
| 1585 |
if (multi_message_index > 0) |
| 1586 |
multi_message_index--; |
| 1587 |
Network_message[multi_message_index] = 0; |
| 1588 |
return window_event_result::handled; |
| 1589 |
case KEY_ENTER: |
| 1590 |
if (multi_sending_message[Player_num] != msgsend_state::none) |
| 1591 |
multi_send_message_end(Robot_info, vmobjptr, Controls); |
| 1592 |
else if (multi_defining_message != multi_macro_message_index::None) |
| 1593 |
multi_define_macro_end(Controls); |
| 1594 |
game_flush_inputs(Controls); |
| 1595 |
return window_event_result::handled; |
| 1596 |
default: |
| 1597 |
{ |
| 1598 |
int ascii = key_ascii(); |
| 1599 |
if ( ascii < 255 ) { |
| 1600 |
if (multi_message_index < MAX_MESSAGE_LEN-2 ) { |
| 1601 |
Network_message[multi_message_index++] = ascii; |
| 1602 |
Network_message[multi_message_index] = 0; |
| 1603 |
} |
| 1604 |
else if (auto &sending = multi_sending_message[Player_num]; sending != msgsend_state::none) |
| 1605 |
{ |
| 1606 |
const char *ptext = nullptr; |
| 1607 |
Network_message[std::size(Network_message) - 2] = ascii; |
| 1608 |
Network_message.back() = 0; |
| 1609 |
const auto nmb = Network_message.begin(); |
| 1610 |
/* Start at the end of the message and scan backward for |
| 1611 |
* the first space. Start the scan at the second-to-last |
| 1612 |
* element, since the last element was set to null above, |
| 1613 |
* and so is guaranteed not to be a space. |
| 1614 |
*/ |
| 1615 |
for (auto nmi = std::prev(Network_message.end());;) |
| 1616 |
{ |
| 1617 |
if (auto &c = * -- nmi; c == ' ') |
| 1618 |
{ |
| 1619 |
/* Found a space. Replace it with a null, and save |
| 1620 |
* a pointer to the first non-space after the |
| 1621 |
* space. |
| 1622 |
*/ |
| 1623 |
c = 0; |
| 1624 |
ptext = std::next(nmi); |
| 1625 |
break; |
| 1626 |
} |
| 1627 |
/* The scan reached the beginning of the buffer without |
| 1628 |
* finding a space. Break anyway to avoid scanning |
| 1629 |
* before the beginning of the buffer. |
| 1630 |
*/ |
| 1631 |
if (nmi == nmb) |
| 1632 |
break; |
| 1633 |
} |
| 1634 |
multi_send_message_end(Robot_info, vmobjptr, Controls); |
| 1635 |
if ( ptext ) { |
| 1636 |
sending = msgsend_state::typing; |
| 1637 |
multi_send_msgsend_state(msgsend_state::typing); |
| 1638 |
auto pcolon = strstr(Network_message.data(), ": " ); |
| 1639 |
std::move(ptext, std::cend(Network_message), pcolon ? std::next(pcolon, 2) : Network_message.data()); |
| 1640 |
multi_message_index = strlen( Network_message ); |
| 1641 |
} |
| 1642 |
} |
| 1643 |
} |
| 1644 |
} |
| 1645 |
} |
| 1646 |
return window_event_result::ignored; |
| 1647 |
} |
| 1648 |
|
| 1649 |
namespace { |
| 1650 |
|
| 1651 |
static void multi_do_fire(fvmobjptridx &vmobjptridx, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_FIRE> buf, const icobjidx_t Network_laser_track, const std::optional<uint16_t> remote_objnum) |
| 1652 |
{ |
| 1653 |
// Act out the actual shooting |
| 1654 |
const uint8_t untrusted_raw_weapon = buf[2]; |
| 1655 |
|
| 1656 |
const auto flags{buf[4]}; |
| 1657 |
|
| 1658 |
const auto shot_orientation = multi_get_vector(buf.subspan<5, 12>()); |
| 1659 |
|
| 1660 |
Assert (pnum < N_players); |
| 1661 |
|
| 1662 |
const auto &&obj = vmobjptridx(vcplayerptr(pnum)->objnum); |
| 1663 |
if (obj->type == OBJ_GHOST) |
| 1664 |
multi_make_ghost_player(pnum); |
| 1665 |
|
| 1666 |
if (untrusted_raw_weapon == FLARE_ADJUST) |
| 1667 |
Laser_player_fire(LevelSharedRobotInfoState.Robot_info, obj, weapon_id_type::FLARE_ID, player_gun_number::center, weapon_sound_flag::audible, shot_orientation, object_none); |
| 1668 |
else if (const uint8_t untrusted_missile_adjusted_weapon = untrusted_raw_weapon - MISSILE_ADJUST; untrusted_missile_adjusted_weapon < MAX_SECONDARY_WEAPONS) |
| 1669 |
{ |
| 1670 |
const auto weapon = secondary_weapon_index_t{untrusted_missile_adjusted_weapon}; |
| 1671 |
const auto weapon_id = Secondary_weapon_to_weapon_info[weapon]; |
| 1672 |
const auto base_weapon_gun = Secondary_weapon_to_gun_num[weapon]; |
| 1673 |
const auto weapon_gun = (base_weapon_gun == player_gun_number::_4) |
| 1674 |
? static_cast<player_gun_number>(static_cast<uint8_t>(base_weapon_gun) + (flags & 1)) |
| 1675 |
: base_weapon_gun; |
| 1676 |
|
| 1677 |
const auto &&objnum = Laser_player_fire(LevelSharedRobotInfoState.Robot_info, obj, weapon_id, weapon_gun, weapon_sound_flag::audible, shot_orientation, Network_laser_track); |
| 1678 |
if (remote_objnum) |
| 1679 |
map_objnum_local_to_remote(objnum, *remote_objnum, pnum); |
| 1680 |
} |
| 1681 |
else if (const uint8_t untrusted_weapon = untrusted_raw_weapon; untrusted_weapon < MAX_PRIMARY_WEAPONS) |
| 1682 |
{ |
| 1683 |
const auto weapon = primary_weapon_index_t{untrusted_weapon}; |
| 1684 |
if (weapon == primary_weapon_index_t::FUSION_INDEX) { |
| 1685 |
obj->ctype.player_info.Fusion_charge = flags << 12; |
| 1686 |
} |
| 1687 |
if (weapon == primary_weapon_index_t::LASER_INDEX) |
| 1688 |
{ |
| 1689 |
auto &powerup_flags = obj->ctype.player_info.powerup_flags; |
| 1690 |
if (flags & LASER_QUAD) |
| 1691 |
powerup_flags |= PLAYER_FLAGS_QUAD_LASERS; |
| 1692 |
else |
| 1693 |
powerup_flags &= ~PLAYER_FLAGS_QUAD_LASERS; |
| 1694 |
} |
| 1695 |
|
| 1696 |
do_laser_firing(obj, weapon, laser_level{buf[3]}, flags, shot_orientation, Network_laser_track); |
| 1697 |
} |
| 1698 |
} |
| 1699 |
|
| 1700 |
static void multi_do_message(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_MESSAGE> cbuf) |
| 1701 |
{ |
| 1702 |
const auto buf = reinterpret_cast<const char *>(cbuf.data()); |
| 1703 |
const char *colon; |
| 1704 |
const char *msgstart; |
| 1705 |
int loc{2}; |
| 1706 |
|
| 1707 |
if (((colon = strstr(buf+loc, ": ")) == NULL) || (colon-(buf+loc) < 1) || (colon-(buf+loc) > CALLSIGN_LEN)) |
| 1708 |
{ |
| 1709 |
msgstart = buf + 2; |
| 1710 |
} |
| 1711 |
else |
| 1712 |
{ |
| 1713 |
/* if |
| 1714 |
* - it is addressed to me by name OR |
| 1715 |
* - team mode is active AND one of: |
| 1716 |
* - it is addressed to the number of my team OR |
| 1717 |
* - it is addressed to the name of my team |
| 1718 |
* |
| 1719 |
* then show it. Otherwise, hide it. |
| 1720 |
*/ |
| 1721 |
if ( (!d_strnicmp(static_cast<const char *>(get_local_player().callsign), buf+loc, colon-(buf+loc))) || |
| 1722 |
((Game_mode & GM_TEAM) && ({ |
| 1723 |
const auto local_player_team = multi_get_team_from_player(Netgame, Player_num); |
| 1724 |
(buf + loc + 1 == colon && ({ |
| 1725 |
/* The length is correct, so this might or might not be a team number. */ |
| 1726 |
const auto o = Netgame.team_name.valid_index(buf[loc] - '1'); |
| 1727 |
o && local_player_team == *o; |
| 1728 |
}) |
| 1729 |
) || |
| 1730 |
!d_strnicmp(Netgame.team_name[local_player_team], buf+loc, colon-(buf+loc)); |
| 1731 |
}))) |
| 1732 |
{ |
| 1733 |
msgstart = colon + 2; |
| 1734 |
} |
| 1735 |
else |
| 1736 |
return; |
| 1737 |
} |
| 1738 |
const auto color{get_player_or_team_color(Netgame, Game_mode, pnum)}; |
| 1739 |
char xrgb = BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b); |
| 1740 |
digi_play_sample(sound_effect::SOUND_HUD_MESSAGE, F1_0); |
| 1741 |
HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, static_cast<const char *>(vcplayerptr(pnum)->callsign), CC_COLOR, BM_XRGB(0, 31, 0), msgstart); |
| 1742 |
multi_sending_message[pnum] = msgsend_state::none; |
| 1743 |
} |
| 1744 |
|
| 1745 |
static void multi_do_position(object_array &Objects, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_POSITION> buf) |
| 1746 |
{ |
| 1747 |
auto &vmobjptridx{Objects.vmptridx}; |
| 1748 |
const auto &&obj = vmobjptridx(vcplayerptr(pnum)->objnum); |
| 1749 |
int count{1}; |
| 1750 |
|
| 1751 |
quaternionpos qpp{}; |
| 1752 |
qpp.orient.w = GET_INTEL_SHORT(&buf[count]); count += 2; |
| 1753 |
qpp.orient.x = GET_INTEL_SHORT(&buf[count]); count += 2; |
| 1754 |
qpp.orient.y = GET_INTEL_SHORT(&buf[count]); count += 2; |
| 1755 |
qpp.orient.z = GET_INTEL_SHORT(&buf[count]); count += 2; |
| 1756 |
qpp.pos = multi_get_vector(buf.subspan<9, 12>()); |
| 1757 |
count += 12; |
| 1758 |
if (const auto s{vmsegidx_t::check_nothrow_index(GET_INTEL_SHORT(&buf[count]))}) |
| 1759 |
{ |
| 1760 |
qpp.segment = *s; |
| 1761 |
count += 2; |
| 1762 |
} |
| 1763 |
else |
| 1764 |
return; |
| 1765 |
qpp.vel = multi_get_vector(buf.subspan<9 + 12 + 2, 12>()); |
| 1766 |
count += 12; |
| 1767 |
qpp.rotvel = multi_get_vector(buf.subspan<9 + 12 + 2 + 12, 12>()); |
| 1768 |
count += 12; |
| 1769 |
extract_quaternionpos(Objects.vmptr, vmsegptr, obj, qpp); |
| 1770 |
|
| 1771 |
if (obj->movement_source == object::movement_type::physics) |
| 1772 |
set_thrust_from_velocity(obj); |
| 1773 |
} |
| 1774 |
|
| 1775 |
static void multi_do_reappear(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_REAPPEAR> buf) |
| 1776 |
{ |
| 1777 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 1778 |
auto &vcobjptr = Objects.vcptr; |
| 1779 |
const objnum_t objnum{GET_INTEL_SHORT(&buf[2])}; |
| 1780 |
|
| 1781 |
const auto &&uobj = vcobjptr.check_untrusted(objnum); |
| 1782 |
if (!uobj) |
| 1783 |
return; |
| 1784 |
auto &obj = **uobj; |
| 1785 |
if (obj.type != OBJ_PLAYER && obj.type != OBJ_GHOST) |
| 1786 |
{ |
| 1787 |
con_printf(CON_URGENT, "%s:%u: BUG: object %hu has type %u, expected %u or %u", __FILE__, __LINE__, objnum, obj.type, OBJ_PLAYER, OBJ_GHOST); |
| 1788 |
return; |
| 1789 |
} |
| 1790 |
/* Override macro, call only the getter. |
| 1791 |
* |
| 1792 |
* This message is overloaded to be used on both players and ghosts, |
| 1793 |
* so the standard check cannot be used. Instead, the correct check |
| 1794 |
* is open-coded above. |
| 1795 |
*/ |
| 1796 |
if (pnum != (get_player_id)(obj)) |
| 1797 |
return; |
| 1798 |
|
| 1799 |
multi_make_ghost_player(pnum); |
| 1800 |
create_player_appearance_effect(Vclip, obj); |
| 1801 |
} |
| 1802 |
|
| 1803 |
static void multi_do_player_deres(const d_robot_info_array &Robot_info, object_array &Objects, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_PLAYER_DERES> buf) |
| 1804 |
{ |
| 1805 |
auto &vmobjptridx = Objects.vmptridx; |
| 1806 |
auto &vmobjptr = Objects.vmptr; |
| 1807 |
// Only call this for players, not robots. pnum is player number, not |
| 1808 |
// Object number. |
| 1809 |
|
| 1810 |
int count; |
| 1811 |
char remote_created; |
| 1812 |
|
| 1813 |
#ifdef NDEBUG |
| 1814 |
if (pnum >= N_players) |
| 1815 |
return; |
| 1816 |
#else |
| 1817 |
Assert(pnum < N_players); |
| 1818 |
#endif |
| 1819 |
|
| 1820 |
// If we are in the process of sending objects to a new player, reset that process |
| 1821 |
if (Network_send_objects) |
| 1822 |
{ |
| 1823 |
Network_send_objnum = -1; |
| 1824 |
} |
| 1825 |
|
| 1826 |
// Stuff the Players structure to prepare for the explosion |
| 1827 |
|
| 1828 |
count = 3; |
| 1829 |
#if DXX_BUILD_DESCENT == 1 |
| 1830 |
#define GET_WEAPON_FLAGS(buf,count) buf[count++] |
| 1831 |
#elif DXX_BUILD_DESCENT == 2 |
| 1832 |
#define GET_WEAPON_FLAGS(buf,count) (count += sizeof(uint16_t), GET_INTEL_SHORT(&buf[(count - sizeof(uint16_t))])) |
| 1833 |
#endif |
| 1834 |
const auto &&objp = vmobjptridx(vcplayerptr(pnum)->objnum); |
| 1835 |
auto &player_info = objp->ctype.player_info; |
| 1836 |
player_info.primary_weapon_flags = GET_WEAPON_FLAGS(buf, count); |
| 1837 |
player_info.laser_level = laser_level{buf[count]}; |
| 1838 |
count++; |
| 1839 |
if (game_mode_hoard(Game_mode)) |
| 1840 |
player_info.hoard.orbs = buf[count]; |
| 1841 |
count++; |
| 1842 |
|
| 1843 |
auto &secondary_ammo = player_info.secondary_ammo; |
| 1844 |
secondary_ammo[secondary_weapon_index_t::HOMING_INDEX] = buf[count]; count++; |
| 1845 |
secondary_ammo[secondary_weapon_index_t::CONCUSSION_INDEX] = buf[count];count++; |
| 1846 |
secondary_ammo[secondary_weapon_index_t::SMART_INDEX] = buf[count]; count++; |
| 1847 |
secondary_ammo[secondary_weapon_index_t::MEGA_INDEX] = buf[count]; count++; |
| 1848 |
secondary_ammo[secondary_weapon_index_t::PROXIMITY_INDEX] = buf[count]; count++; |
| 1849 |
|
| 1850 |
#if DXX_BUILD_DESCENT == 2 |
| 1851 |
secondary_ammo[secondary_weapon_index_t::SMISSILE1_INDEX] = buf[count]; count++; |
| 1852 |
secondary_ammo[secondary_weapon_index_t::GUIDED_INDEX] = buf[count]; count++; |
| 1853 |
secondary_ammo[secondary_weapon_index_t::SMART_MINE_INDEX]= buf[count]; count++; |
| 1854 |
secondary_ammo[secondary_weapon_index_t::SMISSILE4_INDEX] = buf[count]; count++; |
| 1855 |
secondary_ammo[secondary_weapon_index_t::SMISSILE5_INDEX] = buf[count]; count++; |
| 1856 |
#endif |
| 1857 |
|
| 1858 |
player_info.vulcan_ammo = GET_INTEL_SHORT(&buf[count]); count += 2; |
| 1859 |
player_info.powerup_flags = player_flags(GET_INTEL_INT(&buf[count])); count += 4; |
| 1860 |
|
| 1861 |
// objp->phys_info.velocity = *reinterpret_cast<vms_vector *>(buf+16); // 12 bytes |
| 1862 |
// objp->pos = *reinterpret_cast<vms_vector *>(buf+28); // 12 bytes |
| 1863 |
|
| 1864 |
remote_created = buf[count++]; // How many did the other guy create? |
| 1865 |
|
| 1866 |
Net_create_loc = 0; |
| 1867 |
drop_player_eggs(objp); |
| 1868 |
|
| 1869 |
// Create mapping from remote to local numbering system |
| 1870 |
|
| 1871 |
// We now handle this situation gracefully, Int3 not required |
| 1872 |
// if (Net_create_loc != remote_created) |
| 1873 |
// Int3(); // Probably out of object array space, see Rob |
| 1874 |
|
| 1875 |
range_for (const auto i, partial_const_range(Net_create_objnums, std::min(Net_create_loc, static_cast<unsigned>(remote_created)))) |
| 1876 |
{ |
| 1877 |
const int16_t s{GET_INTEL_SHORT<int16_t>(&buf[count])}; |
| 1878 |
if (s > 0) |
| 1879 |
map_objnum_local_to_remote(i, s, pnum); |
| 1880 |
count += 2; |
| 1881 |
} |
| 1882 |
range_for (const auto i, partial_const_range(Net_create_objnums, remote_created, Net_create_loc)) |
| 1883 |
{ |
| 1884 |
vmobjptr(i)->flags |= OF_SHOULD_BE_DEAD; |
| 1885 |
} |
| 1886 |
|
| 1887 |
if (buf[2] == deres_explode) |
| 1888 |
{ |
| 1889 |
explode_badass_player(Robot_info, objp); |
| 1890 |
|
| 1891 |
objp->flags &= ~OF_SHOULD_BE_DEAD; //don't really kill player |
| 1892 |
multi_make_player_ghost(pnum); |
| 1893 |
} |
| 1894 |
else |
| 1895 |
{ |
| 1896 |
create_player_appearance_effect(Vclip, objp); |
| 1897 |
} |
| 1898 |
|
| 1899 |
player_info.powerup_flags &= ~(PLAYER_FLAGS_CLOAKED | PLAYER_FLAGS_INVULNERABLE); |
| 1900 |
#if DXX_BUILD_DESCENT == 2 |
| 1901 |
player_info.powerup_flags &= ~PLAYER_FLAGS_FLAG; |
| 1902 |
#endif |
| 1903 |
DXX_MAKE_VAR_UNDEFINED(player_info.cloak_time); |
| 1904 |
} |
| 1905 |
|
| 1906 |
/* |
| 1907 |
* Process can compute a kill. If I am a Client this might be my own one (see multi_send_kill()) but with more specific data so I can compute my kill correctly. |
| 1908 |
*/ |
| 1909 |
static void multi_do_kill_host(object_array &Objects, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_KILL_HOST> buf) |
| 1910 |
{ |
| 1911 |
int count{1}; |
| 1912 |
|
| 1913 |
if (multi_i_am_master()) |
| 1914 |
return; |
| 1915 |
const auto killed = vcplayerptr(pnum)->objnum; |
| 1916 |
count += 1; |
| 1917 |
objnum_t killer{GET_INTEL_SHORT(&buf[count])}; |
| 1918 |
if (killer > 0) |
| 1919 |
killer = objnum_remote_to_local(killer, buf[count+2]); |
| 1920 |
Netgame.team_vector = buf[5]; |
| 1921 |
Bounty_target = buf[6]; |
| 1922 |
|
| 1923 |
multi_compute_kill(LevelSharedRobotInfoState.Robot_info, Objects.imptridx(killer), Objects.vmptridx(killed)); |
| 1924 |
} |
| 1925 |
|
| 1926 |
static void multi_do_kill_client(object_array &Objects, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_KILL_CLIENT> buf) |
| 1927 |
{ |
| 1928 |
if (!multi_i_am_master()) |
| 1929 |
return; |
| 1930 |
int count{1}; |
| 1931 |
// I am host, I know what's going on so take this packet, add game_mode related info which might be necessary for kill computation and send it to everyone so they can compute their kills correctly |
| 1932 |
{ |
| 1933 |
multi_command<multiplayer_command_t::MULTI_KILL_HOST> multibuf; |
| 1934 |
std::memcpy(std::next(multibuf.data()), std::next(buf.data()), 4); |
| 1935 |
multibuf[5] = Netgame.team_vector; |
| 1936 |
multibuf[6] = Bounty_target; |
| 1937 |
|
| 1938 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 1939 |
} |
| 1940 |
|
| 1941 |
const auto killed = vcplayerptr(pnum)->objnum; |
| 1942 |
count += 1; |
| 1943 |
objnum_t killer{GET_INTEL_SHORT(&buf[count])}; |
| 1944 |
if (killer > 0) |
| 1945 |
killer = objnum_remote_to_local(killer, buf[count+2]); |
| 1946 |
|
| 1947 |
multi_compute_kill(LevelSharedRobotInfoState.Robot_info, Objects.imptridx(killer), Objects.vmptridx(killed)); |
| 1948 |
|
| 1949 |
if (Game_mode & GM_BOUNTY) // update in case if needed... we could attach this to this packet but... meh... |
| 1950 |
multi_send_bounty(); |
| 1951 |
} |
| 1952 |
|
| 1953 |
// Changed by MK on 10/20/94 to send NULL as object to net_destroy_controlcen if it got -1 |
| 1954 |
// which means not a controlcen object, but contained in another object |
| 1955 |
static void multi_do_controlcen_destroy(const d_robot_info_array &Robot_info, fimobjptridx &imobjptridx, const multiplayer_rspan<multiplayer_command_t::MULTI_CONTROLCEN> buf) |
| 1956 |
{ |
| 1957 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 1958 |
const objnum_t objnum{GET_INTEL_SHORT(&buf[1])}; |
| 1959 |
const playernum_t who = buf[3]; |
| 1960 |
|
| 1961 |
if (LevelUniqueControlCenterState.Control_center_destroyed != 1) |
| 1962 |
{ |
| 1963 |
if ((who < N_players) && (who != Player_num)) { |
| 1964 |
HUD_init_message(HM_MULTI, "%s %s", static_cast<const char *>(vcplayerptr(who)->callsign), TXT_HAS_DEST_CONTROL); |
| 1965 |
} |
| 1966 |
else |
| 1967 |
HUD_init_message_literal(HM_MULTI, who == Player_num ? ( { const auto &&m = TXT_YOU_DEST_CONTROL; std::span<const char>(m, strlen(m)); }) : ( { const auto &&m = TXT_CONTROL_DESTROYED; std::span<const char>(m, strlen(m)); })); |
| 1968 |
|
| 1969 |
net_destroy_controlcen_object(Robot_info, objnum == object_none ? object_none : imobjptridx(objnum)); |
| 1970 |
} |
| 1971 |
} |
| 1972 |
|
| 1973 |
static void multi_do_escape(fvmobjptridx &vmobjptridx, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_ENDLEVEL_START> buf) |
| 1974 |
{ |
| 1975 |
digi_play_sample(sound_effect::SOUND_HUD_MESSAGE, F1_0); |
| 1976 |
auto &plr = *vmplayerptr(pnum); |
| 1977 |
const auto &&objnum = vmobjptridx(plr.objnum); |
| 1978 |
#if DXX_BUILD_DESCENT == 2 |
| 1979 |
digi_kill_sound_linked_to_object (objnum); |
| 1980 |
#endif |
| 1981 |
|
| 1982 |
const char *txt; |
| 1983 |
player_connection_status connected; |
| 1984 |
#if DXX_BUILD_DESCENT == 1 |
| 1985 |
if (buf[2] == static_cast<uint8_t>(multi_endlevel_type::secret)) |
| 1986 |
{ |
| 1987 |
txt = TXT_HAS_FOUND_SECRET; |
| 1988 |
connected = player_connection_status::found_secret; |
| 1989 |
} |
| 1990 |
else |
| 1991 |
#endif |
| 1992 |
{ |
| 1993 |
txt = TXT_HAS_ESCAPED; |
| 1994 |
connected = player_connection_status::escape_tunnel; |
| 1995 |
} |
| 1996 |
HUD_init_message(HM_MULTI, "%s %s", static_cast<const char *>(plr.callsign), txt); |
| 1997 |
if (Game_mode & GM_NETWORK) |
| 1998 |
plr.connected = connected; |
| 1999 |
create_player_appearance_effect(Vclip, objnum); |
| 2000 |
multi_make_player_ghost(buf[1]); |
| 2001 |
} |
| 2002 |
|
| 2003 |
static void multi_do_remobj(fvmobjptr &vmobjptr, const multiplayer_rspan<multiplayer_command_t::MULTI_REMOVE_OBJECT> buf) |
| 2004 |
{ |
| 2005 |
// which object to remove |
| 2006 |
const objnum_t objnum{GET_INTEL_SHORT(&buf[1])}; |
| 2007 |
// which remote list is it entered in |
| 2008 |
auto obj_owner = buf[3]; |
| 2009 |
|
| 2010 |
if (objnum < 1) |
| 2011 |
return; |
| 2012 |
|
| 2013 |
const auto local_objnum = objnum_remote_to_local(objnum, obj_owner); // translate to local objnum |
| 2014 |
if (local_objnum == object_none) |
| 2015 |
{ |
| 2016 |
return; |
| 2017 |
} |
| 2018 |
|
| 2019 |
auto &obj = *vmobjptr(local_objnum); |
| 2020 |
if (obj.type != OBJ_POWERUP && obj.type != OBJ_HOSTAGE) |
| 2021 |
{ |
| 2022 |
return; |
| 2023 |
} |
| 2024 |
|
| 2025 |
if (Network_send_objects && multi::dispatch->objnum_is_past(local_objnum)) |
| 2026 |
{ |
| 2027 |
Network_send_objnum = -1; |
| 2028 |
} |
| 2029 |
|
| 2030 |
obj.flags |= OF_SHOULD_BE_DEAD; // quick and painless |
| 2031 |
} |
| 2032 |
|
| 2033 |
} |
| 2034 |
|
| 2035 |
} |
| 2036 |
|
| 2037 |
void multi_disconnect_player(const playernum_t pnum) |
| 2038 |
{ |
| 2039 |
if (!(Game_mode & GM_NETWORK)) |
| 2040 |
return; |
| 2041 |
if (vcplayerptr(pnum)->connected == player_connection_status::disconnected) |
| 2042 |
return; |
| 2043 |
|
| 2044 |
if (vcplayerptr(pnum)->connected == player_connection_status::playing) |
| 2045 |
{ |
| 2046 |
digi_play_sample( sound_effect::SOUND_HUD_MESSAGE, F1_0 ); |
| 2047 |
HUD_init_message(HM_MULTI, "%s %s", static_cast<const char *>(vcplayerptr(pnum)->callsign), TXT_HAS_LEFT_THE_GAME); |
| 2048 |
|
| 2049 |
multi_sending_message[pnum] = msgsend_state::none; |
| 2050 |
|
| 2051 |
if (Network_status == network_state::playing) |
| 2052 |
{ |
| 2053 |
multi_make_player_ghost(pnum); |
| 2054 |
multi_strip_robots(pnum); |
| 2055 |
} |
| 2056 |
|
| 2057 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 2058 |
newdemo_record_multi_disconnect(pnum); |
| 2059 |
|
| 2060 |
// Bounty target left - select a new one |
| 2061 |
if( Game_mode & GM_BOUNTY && pnum == Bounty_target && multi_i_am_master() ) |
| 2062 |
{ |
| 2063 |
update_bounty_target(); |
| 2064 |
/* Send this new data */ |
| 2065 |
multi_send_bounty(); |
| 2066 |
} |
| 2067 |
} |
| 2068 |
|
| 2069 |
vmplayerptr(pnum)->connected = player_connection_status::disconnected; |
| 2070 |
Netgame.players[pnum].connected = player_connection_status::disconnected; |
| 2071 |
|
| 2072 |
multi::dispatch->disconnect_player(pnum); |
| 2073 |
|
| 2074 |
if (pnum == multi_who_is_master()) // Host has left - Quit game! |
| 2075 |
{ |
| 2076 |
const auto g{Game_wind}; |
| 2077 |
if (g) |
| 2078 |
g->set_visible(0); |
| 2079 |
struct host_left_game : passive_messagebox |
| 2080 |
{ |
| 2081 |
host_left_game() : |
| 2082 |
passive_messagebox(menu_title{nullptr}, menu_subtitle{"Host left the game!"}, TXT_OK, grd_curscreen->sc_canvas) |
| 2083 |
{ |
| 2084 |
} |
| 2085 |
}; |
| 2086 |
run_blocking_newmenu<host_left_game>(); |
| 2087 |
if (g) |
| 2088 |
g->set_visible(1); |
| 2089 |
multi_quit_game = 1; |
| 2090 |
game_leave_menus(); |
| 2091 |
return; |
| 2092 |
} |
| 2093 |
|
| 2094 |
int n{0}; |
| 2095 |
range_for (auto &i, partial_const_range(Players, N_players)) |
| 2096 |
if (i.connected != player_connection_status::disconnected) |
| 2097 |
if (++n > 1) |
| 2098 |
break; |
| 2099 |
if (n == 1) |
| 2100 |
{ |
| 2101 |
HUD_init_message_literal(HM_MULTI, "You are the only person remaining in this netgame"); |
| 2102 |
} |
| 2103 |
} |
| 2104 |
|
| 2105 |
namespace { |
| 2106 |
|
| 2107 |
static void multi_do_quit(const playernum_t pnum) |
| 2108 |
{ |
| 2109 |
multi_disconnect_player(pnum); |
| 2110 |
} |
| 2111 |
|
| 2112 |
} |
| 2113 |
|
| 2114 |
namespace dsx { |
| 2115 |
|
| 2116 |
namespace { |
| 2117 |
|
| 2118 |
static void multi_do_cloak(fvmobjptr &vmobjptr, const playernum_t pnum) |
| 2119 |
{ |
| 2120 |
Assert(pnum < N_players); |
| 2121 |
|
| 2122 |
const auto &&objp = vmobjptr(vcplayerptr(pnum)->objnum); |
| 2123 |
auto &player_info = objp->ctype.player_info; |
| 2124 |
player_info.powerup_flags |= PLAYER_FLAGS_CLOAKED; |
| 2125 |
player_info.cloak_time = {GameTime64}; |
| 2126 |
ai_do_cloak_stuff(); |
| 2127 |
|
| 2128 |
multi_strip_robots(pnum); |
| 2129 |
|
| 2130 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 2131 |
newdemo_record_multi_cloak(pnum); |
| 2132 |
} |
| 2133 |
|
| 2134 |
} |
| 2135 |
|
| 2136 |
} |
| 2137 |
|
| 2138 |
namespace dcx { |
| 2139 |
|
| 2140 |
namespace { |
| 2141 |
|
| 2142 |
static const char *deny_multi_save_game_duplicate_callsign(const std::ranges::subrange<const player *> range) |
| 2143 |
{ |
| 2144 |
const auto e = range.end(); |
| 2145 |
for (auto i = range.begin(); i != e; ++i) |
| 2146 |
for (auto j = std::next(i); j != e; ++j) |
| 2147 |
{ |
| 2148 |
if (i->callsign == j->callsign) |
| 2149 |
return "Multiple players with same callsign!"; |
| 2150 |
} |
| 2151 |
return nullptr; |
| 2152 |
} |
| 2153 |
|
| 2154 |
static void multi_do_decloak(const playernum_t pnum) |
| 2155 |
{ |
| 2156 |
if (Newdemo_state == ND_STATE_RECORDING) |
| 2157 |
newdemo_record_multi_decloak(pnum); |
| 2158 |
} |
| 2159 |
|
| 2160 |
} |
| 2161 |
|
| 2162 |
} |
| 2163 |
|
| 2164 |
namespace dsx { |
| 2165 |
|
| 2166 |
namespace { |
| 2167 |
|
| 2168 |
static void multi_do_door_open(fvmwallptr &vmwallptr, const multiplayer_rspan<multiplayer_command_t::MULTI_DOOR_OPEN> buf) |
| 2169 |
{ |
| 2170 |
const auto uside = build_sidenum_from_untrusted(buf[3]); |
| 2171 |
if (!uside) |
| 2172 |
return; |
| 2173 |
const auto side = *uside; |
| 2174 |
#if DXX_BUILD_DESCENT == 2 |
| 2175 |
ubyte flag= buf[4]; |
| 2176 |
#endif |
| 2177 |
|
| 2178 |
const auto &&useg = vmsegptridx.check_untrusted(segnum_t{GET_INTEL_SHORT(&buf[1])}); |
| 2179 |
if (!useg) |
| 2180 |
return; |
| 2181 |
const auto &&seg = *useg; |
| 2182 |
const auto wall_num = seg->shared_segment::sides[side].wall_num; |
| 2183 |
if (wall_num == wall_none) { //Opening door on illegal wall |
| 2184 |
Int3(); |
| 2185 |
return; |
| 2186 |
} |
| 2187 |
|
| 2188 |
auto &w = *vmwallptr(wall_num); |
| 2189 |
|
| 2190 |
if (w.type == WALL_BLASTABLE) |
| 2191 |
{ |
| 2192 |
if (!(w.flags & wall_flag::blasted)) |
| 2193 |
{ |
| 2194 |
wall_destroy(seg, side); |
| 2195 |
} |
| 2196 |
return; |
| 2197 |
} |
| 2198 |
else if (w.state != wall_state::opening) |
| 2199 |
{ |
| 2200 |
wall_open_door(seg, side); |
| 2201 |
} |
| 2202 |
#if DXX_BUILD_DESCENT == 2 |
| 2203 |
w.flags = wall_flags{flag}; |
| 2204 |
#endif |
| 2205 |
|
| 2206 |
} |
| 2207 |
|
| 2208 |
static void multi_do_create_explosion(fvmobjptridx &vmobjptridx, const playernum_t pnum) |
| 2209 |
{ |
| 2210 |
create_small_fireball_on_object(vmobjptridx(vcplayerptr(pnum)->objnum), F1_0, 1); |
| 2211 |
} |
| 2212 |
|
| 2213 |
static void multi_do_controlcen_fire(const multiplayer_rspan<multiplayer_command_t::MULTI_CONTROLCEN_FIRE> buf) |
| 2214 |
{ |
| 2215 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2216 |
auto &vmobjptridx = Objects.vmptridx; |
| 2217 |
int gun_num; |
| 2218 |
int count{1}; |
| 2219 |
|
| 2220 |
const auto to_target = multi_get_vector(buf.subspan<1, 12>()); |
| 2221 |
count += 12; |
| 2222 |
gun_num = buf[count]; count += 1; |
| 2223 |
const objnum_t objnum{GET_INTEL_SHORT(&buf[count])}; count += 2; |
| 2224 |
|
| 2225 |
const auto &&uobj = vmobjptridx.check_untrusted(objnum); |
| 2226 |
if (!uobj) |
| 2227 |
return; |
| 2228 |
const auto &&objp = *uobj; |
| 2229 |
Laser_create_new_easy(LevelSharedRobotInfoState.Robot_info, to_target, objp->ctype.reactor_info.gun_pos[gun_num], objp, weapon_id_type::CONTROLCEN_WEAPON_NUM, weapon_sound_flag::audible); |
| 2230 |
} |
| 2231 |
|
| 2232 |
static void multi_do_create_powerup(fvmsegptridx &vmsegptridx, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_CREATE_POWERUP> buf) |
| 2233 |
{ |
| 2234 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 2235 |
int count{1}; |
| 2236 |
if (Network_status == network_state::endlevel || LevelUniqueControlCenterState.Control_center_destroyed) |
| 2237 |
return; |
| 2238 |
|
| 2239 |
count++; |
| 2240 |
const uint8_t powerup_type{buf[count++]}; |
| 2241 |
if (powerup_type >= MAX_POWERUP_TYPES) |
| 2242 |
return; |
| 2243 |
/* Casting the untrusted network input to segnum_t is safe here, since it |
| 2244 |
* is immediately passed to `check_untrusted`, which validates that the |
| 2245 |
* index is reasonable. |
| 2246 |
*/ |
| 2247 |
const auto &&useg = vmsegptridx.check_untrusted(segnum_t{GET_INTEL_SHORT(&buf[count])}); |
| 2248 |
if (!useg) |
| 2249 |
return; |
| 2250 |
const auto &&segnum = *useg; |
| 2251 |
count += 2; |
| 2252 |
const objnum_t objnum{GET_INTEL_SHORT(&buf[count])}; count += 2; |
| 2253 |
const auto new_pos = multi_get_vector(buf.subspan<1 + 1 + 1 + 2 + 2, 12>()); |
| 2254 |
count+=sizeof(vms_vector); |
| 2255 |
const auto &&my_objnum{drop_powerup(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, Vclip, powerup_type_t{powerup_type}, vmd_zero_vector, new_pos, segnum, true)}; |
| 2256 |
if (my_objnum == object_none) |
| 2257 |
return; |
| 2258 |
|
| 2259 |
if (Network_send_objects && multi::dispatch->objnum_is_past(my_objnum)) |
| 2260 |
{ |
| 2261 |
Network_send_objnum = -1; |
| 2262 |
} |
| 2263 |
|
| 2264 |
map_objnum_local_to_remote(my_objnum, objnum, pnum); |
| 2265 |
|
| 2266 |
object_create_explosion_without_damage(Vclip, segnum, new_pos, i2f(5), vclip_index::powerup_disappearance); |
| 2267 |
} |
| 2268 |
|
| 2269 |
static void multi_do_play_sound(object_array &Objects, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_PLAY_SOUND> buf) |
| 2270 |
{ |
| 2271 |
auto &vcobjptridx = Objects.vcptridx; |
| 2272 |
const auto &plr = *vcplayerptr(pnum); |
| 2273 |
if (plr.connected == player_connection_status::disconnected) |
| 2274 |
return; |
| 2275 |
|
| 2276 |
const uint8_t sound_num{buf[2]}; |
| 2277 |
const uint8_t once = buf[3]; |
| 2278 |
const fix volume{GET_INTEL_INT<int32_t>(&buf[4])}; |
| 2279 |
|
| 2280 |
const auto objnum{plr.objnum}; |
| 2281 |
digi_link_sound_to_object(static_cast<sound_effect>(sound_num), vcobjptridx(objnum), 0, volume, static_cast<sound_stack>(once)); |
| 2282 |
} |
| 2283 |
|
| 2284 |
} |
| 2285 |
|
| 2286 |
} |
| 2287 |
|
| 2288 |
namespace { |
| 2289 |
|
| 2290 |
static void multi_do_score(fvmobjptr &vmobjptr, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_SCORE> buf) |
| 2291 |
{ |
| 2292 |
if (pnum >= N_players) |
| 2293 |
{ |
| 2294 |
Int3(); // Non-terminal, see rob |
| 2295 |
return; |
| 2296 |
} |
| 2297 |
|
| 2298 |
const auto score{GET_INTEL_INT<int32_t>(&buf[2])}; |
| 2299 |
if (Newdemo_state == ND_STATE_RECORDING) { |
| 2300 |
newdemo_record_multi_score(pnum, score); |
| 2301 |
} |
| 2302 |
auto &player_info = vmobjptr(vcplayerptr(pnum)->objnum)->ctype.player_info; |
| 2303 |
player_info.mission.score = score; |
| 2304 |
multi_sort_kill_list(); |
| 2305 |
} |
| 2306 |
|
| 2307 |
static void multi_do_trigger(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_TRIGGER> buf) |
| 2308 |
{ |
| 2309 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2310 |
auto &vmobjptr = Objects.vmptr; |
| 2311 |
const std::underlying_type<trgnum_t>::type trigger = buf[2]; |
| 2312 |
if (pnum >= N_players || pnum == Player_num) |
| 2313 |
{ |
| 2314 |
Int3(); // Got trigger from illegal playernum |
| 2315 |
return; |
| 2316 |
} |
| 2317 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 2318 |
if (trigger >= Triggers.get_count()) |
| 2319 |
{ |
| 2320 |
Int3(); // Illegal trigger number in multiplayer |
| 2321 |
return; |
| 2322 |
} |
| 2323 |
check_trigger_sub(get_local_plrobj(), static_cast<trgnum_t>(trigger), pnum, 0); |
| 2324 |
} |
| 2325 |
|
| 2326 |
} |
| 2327 |
|
| 2328 |
#if DXX_BUILD_DESCENT == 2 |
| 2329 |
namespace dsx { |
| 2330 |
|
| 2331 |
namespace { |
| 2332 |
|
| 2333 |
static void multi_do_effect_blowup(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_EFFECT_BLOWUP> buf) |
| 2334 |
{ |
| 2335 |
if (pnum >= N_players || pnum == Player_num) |
| 2336 |
return; |
| 2337 |
|
| 2338 |
multi::dispatch->do_protocol_frame(1, 0); // force packets to be sent, ensuring this packet will be attached to following MULTI_TRIGGER |
| 2339 |
|
| 2340 |
const auto &&useg = vmsegptridx.check_untrusted(segnum_t{GET_INTEL_SHORT(&buf[2])}); |
| 2341 |
if (!useg) |
| 2342 |
return; |
| 2343 |
const auto uside = build_sidenum_from_untrusted(buf[4]); |
| 2344 |
if (!uside) |
| 2345 |
return; |
| 2346 |
const auto side = *uside; |
| 2347 |
const auto hitpnt = multi_get_vector(buf.subspan<5, 12>()); |
| 2348 |
|
| 2349 |
//create a dummy object which will be the weapon that hits |
| 2350 |
//the monitor. the blowup code wants to know who the parent of the |
| 2351 |
//laser is, so create a laser whose parent is the player |
| 2352 |
laser_parent laser; |
| 2353 |
laser.parent_type = OBJ_PLAYER; |
| 2354 |
laser.parent_num = pnum; |
| 2355 |
|
| 2356 |
auto &LevelSharedDestructibleLightState = LevelSharedSegmentState.DestructibleLights; |
| 2357 |
check_effect_blowup(LevelSharedDestructibleLightState, Vclip, *useg, side, hitpnt, laser, 0, 1); |
| 2358 |
} |
| 2359 |
|
| 2360 |
static void multi_do_drop_marker(object_array &Objects, fvmsegptridx &vmsegptridx, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_MARKER> buf) |
| 2361 |
{ |
| 2362 |
if (pnum==Player_num) // my marker? don't set it down cuz it might screw up the orientation |
| 2363 |
return; |
| 2364 |
|
| 2365 |
const auto mesnum = buf[2]; |
| 2366 |
const auto game_mode{Game_mode}; |
| 2367 |
const auto max_numplayers = Netgame.max_numplayers; |
| 2368 |
if (mesnum >= MarkerState.get_markers_per_player(game_mode, max_numplayers)) |
| 2369 |
return; |
| 2370 |
|
| 2371 |
const auto position = multi_get_vector(buf.subspan<3, 12>()); |
| 2372 |
|
| 2373 |
const auto gmi = convert_player_marker_index_to_game_marker_index(game_mode, max_numplayers, pnum, player_marker_index{mesnum}); |
| 2374 |
auto &marker_message = MarkerState.message[gmi]; |
| 2375 |
marker_message = {}; |
| 2376 |
for (const auto i : xrange(marker_message.size())) |
| 2377 |
{ |
| 2378 |
const auto c = marker_message[i] = buf[15 + i]; |
| 2379 |
if (!c) |
| 2380 |
break; |
| 2381 |
} |
| 2382 |
|
| 2383 |
auto &mo = MarkerState.imobjidx[gmi]; |
| 2384 |
if (mo != object_none) |
| 2385 |
obj_delete(LevelUniqueObjectState, Segments, Objects.vmptridx(mo)); |
| 2386 |
|
| 2387 |
const auto &&plr_objp = Objects.vcptr(vcplayerptr(pnum)->objnum); |
| 2388 |
mo = drop_marker_object(position, vmsegptridx(plr_objp->segnum), plr_objp->orient, gmi); |
| 2389 |
} |
| 2390 |
|
| 2391 |
} |
| 2392 |
|
| 2393 |
} |
| 2394 |
#endif |
| 2395 |
|
| 2396 |
namespace { |
| 2397 |
|
| 2398 |
static void multi_do_hostage_door_status(fvmsegptridx &vmsegptridx, wall_array &Walls, const multiplayer_rspan<multiplayer_command_t::MULTI_HOSTAGE_DOOR> buf) |
| 2399 |
{ |
| 2400 |
// Update hit point status of a door |
| 2401 |
|
| 2402 |
int count{1}; |
| 2403 |
|
| 2404 |
const wallnum_t wallnum{GET_INTEL_SHORT(&buf[count])}; |
| 2405 |
count += 2; |
| 2406 |
const fix hps{GET_INTEL_INT<int32_t>(&buf[count])}; count += 4; |
| 2407 |
|
| 2408 |
auto &vmwallptr = Walls.vmptr; |
| 2409 |
auto &w = *vmwallptr(wallnum); |
| 2410 |
if (hps < 0 || w.type != WALL_BLASTABLE) |
| 2411 |
{ |
| 2412 |
Int3(); // Non-terminal, see Rob |
| 2413 |
return; |
| 2414 |
} |
| 2415 |
|
| 2416 |
if (hps < w.hps) |
| 2417 |
wall_damage(vmsegptridx(w.segnum), w.sidenum, w.hps - hps); |
| 2418 |
} |
| 2419 |
|
| 2420 |
} |
| 2421 |
|
| 2422 |
void multi_reset_stuff() |
| 2423 |
{ |
| 2424 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2425 |
auto &vmobjptr = Objects.vmptr; |
| 2426 |
// A generic, emergency function to solve problems that crop up |
| 2427 |
// when a player exits quick-out from the game because of a |
| 2428 |
// connection loss. Fixes several weird bugs! |
| 2429 |
|
| 2430 |
dead_player_end(); |
| 2431 |
get_local_plrobj().ctype.player_info.homing_object_dist = -1; // Turn off homing sound. |
| 2432 |
reset_rear_view(); |
| 2433 |
} |
| 2434 |
|
| 2435 |
namespace dsx { |
| 2436 |
|
| 2437 |
void multi_reset_player_object(object &objp) |
| 2438 |
{ |
| 2439 |
//Init physics for a non-console player |
| 2440 |
Assert((objp.type == OBJ_PLAYER) || (objp.type == OBJ_GHOST)); |
| 2441 |
|
| 2442 |
objp.mtype.phys_info.velocity = {}; |
| 2443 |
objp.mtype.phys_info.thrust = {}; |
| 2444 |
objp.mtype.phys_info.rotvel = {}; |
| 2445 |
objp.mtype.phys_info.rotthrust = {}; |
| 2446 |
objp.mtype.phys_info.turnroll = 0; |
| 2447 |
objp.mtype.phys_info.mass = Player_ship->mass; |
| 2448 |
objp.mtype.phys_info.drag = Player_ship->drag; |
| 2449 |
if (objp.type == OBJ_PLAYER) |
| 2450 |
objp.mtype.phys_info.flags = PF_TURNROLL | PF_WIGGLE | PF_USES_THRUST; |
| 2451 |
else |
| 2452 |
objp.mtype.phys_info.flags &= ~(PF_TURNROLL | PF_LEVELLING | PF_WIGGLE); |
| 2453 |
|
| 2454 |
//Init render info |
| 2455 |
|
| 2456 |
objp.render_type = render_type::RT_POLYOBJ; |
| 2457 |
objp.rtype.pobj_info.model_num = Player_ship->model_num; //what model is this? |
| 2458 |
objp.rtype.pobj_info.subobj_flags = 0; //zero the flags |
| 2459 |
objp.rtype.pobj_info.anim_angles = {}; |
| 2460 |
|
| 2461 |
// Clear misc |
| 2462 |
|
| 2463 |
objp.flags = 0; |
| 2464 |
|
| 2465 |
if (objp.type == OBJ_GHOST) |
| 2466 |
objp.render_type = render_type::RT_NONE; |
| 2467 |
//reset textures for this, if not player 0 |
| 2468 |
multi_reset_object_texture (objp); |
| 2469 |
} |
| 2470 |
|
| 2471 |
namespace { |
| 2472 |
|
| 2473 |
static void multi_reset_object_texture(object_base &objp) |
| 2474 |
{ |
| 2475 |
if (objp.type == OBJ_GHOST) |
| 2476 |
return; |
| 2477 |
|
| 2478 |
const auto player_id = get_player_id(objp); |
| 2479 |
const auto id = (Game_mode & GM_TEAM) |
| 2480 |
? static_cast<unsigned>(multi_get_team_from_player(Netgame, player_id)) |
| 2481 |
: player_id; |
| 2482 |
|
| 2483 |
auto &pobj_info = objp.rtype.pobj_info; |
| 2484 |
pobj_info.alt_textures = id; |
| 2485 |
if (id) |
| 2486 |
{ |
| 2487 |
auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models; |
| 2488 |
auto &model = Polygon_models[pobj_info.model_num]; |
| 2489 |
const unsigned n_textures = model.n_textures; |
| 2490 |
if (N_PLAYER_SHIP_TEXTURES < n_textures) |
| 2491 |
Error("Too many player ship textures!\n"); |
| 2492 |
|
| 2493 |
const unsigned first_texture = model.first_texture; |
| 2494 |
for (unsigned i = 0; i < n_textures; ++i) |
| 2495 |
multi_player_textures[id - 1][i] = ObjBitmaps[ObjBitmapPtrs[first_texture + i]]; |
| 2496 |
|
| 2497 |
multi_player_textures[id-1][4] = ObjBitmaps[ObjBitmapPtrs[First_multi_bitmap_num+(id-1)*2]]; |
| 2498 |
multi_player_textures[id-1][5] = ObjBitmaps[ObjBitmapPtrs[First_multi_bitmap_num+(id-1)*2+1]]; |
| 2499 |
} |
| 2500 |
} |
| 2501 |
|
| 2502 |
static std::optional<multiplayer_command_t> build_multiplayer_command_from_untrusted(const uint8_t type) |
| 2503 |
{ |
| 2504 |
switch (type) |
| 2505 |
{ |
| 2506 |
#define multiplayer_case(NAME, LENGTH) \ |
| 2507 |
case static_cast<uint8_t>(multiplayer_command_t::NAME): |
| 2508 |
for_each_multiplayer_command(multiplayer_case); |
| 2509 |
return static_cast<multiplayer_command_t>(type); |
| 2510 |
#undef multiplayer_case |
| 2511 |
default: |
| 2512 |
return std::nullopt; |
| 2513 |
} |
| 2514 |
} |
| 2515 |
|
| 2516 |
} |
| 2517 |
|
| 2518 |
void multi_process_bigdata(const d_level_shared_robot_info_state &LevelSharedRobotInfoState, const playernum_t pnum, const std::span<const uint8_t> buf) |
| 2519 |
{ |
| 2520 |
// Takes a bunch of messages, check them for validity, |
| 2521 |
// and pass them to multi_process_data. |
| 2522 |
|
| 2523 |
uint_fast32_t bytes_processed{0}; |
| 2524 |
|
| 2525 |
while (bytes_processed < buf.size()) |
| 2526 |
{ |
| 2527 |
const uint_fast32_t type = buf[bytes_processed]; |
| 2528 |
|
| 2529 |
if (type >= std::size(message_length)) |
| 2530 |
{ |
| 2531 |
con_printf(CON_DEBUG, "multi_process_bigdata: Invalid packet type %" PRIuFAST32 "!", type); |
| 2532 |
return; |
| 2533 |
} |
| 2534 |
const auto mtype = build_multiplayer_command_from_untrusted(type); |
| 2535 |
if (!mtype) |
| 2536 |
return; |
| 2537 |
const uint_fast32_t sub_len = message_length[type]; |
| 2538 |
|
| 2539 |
Assert(sub_len > 0); |
| 2540 |
|
| 2541 |
if (bytes_processed + sub_len > buf.size()) |
| 2542 |
{ |
| 2543 |
con_printf(CON_DEBUG, "multi_process_bigdata: packet type %" PRIuFAST32 " too short (%" PRIuFAST32 " > %" DXX_PRI_size_type ")!", type, bytes_processed + sub_len, buf.size()); |
| 2544 |
Int3(); |
| 2545 |
return; |
| 2546 |
} |
| 2547 |
|
| 2548 |
multi_process_data(LevelSharedRobotInfoState, pnum, buf.subspan(bytes_processed, sub_len), *mtype); |
| 2549 |
bytes_processed += sub_len; |
| 2550 |
} |
| 2551 |
} |
| 2552 |
|
| 2553 |
// |
| 2554 |
// Part 2 : Functions that send communication messages to inform the other |
| 2555 |
// players of something we did. |
| 2556 |
// |
| 2557 |
|
| 2558 |
void multi_send_fire(const vms_matrix &orient, int laser_gun, const laser_level level, int laser_flags, objnum_t laser_track, const imobjptridx_t is_bomb_objnum) |
| 2559 |
{ |
| 2560 |
static fix64 last_fireup_time = 0; |
| 2561 |
|
| 2562 |
// provoke positional update if possible (20 times per second max. matches vulcan, the fastest firing weapon) |
| 2563 |
if (timer_query() >= (last_fireup_time+(F1_0/20))) |
| 2564 |
{ |
| 2565 |
multi::dispatch->do_protocol_frame(1, 0); |
| 2566 |
last_fireup_time = timer_query(); |
| 2567 |
} |
| 2568 |
|
| 2569 |
union mb { |
| 2570 |
multi_command<multiplayer_command_t::MULTI_FIRE_BOMB> multibomb; |
| 2571 |
multi_command<multiplayer_command_t::MULTI_FIRE_TRACK> multitrack; |
| 2572 |
multi_command<multiplayer_command_t::MULTI_FIRE> multifire; |
| 2573 |
mb() {} |
| 2574 |
} multibuf; |
| 2575 |
if (is_bomb_objnum != object_none) |
| 2576 |
new(&multibuf.multibomb) multi_command<multiplayer_command_t::MULTI_FIRE_BOMB>(); |
| 2577 |
else if (laser_track != object_none) |
| 2578 |
new(&multibuf.multitrack) multi_command<multiplayer_command_t::MULTI_FIRE_TRACK>(); |
| 2579 |
else |
| 2580 |
new(&multibuf.multifire) multi_command<multiplayer_command_t::MULTI_FIRE>(); |
| 2581 |
multibuf.multifire[1] = static_cast<char>(Player_num); |
| 2582 |
multibuf.multifire[2] = static_cast<char>(laser_gun); |
| 2583 |
multibuf.multifire[3] = static_cast<uint8_t>(level); |
| 2584 |
multibuf.multifire[4] = static_cast<char>(laser_flags); |
| 2585 |
|
| 2586 |
multi_put_vector(&multibuf.multifire[5], orient.fvec); |
| 2587 |
|
| 2588 |
/* |
| 2589 |
* If we fire a bomb, it's persistent. Let others know of it's objnum so host can track it's behaviour over clients (host-authority functions, D2 chaff ability). |
| 2590 |
* If we fire a tracking projectile, we should others let know about what we track but we have to pay attention that it is mapped correctly. |
| 2591 |
* If we fire something else, we make the packet as small as possible. |
| 2592 |
*/ |
| 2593 |
if (is_bomb_objnum != object_none) |
| 2594 |
{ |
| 2595 |
map_objnum_local_to_local(is_bomb_objnum); |
| 2596 |
PUT_INTEL_SHORT(&multibuf.multibomb[17], is_bomb_objnum.operator objnum_t()); |
| 2597 |
multi_send_data(multibuf.multibomb, multiplayer_data_priority::_1); |
| 2598 |
} |
| 2599 |
else if (laser_track != object_none) |
| 2600 |
{ |
| 2601 |
const auto &&[remote_owner, remote_laser_track] = objnum_local_to_remote(laser_track); |
| 2602 |
PUT_INTEL_SHORT(&multibuf.multitrack[17], remote_laser_track); |
| 2603 |
multibuf.multitrack[19] = remote_owner; |
| 2604 |
multi_send_data(multibuf.multitrack, multiplayer_data_priority::_1); |
| 2605 |
} |
| 2606 |
else |
| 2607 |
multi_send_data(multibuf.multifire, multiplayer_data_priority::_1); |
| 2608 |
} |
| 2609 |
|
| 2610 |
void multi_send_destroy_controlcen(const objnum_t objnum, const playernum_t player) |
| 2611 |
{ |
| 2612 |
if (player == Player_num) |
| 2613 |
{ |
| 2614 |
const auto &&m = TXT_YOU_DEST_CONTROL; |
| 2615 |
HUD_init_message_literal(HM_MULTI, {m, strlen(m)}); |
| 2616 |
} |
| 2617 |
else if ((player > 0) && (player < N_players)) |
| 2618 |
HUD_init_message(HM_MULTI, "%s %s", static_cast<const char *>(vcplayerptr(player)->callsign), TXT_HAS_DEST_CONTROL); |
| 2619 |
else |
| 2620 |
{ |
| 2621 |
const auto &&m = TXT_CONTROL_DESTROYED; |
| 2622 |
HUD_init_message_literal(HM_MULTI, {m, strlen(m)}); |
| 2623 |
} |
| 2624 |
|
| 2625 |
multi_command<multiplayer_command_t::MULTI_CONTROLCEN> multibuf; |
| 2626 |
PUT_INTEL_SHORT(&multibuf[1], objnum); |
| 2627 |
multibuf[3] = player; |
| 2628 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2629 |
} |
| 2630 |
|
| 2631 |
#if DXX_BUILD_DESCENT == 2 |
| 2632 |
void multi_send_drop_marker(const unsigned player, const vms_vector &position, const player_marker_index messagenum, const marker_message_text_t &text) |
| 2633 |
{ |
| 2634 |
multi_command<multiplayer_command_t::MULTI_MARKER> multibuf; |
| 2635 |
multibuf[1]=static_cast<char>(player); |
| 2636 |
multibuf[2] = static_cast<uint8_t>(messagenum); |
| 2637 |
multi_put_vector(&multibuf[3], position); |
| 2638 |
std::copy(text.begin(), text.end(), std::next(multibuf.begin(), 15)); |
| 2639 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2640 |
} |
| 2641 |
|
| 2642 |
void multi_send_markers() |
| 2643 |
{ |
| 2644 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2645 |
auto &vcobjptr = Objects.vcptr; |
| 2646 |
// send marker positions/text to new player |
| 2647 |
|
| 2648 |
const auto game_mode{Game_mode}; |
| 2649 |
const auto max_numplayers = Netgame.max_numplayers; |
| 2650 |
auto &&player_marker_range = get_player_marker_range(MarkerState.get_markers_per_player(game_mode, max_numplayers)); |
| 2651 |
for (const playernum_t pnum : xrange(max_numplayers)) |
| 2652 |
{ |
| 2653 |
for (const auto pmi : player_marker_range) |
| 2654 |
{ |
| 2655 |
const auto gmi = convert_player_marker_index_to_game_marker_index(game_mode, max_numplayers, pnum, pmi); |
| 2656 |
const auto mo = MarkerState.imobjidx[gmi]; |
| 2657 |
if (mo != object_none) |
| 2658 |
multi_send_drop_marker(pnum, vcobjptr(mo)->pos, pmi, MarkerState.message[gmi]); |
| 2659 |
} |
| 2660 |
} |
| 2661 |
} |
| 2662 |
#endif |
| 2663 |
|
| 2664 |
#if DXX_BUILD_DESCENT == 1 |
| 2665 |
void multi_send_endlevel_start(const multi_endlevel_type secret) |
| 2666 |
#elif DXX_BUILD_DESCENT == 2 |
| 2667 |
void multi_send_endlevel_start() |
| 2668 |
#endif |
| 2669 |
{ |
| 2670 |
multi_command<multiplayer_command_t::MULTI_ENDLEVEL_START> buf; |
| 2671 |
/* Obsolete - reclaim player number field on next multiplayer protocol version bump */ |
| 2672 |
buf[1] = Player_num; |
| 2673 |
#if DXX_BUILD_DESCENT == 1 |
| 2674 |
buf[2] = static_cast<uint8_t>(secret); |
| 2675 |
#endif |
| 2676 |
|
| 2677 |
multi_send_data(buf, multiplayer_data_priority::_2); |
| 2678 |
if (Game_mode & GM_NETWORK) |
| 2679 |
{ |
| 2680 |
get_local_player().connected = player_connection_status::escape_tunnel; |
| 2681 |
multi::dispatch->send_endlevel_packet(); |
| 2682 |
} |
| 2683 |
} |
| 2684 |
|
| 2685 |
void multi_send_player_deres(deres_type_t type) |
| 2686 |
{ |
| 2687 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2688 |
auto &vmobjptr = Objects.vmptr; |
| 2689 |
auto &vmobjptridx = Objects.vmptridx; |
| 2690 |
int count{0}; |
| 2691 |
if (Network_send_objects) |
| 2692 |
{ |
| 2693 |
Network_send_objnum = -1; |
| 2694 |
} |
| 2695 |
|
| 2696 |
multi_send_position(vmobjptridx(get_local_player().objnum)); |
| 2697 |
|
| 2698 |
multi_command<multiplayer_command_t::MULTI_PLAYER_DERES> multibuf; |
| 2699 |
count++; |
| 2700 |
multibuf[count++] = Player_num; |
| 2701 |
multibuf[count++] = type; |
| 2702 |
|
| 2703 |
#if DXX_BUILD_DESCENT == 1 |
| 2704 |
#define PUT_WEAPON_FLAGS(buf,count,value) (buf[count] = value, ++count) |
| 2705 |
#elif DXX_BUILD_DESCENT == 2 |
| 2706 |
#define PUT_WEAPON_FLAGS(buf,count,value) ((PUT_INTEL_SHORT(&buf[count], value)), count+=sizeof(uint16_t)) |
| 2707 |
#endif |
| 2708 |
auto &player_info = get_local_plrobj().ctype.player_info; |
| 2709 |
PUT_WEAPON_FLAGS(multibuf, count, player_info.primary_weapon_flags); |
| 2710 |
multibuf[count++] = static_cast<char>(player_info.laser_level); |
| 2711 |
multibuf[count++] = game_mode_hoard(Game_mode) ? static_cast<char>(player_info.hoard.orbs) : 0; |
| 2712 |
|
| 2713 |
auto &secondary_ammo = player_info.secondary_ammo; |
| 2714 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::HOMING_INDEX]; |
| 2715 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::CONCUSSION_INDEX]; |
| 2716 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMART_INDEX]; |
| 2717 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::MEGA_INDEX]; |
| 2718 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::PROXIMITY_INDEX]; |
| 2719 |
|
| 2720 |
#if DXX_BUILD_DESCENT == 2 |
| 2721 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMISSILE1_INDEX]; |
| 2722 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::GUIDED_INDEX]; |
| 2723 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMART_MINE_INDEX]; |
| 2724 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMISSILE4_INDEX]; |
| 2725 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMISSILE5_INDEX]; |
| 2726 |
#endif |
| 2727 |
|
| 2728 |
PUT_INTEL_SHORT(&multibuf[count], player_info.vulcan_ammo); |
| 2729 |
count += 2; |
| 2730 |
PUT_INTEL_INT(&multibuf[count], player_info.powerup_flags.get_player_flags()); |
| 2731 |
count += 4; |
| 2732 |
|
| 2733 |
multibuf[count++] = Net_create_loc; |
| 2734 |
|
| 2735 |
Assert(Net_create_loc <= MAX_NET_CREATE_OBJECTS); |
| 2736 |
|
| 2737 |
memset(&multibuf[count], -1, MAX_NET_CREATE_OBJECTS*sizeof(short)); |
| 2738 |
|
| 2739 |
range_for (const auto i, partial_const_range(Net_create_objnums, Net_create_loc)) |
| 2740 |
{ |
| 2741 |
if (i <= 0) { |
| 2742 |
Int3(); // Illegal value in created egg object numbers |
| 2743 |
count +=2; |
| 2744 |
continue; |
| 2745 |
} |
| 2746 |
|
| 2747 |
PUT_INTEL_SHORT(&multibuf[count], i); count += 2; |
| 2748 |
|
| 2749 |
// We created these objs so our local number = the network number |
| 2750 |
map_objnum_local_to_local(i); |
| 2751 |
} |
| 2752 |
|
| 2753 |
Net_create_loc = 0; |
| 2754 |
|
| 2755 |
if (count > command_length<multiplayer_command_t::MULTI_PLAYER_DERES>) |
| 2756 |
{ |
| 2757 |
Int3(); // See Rob |
| 2758 |
} |
| 2759 |
|
| 2760 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2761 |
if (player_info.powerup_flags & PLAYER_FLAGS_CLOAKED) |
| 2762 |
multi_send_decloak(); |
| 2763 |
multi_strip_robots(Player_num); |
| 2764 |
} |
| 2765 |
|
| 2766 |
} |
| 2767 |
|
| 2768 |
namespace { |
| 2769 |
|
| 2770 |
void multi_send_message() |
| 2771 |
{ |
| 2772 |
if (Network_message_reciever != -1) |
| 2773 |
{ |
| 2774 |
multi_command<multiplayer_command_t::MULTI_MESSAGE> multibuf; |
| 2775 |
/* Obsolete - reclaim player number field on next multiplayer protocol version bump */ |
| 2776 |
multibuf[1] = Player_num; |
| 2777 |
std::copy(Network_message.begin(), Network_message.end(), std::next(multibuf.begin(), 2)); |
| 2778 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 2779 |
Network_message_reciever = -1; |
| 2780 |
} |
| 2781 |
} |
| 2782 |
|
| 2783 |
} |
| 2784 |
|
| 2785 |
void multi_send_reappear() |
| 2786 |
{ |
| 2787 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2788 |
auto &vmobjptridx = Objects.vmptridx; |
| 2789 |
auto &plr = get_local_player(); |
| 2790 |
multi_send_position(vmobjptridx(plr.objnum)); |
| 2791 |
multi_command<multiplayer_command_t::MULTI_REAPPEAR> multibuf; |
| 2792 |
multibuf[1] = static_cast<char>(Player_num); |
| 2793 |
PUT_INTEL_SHORT(&multibuf[2], plr.objnum); |
| 2794 |
|
| 2795 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2796 |
} |
| 2797 |
|
| 2798 |
namespace dsx { |
| 2799 |
|
| 2800 |
void multi_send_position(object &obj) |
| 2801 |
{ |
| 2802 |
int count{1}; |
| 2803 |
|
| 2804 |
const auto qpp{build_quaternionpos(obj)}; |
| 2805 |
multi_command<multiplayer_command_t::MULTI_POSITION> multibuf; |
| 2806 |
PUT_INTEL_SHORT(&multibuf[count], qpp.orient.w); count += 2; |
| 2807 |
PUT_INTEL_SHORT(&multibuf[count], qpp.orient.x); count += 2; |
| 2808 |
PUT_INTEL_SHORT(&multibuf[count], qpp.orient.y); count += 2; |
| 2809 |
PUT_INTEL_SHORT(&multibuf[count], qpp.orient.z); count += 2; |
| 2810 |
multi_put_vector(&multibuf[count], qpp.pos); |
| 2811 |
count += 12; |
| 2812 |
PUT_INTEL_SEGNUM(&multibuf[count], qpp.segment); count += 2; |
| 2813 |
multi_put_vector(&multibuf[count], qpp.vel); |
| 2814 |
count += 12; |
| 2815 |
multi_put_vector(&multibuf[count], qpp.rotvel); |
| 2816 |
count += 12; |
| 2817 |
// 46 |
| 2818 |
|
| 2819 |
// send twice while first has priority so the next one will be attached to the next bigdata packet |
| 2820 |
multi_send_data(multibuf, multiplayer_data_priority::_1); |
| 2821 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 2822 |
} |
| 2823 |
|
| 2824 |
/* |
| 2825 |
* I was killed. If I am host, send this info to everyone and compute kill. If I am just a Client I'll only send the kill but not compute it for me. I (Client) will wait for Host to send me my kill back together with updated game_mode related variables which are important for me to compute consistent kill. |
| 2826 |
*/ |
| 2827 |
void multi_send_kill(const vmobjptridx_t objnum) |
| 2828 |
{ |
| 2829 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 2830 |
auto &imobjptridx = Objects.imptridx; |
| 2831 |
auto &vmobjptr = Objects.vmptr; |
| 2832 |
// I died, tell the world. |
| 2833 |
Assert(get_player_id(objnum) == Player_num); |
| 2834 |
const auto killer_objnum = get_local_plrobj().ctype.player_info.killer_objnum; |
| 2835 |
|
| 2836 |
// do it with variable since INTEL_SHORT won't work on return val from function. |
| 2837 |
const auto &&[remote_owner, remote_objnum] = killer_objnum != object_none |
| 2838 |
? objnum_local_to_remote(killer_objnum) |
| 2839 |
: owned_remote_objnum{static_cast<int8_t>(-1), static_cast<uint16_t>(0xffff)}; |
| 2840 |
const auto local_is_host = multi_i_am_master(); |
| 2841 |
union mb { |
| 2842 |
multi_command<multiplayer_command_t::MULTI_KILL_CLIENT> c; |
| 2843 |
multi_command<multiplayer_command_t::MULTI_KILL_HOST> h; |
| 2844 |
mb() {} |
| 2845 |
}; |
| 2846 |
mb multibuf; |
| 2847 |
if (local_is_host) |
| 2848 |
{ |
| 2849 |
new(&multibuf.h) multi_command<multiplayer_command_t::MULTI_KILL_HOST>(); |
| 2850 |
multibuf.h[5] = Netgame.team_vector; |
| 2851 |
multibuf.h[6] = Bounty_target; |
| 2852 |
} |
| 2853 |
else |
| 2854 |
{ |
| 2855 |
new(&multibuf.c) multi_command<multiplayer_command_t::MULTI_KILL_CLIENT>(); |
| 2856 |
} |
| 2857 |
/* Obsolete - reclaim player number field on next multiplayer protocol version bump */ |
| 2858 |
multibuf.h[1] = Player_num; |
| 2859 |
multibuf.h[4] = remote_owner; |
| 2860 |
PUT_INTEL_SHORT(&multibuf.h[2], remote_objnum); |
| 2861 |
// I am host - I know what's going on so attach game_mode related info which might be vital for correct kill computation |
| 2862 |
if (local_is_host) |
| 2863 |
{ |
| 2864 |
multi_compute_kill(LevelSharedRobotInfoState.Robot_info, imobjptridx(killer_objnum), objnum); |
| 2865 |
multi_send_data(multibuf.h, multiplayer_data_priority::_2); |
| 2866 |
} |
| 2867 |
else |
| 2868 |
multi_send_data_direct(multibuf.c, multi_who_is_master(), 2); // I am just a client so I'll only send my kill but not compute it, yet. I'll get response from host so I can compute it correctly |
| 2869 |
|
| 2870 |
multi_strip_robots(Player_num); |
| 2871 |
|
| 2872 |
if (Game_mode & GM_BOUNTY && multi_i_am_master()) // update in case if needed... we could attach this to this packet but... meh... |
| 2873 |
multi_send_bounty(); |
| 2874 |
} |
| 2875 |
|
| 2876 |
void multi_send_remobj(const vmobjidx_t objnum) |
| 2877 |
{ |
| 2878 |
// Tell the other guy to remove an object from his list |
| 2879 |
const auto &&[obj_owner, remote_objnum] = objnum_local_to_remote(objnum); |
| 2880 |
multi_command<multiplayer_command_t::MULTI_REMOVE_OBJECT> multibuf; |
| 2881 |
PUT_INTEL_SHORT(&multibuf[1], remote_objnum); // Map to network objnums |
| 2882 |
|
| 2883 |
multibuf[3] = obj_owner; |
| 2884 |
|
| 2885 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2886 |
|
| 2887 |
if (Network_send_objects && multi::dispatch->objnum_is_past(objnum)) |
| 2888 |
{ |
| 2889 |
Network_send_objnum = -1; |
| 2890 |
} |
| 2891 |
} |
| 2892 |
|
| 2893 |
} |
| 2894 |
|
| 2895 |
namespace dcx { |
| 2896 |
|
| 2897 |
namespace { |
| 2898 |
|
| 2899 |
void multi_send_quit() |
| 2900 |
{ |
| 2901 |
// I am quitting the game, tell the other guy the bad news. |
| 2902 |
|
| 2903 |
multi_command<multiplayer_command_t::MULTI_QUIT> multibuf; |
| 2904 |
/* Obsolete - reclaim player number field on next multiplayer protocol version bump */ |
| 2905 |
multibuf[1] = Player_num; |
| 2906 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2907 |
} |
| 2908 |
|
| 2909 |
} |
| 2910 |
|
| 2911 |
void multi_send_cloak() |
| 2912 |
{ |
| 2913 |
// Broadcast a change in our pflags (made to support cloaking) |
| 2914 |
|
| 2915 |
multi_command<multiplayer_command_t::MULTI_CLOAK> multibuf; |
| 2916 |
const auto pnum{Player_num}; |
| 2917 |
multibuf[1] = pnum; |
| 2918 |
|
| 2919 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2920 |
|
| 2921 |
multi_strip_robots(pnum); |
| 2922 |
} |
| 2923 |
|
| 2924 |
void multi_send_decloak() |
| 2925 |
{ |
| 2926 |
// Broadcast a change in our pflags (made to support cloaking) |
| 2927 |
|
| 2928 |
multi_command<multiplayer_command_t::MULTI_DECLOAK> multibuf; |
| 2929 |
multibuf[1] = Player_num; |
| 2930 |
|
| 2931 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2932 |
} |
| 2933 |
|
| 2934 |
} |
| 2935 |
|
| 2936 |
namespace dsx { |
| 2937 |
|
| 2938 |
void multi_send_door_open(const vcsegidx_t segnum, const sidenum_t side, const wall_flags flag) |
| 2939 |
{ |
| 2940 |
multi_command<multiplayer_command_t::MULTI_DOOR_OPEN> multibuf; |
| 2941 |
// When we open a door make sure everyone else opens that door |
| 2942 |
PUT_INTEL_SEGNUM(&multibuf[1], segnum); |
| 2943 |
multibuf[3] = underlying_value(side); |
| 2944 |
#if DXX_BUILD_DESCENT == 1 |
| 2945 |
(void)flag; |
| 2946 |
#elif DXX_BUILD_DESCENT == 2 |
| 2947 |
multibuf[4] = underlying_value(flag); |
| 2948 |
#endif |
| 2949 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 2950 |
} |
| 2951 |
|
| 2952 |
#if DXX_BUILD_DESCENT == 2 |
| 2953 |
void multi_send_door_open_specific(const playernum_t pnum, const vcsegidx_t segnum, const sidenum_t side, const wall_flags flag) |
| 2954 |
{ |
| 2955 |
// For sending doors only to a specific person (usually when they're joining) |
| 2956 |
|
| 2957 |
Assert (Game_mode & GM_NETWORK); |
| 2958 |
// Assert (pnum>-1 && pnum<N_players); |
| 2959 |
|
| 2960 |
multi_command<multiplayer_command_t::MULTI_DOOR_OPEN> multibuf; |
| 2961 |
PUT_INTEL_SEGNUM(&multibuf[1], segnum); |
| 2962 |
multibuf[3] = static_cast<int8_t>(side); |
| 2963 |
multibuf[4] = underlying_value(flag); |
| 2964 |
|
| 2965 |
multi_send_data_direct(multibuf, pnum, 2); |
| 2966 |
} |
| 2967 |
#endif |
| 2968 |
|
| 2969 |
} |
| 2970 |
|
| 2971 |
// |
| 2972 |
// Part 3 : Functions that change or prepare the game for multiplayer use. |
| 2973 |
// Not including functions needed to syncronize or start the |
| 2974 |
// particular type of multiplayer game. Includes preparing the |
| 2975 |
// mines, player structures, etc. |
| 2976 |
|
| 2977 |
void multi_send_create_explosion(const playernum_t pnum) |
| 2978 |
{ |
| 2979 |
// Send all data needed to create a remote explosion |
| 2980 |
|
| 2981 |
int count{0}; |
| 2982 |
|
| 2983 |
count += 1; |
| 2984 |
multi_command<multiplayer_command_t::MULTI_CREATE_EXPLOSION> multibuf; |
| 2985 |
multibuf[count] = static_cast<int8_t>(pnum); count += 1; |
| 2986 |
// ----------- |
| 2987 |
// Total size = 2 |
| 2988 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 2989 |
} |
| 2990 |
|
| 2991 |
void multi_send_controlcen_fire(const vms_vector &to_goal, int best_gun_num, objnum_t objnum) |
| 2992 |
{ |
| 2993 |
int count{0}; |
| 2994 |
|
| 2995 |
count += 1; |
| 2996 |
multi_command<multiplayer_command_t::MULTI_CONTROLCEN_FIRE> multibuf; |
| 2997 |
multi_put_vector(&multibuf[count], to_goal); |
| 2998 |
count += 12; |
| 2999 |
multibuf[count] = static_cast<char>(best_gun_num); count += 1; |
| 3000 |
PUT_INTEL_SHORT(&multibuf[count], objnum ); count += 2; |
| 3001 |
// ------------ |
| 3002 |
// Total = 16 |
| 3003 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 3004 |
} |
| 3005 |
|
| 3006 |
namespace dsx { |
| 3007 |
|
| 3008 |
void multi_send_create_powerup(const powerup_type_t powerup_type, const vcsegidx_t segnum, const vcobjidx_t objnum, const vms_vector &pos) |
| 3009 |
{ |
| 3010 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3011 |
auto &vmobjptridx = Objects.vmptridx; |
| 3012 |
// Create a powerup on a remote machine, used for remote |
| 3013 |
// placement of used powerups like missiles and cloaking |
| 3014 |
// powerups. |
| 3015 |
|
| 3016 |
int count{0}; |
| 3017 |
|
| 3018 |
multi_send_position(vmobjptridx(get_local_player().objnum)); |
| 3019 |
|
| 3020 |
count += 1; |
| 3021 |
multi_command<multiplayer_command_t::MULTI_CREATE_POWERUP> multibuf; |
| 3022 |
multibuf[count] = Player_num; count += 1; |
| 3023 |
multibuf[count] = underlying_value(powerup_type); count += 1; |
| 3024 |
PUT_INTEL_SEGNUM(&multibuf[count], segnum); count += 2; |
| 3025 |
PUT_INTEL_SHORT(&multibuf[count], objnum ); count += 2; |
| 3026 |
multi_put_vector(&multibuf[count], pos); |
| 3027 |
count += 12; |
| 3028 |
// ----------- |
| 3029 |
// Total = 19 |
| 3030 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 3031 |
|
| 3032 |
if (Network_send_objects && multi::dispatch->objnum_is_past(objnum)) |
| 3033 |
{ |
| 3034 |
Network_send_objnum = -1; |
| 3035 |
} |
| 3036 |
|
| 3037 |
map_objnum_local_to_local(objnum); |
| 3038 |
} |
| 3039 |
|
| 3040 |
} |
| 3041 |
|
| 3042 |
namespace { |
| 3043 |
|
| 3044 |
static void multi_digi_play_sample(const sound_effect soundnum, const fix max_volume, const sound_stack once) |
| 3045 |
{ |
| 3046 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3047 |
auto &vcobjptridx = Objects.vcptridx; |
| 3048 |
if (Game_mode & GM_MULTI) |
| 3049 |
multi_send_play_sound(soundnum, max_volume, once); |
| 3050 |
digi_link_sound_to_object(soundnum, vcobjptridx(Viewer), 0, max_volume, once); |
| 3051 |
} |
| 3052 |
|
| 3053 |
} |
| 3054 |
|
| 3055 |
void multi_digi_play_sample_once(const sound_effect soundnum, const fix max_volume) |
| 3056 |
{ |
| 3057 |
multi_digi_play_sample(soundnum, max_volume, sound_stack::cancel_previous); |
| 3058 |
} |
| 3059 |
|
| 3060 |
void multi_digi_play_sample(const sound_effect soundnum, const fix max_volume) |
| 3061 |
{ |
| 3062 |
multi_digi_play_sample(soundnum, max_volume, sound_stack::allow_stacking); |
| 3063 |
} |
| 3064 |
|
| 3065 |
namespace dsx { |
| 3066 |
|
| 3067 |
void multi_digi_link_sound_to_pos(const sound_effect soundnum, const vcsegptridx_t segnum, const sidenum_t sidenum, const vms_vector &pos, const int forever, const fix max_volume) |
| 3068 |
{ |
| 3069 |
if (Game_mode & GM_MULTI) |
| 3070 |
multi_send_play_sound(soundnum, max_volume, sound_stack::allow_stacking); |
| 3071 |
digi_link_sound_to_pos(soundnum, segnum, sidenum, pos, forever, max_volume); |
| 3072 |
} |
| 3073 |
|
| 3074 |
} |
| 3075 |
|
| 3076 |
void multi_send_play_sound(const sound_effect sound_num, const fix volume, const sound_stack once) |
| 3077 |
{ |
| 3078 |
int count{0}; |
| 3079 |
count += 1; |
| 3080 |
multi_command<multiplayer_command_t::MULTI_PLAY_SOUND> multibuf; |
| 3081 |
multibuf[count] = Player_num; count += 1; |
| 3082 |
multibuf[count] = static_cast<char>(sound_num); count += 1; |
| 3083 |
multibuf[count] = static_cast<uint8_t>(once); count += 1; |
| 3084 |
PUT_INTEL_INT(&multibuf[count], volume); count += 4; |
| 3085 |
// ----------- |
| 3086 |
// Total = 4 |
| 3087 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 3088 |
} |
| 3089 |
|
| 3090 |
void multi_send_score() |
| 3091 |
{ |
| 3092 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3093 |
auto &vmobjptr = Objects.vmptr; |
| 3094 |
// Send my current score to all other players so it will remain |
| 3095 |
// synced. |
| 3096 |
int count{0}; |
| 3097 |
|
| 3098 |
if (Game_mode & GM_MULTI_COOP) { |
| 3099 |
multi_sort_kill_list(); |
| 3100 |
count += 1; |
| 3101 |
multi_command<multiplayer_command_t::MULTI_SCORE> multibuf; |
| 3102 |
multibuf[count] = Player_num; count += 1; |
| 3103 |
auto &player_info = get_local_plrobj().ctype.player_info; |
| 3104 |
PUT_INTEL_INT(&multibuf[count], player_info.mission.score); count += 4; |
| 3105 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 3106 |
} |
| 3107 |
} |
| 3108 |
|
| 3109 |
void multi_send_trigger(const trgnum_t triggernum) |
| 3110 |
{ |
| 3111 |
// Send an event to trigger something in the mine |
| 3112 |
|
| 3113 |
int count{0}; |
| 3114 |
|
| 3115 |
count += 1; |
| 3116 |
multi_command<multiplayer_command_t::MULTI_TRIGGER> multibuf; |
| 3117 |
/* Obsolete - reclaim player number field on next multiplayer protocol version bump */ |
| 3118 |
multibuf[count] = Player_num; count += 1; |
| 3119 |
static_assert(sizeof(trgnum_t) == sizeof(uint8_t), "trigger number could be truncated"); |
| 3120 |
multibuf[count] = static_cast<uint8_t>(triggernum); count += 1; |
| 3121 |
|
| 3122 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 3123 |
} |
| 3124 |
|
| 3125 |
namespace dsx { |
| 3126 |
|
| 3127 |
#if DXX_BUILD_DESCENT == 2 |
| 3128 |
void multi_send_effect_blowup(const vcsegidx_t segnum, const sidenum_t side, const vms_vector &pnt) |
| 3129 |
{ |
| 3130 |
// We blew up something connected to a trigger. Send this blowup result to other players shortly before MULTI_TRIGGER. |
| 3131 |
// NOTE: The reason this is now a separate packet is to make sure trigger-connected switches/monitors are in sync with MULTI_TRIGGER. |
| 3132 |
// If a fire packet is late it might blow up a switch for some clients without the shooter actually registering this hit, |
| 3133 |
// not sending MULTI_TRIGGER and making puzzles or progress impossible. |
| 3134 |
int count{0}; |
| 3135 |
|
| 3136 |
multi::dispatch->do_protocol_frame(1, 0); // force packets to be sent, ensuring this packet will be attached to following MULTI_TRIGGER |
| 3137 |
|
| 3138 |
count += 1; |
| 3139 |
multi_command<multiplayer_command_t::MULTI_EFFECT_BLOWUP> multibuf; |
| 3140 |
multibuf[count] = Player_num; count += 1; |
| 3141 |
PUT_INTEL_SEGNUM(&multibuf[count], segnum); count += 2; |
| 3142 |
multibuf[count] = static_cast<int8_t>(side); count += 1; |
| 3143 |
multi_put_vector(&multibuf[count], pnt); |
| 3144 |
|
| 3145 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 3146 |
} |
| 3147 |
#endif |
| 3148 |
|
| 3149 |
void multi_send_hostage_door_status(const vcwallptridx_t w) |
| 3150 |
{ |
| 3151 |
// Tell the other player what the hit point status of a hostage door |
| 3152 |
// should be |
| 3153 |
|
| 3154 |
int count{0}; |
| 3155 |
|
| 3156 |
assert(w->type == WALL_BLASTABLE); |
| 3157 |
|
| 3158 |
count += 1; |
| 3159 |
multi_command<multiplayer_command_t::MULTI_HOSTAGE_DOOR> multibuf; |
| 3160 |
PUT_INTEL_SHORT(&multibuf[count], underlying_value(wallnum_t{w})); |
| 3161 |
count += 2; |
| 3162 |
PUT_INTEL_INT(&multibuf[count], w->hps); count += 4; |
| 3163 |
|
| 3164 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 3165 |
} |
| 3166 |
|
| 3167 |
} |
| 3168 |
|
| 3169 |
void multi_consistency_error(int reset) |
| 3170 |
{ |
| 3171 |
static int count = 0; |
| 3172 |
|
| 3173 |
if (reset) |
| 3174 |
count = 0; |
| 3175 |
|
| 3176 |
if (++count < 10) |
| 3177 |
return; |
| 3178 |
|
| 3179 |
const auto g{Game_wind}; |
| 3180 |
if (g) |
| 3181 |
g->set_visible(0); |
| 3182 |
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{TXT_CONSISTENCY_ERROR}); |
| 3183 |
if (g) |
| 3184 |
g->set_visible(1); |
| 3185 |
count = 0; |
| 3186 |
multi_quit_game = 1; |
| 3187 |
game_leave_menus(); |
| 3188 |
multi_reset_stuff(); |
| 3189 |
} |
| 3190 |
|
| 3191 |
namespace { |
| 3192 |
|
| 3193 |
template <netgrant_bit grant, netflag_bit flag, int s = static_cast<int>(grant) - static_cast<int>(flag)> |
| 3194 |
static constexpr netflag_flag grant_shift_helper(const packed_spawn_granted_items p) |
| 3195 |
{ |
| 3196 |
if constexpr (s > 0) |
| 3197 |
return static_cast<netflag_flag>(p.mask >> s); |
| 3198 |
else |
| 3199 |
return static_cast<netflag_flag>(p.mask << -s); |
| 3200 |
} |
| 3201 |
|
| 3202 |
} |
| 3203 |
|
| 3204 |
namespace dsx { |
| 3205 |
|
| 3206 |
player_flags map_granted_flags_to_player_flags(const packed_spawn_granted_items p) |
| 3207 |
{ |
| 3208 |
auto &grant = p.mask; |
| 3209 |
const auto None = PLAYER_FLAG::None; |
| 3210 |
return player_flags( |
| 3211 |
((grant & netgrant_flag::NETGRANT_QUAD) != netgrant_flag::None ? PLAYER_FLAGS_QUAD_LASERS : None) |
| 3212 |
#if DXX_BUILD_DESCENT == 2 |
| 3213 |
| ((grant & netgrant_flag::NETGRANT_AFTERBURNER) != netgrant_flag::None ? PLAYER_FLAGS_AFTERBURNER : None) |
| 3214 |
| ((grant & netgrant_flag::NETGRANT_AMMORACK) != netgrant_flag::None ? PLAYER_FLAGS_AMMO_RACK : None) |
| 3215 |
| ((grant & netgrant_flag::NETGRANT_CONVERTER) != netgrant_flag::None ? PLAYER_FLAGS_CONVERTER : None) |
| 3216 |
| ((grant & netgrant_flag::NETGRANT_HEADLIGHT) != netgrant_flag::None ? PLAYER_FLAGS_HEADLIGHT : None) |
| 3217 |
#endif |
| 3218 |
); |
| 3219 |
} |
| 3220 |
|
| 3221 |
uint_fast32_t map_granted_flags_to_primary_weapon_flags(const packed_spawn_granted_items p) |
| 3222 |
{ |
| 3223 |
auto &grant = p.mask; |
| 3224 |
return ((grant & netgrant_flag::NETGRANT_VULCAN) != netgrant_flag::None ? HAS_VULCAN_FLAG : 0) |
| 3225 |
| ((grant & netgrant_flag::NETGRANT_SPREAD) != netgrant_flag::None ? HAS_SPREADFIRE_FLAG : 0) |
| 3226 |
| ((grant & netgrant_flag::NETGRANT_PLASMA) != netgrant_flag::None ? HAS_PLASMA_FLAG : 0) |
| 3227 |
| ((grant & netgrant_flag::NETGRANT_FUSION) != netgrant_flag::None ? HAS_FUSION_FLAG : 0) |
| 3228 |
#if DXX_BUILD_DESCENT == 2 |
| 3229 |
| ((grant & netgrant_flag::NETGRANT_GAUSS) != netgrant_flag::None ? HAS_GAUSS_FLAG : 0) |
| 3230 |
| ((grant & netgrant_flag::NETGRANT_HELIX) != netgrant_flag::None ? HAS_HELIX_FLAG : 0) |
| 3231 |
| ((grant & netgrant_flag::NETGRANT_PHOENIX) != netgrant_flag::None ? HAS_PHOENIX_FLAG : 0) |
| 3232 |
| ((grant & netgrant_flag::NETGRANT_OMEGA) != netgrant_flag::None ? HAS_OMEGA_FLAG : 0) |
| 3233 |
#endif |
| 3234 |
; |
| 3235 |
} |
| 3236 |
|
| 3237 |
uint16_t map_granted_flags_to_vulcan_ammo(const packed_spawn_granted_items p) |
| 3238 |
{ |
| 3239 |
auto &grant = p.mask; |
| 3240 |
const auto amount{VULCAN_WEAPON_AMMO_AMOUNT}; |
| 3241 |
return |
| 3242 |
#if DXX_BUILD_DESCENT == 2 |
| 3243 |
((grant & netgrant_flag::NETGRANT_GAUSS) != netgrant_flag::None ? amount : 0) + |
| 3244 |
#endif |
| 3245 |
((grant & netgrant_flag::NETGRANT_VULCAN) != netgrant_flag::None ? amount : 0); |
| 3246 |
} |
| 3247 |
|
| 3248 |
namespace { |
| 3249 |
|
| 3250 |
static constexpr netflag_flag map_granted_flags_to_netflag(const packed_spawn_granted_items grant) |
| 3251 |
{ |
| 3252 |
return (grant_shift_helper<BIT_NETGRANT_QUAD, BIT_NETFLAG_DOQUAD>(grant) & (netflag_flag::NETFLAG_DOQUAD | netflag_flag::NETFLAG_DOVULCAN | netflag_flag::NETFLAG_DOSPREAD | netflag_flag::NETFLAG_DOPLASMA | netflag_flag::NETFLAG_DOFUSION)) |
| 3253 |
#if DXX_BUILD_DESCENT == 2 |
| 3254 |
| (grant_shift_helper<BIT_NETGRANT_GAUSS, BIT_NETFLAG_DOGAUSS>(grant) & (netflag_flag::NETFLAG_DOGAUSS | netflag_flag::NETFLAG_DOHELIX | netflag_flag::NETFLAG_DOPHOENIX | netflag_flag::NETFLAG_DOOMEGA)) |
| 3255 |
| (grant_shift_helper<BIT_NETGRANT_AFTERBURNER, BIT_NETFLAG_DOAFTERBURNER>(grant) & (netflag_flag::NETFLAG_DOAFTERBURNER | netflag_flag::NETFLAG_DOAMMORACK | netflag_flag::NETFLAG_DOCONVERTER | netflag_flag::NETFLAG_DOHEADLIGHT)) |
| 3256 |
#endif |
| 3257 |
; |
| 3258 |
} |
| 3259 |
|
| 3260 |
template <netgrant_flag grant, netflag_flag expected_flag, netflag_flag actual_flag = map_granted_flags_to_netflag(grant)> |
| 3261 |
struct assert_netgrant_map_result : std::true_type |
| 3262 |
{ |
| 3263 |
static_assert(actual_flag == expected_flag); |
| 3264 |
}; |
| 3265 |
|
| 3266 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_QUAD, netflag_flag::NETFLAG_DOQUAD>::value, "QUAD"); |
| 3267 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_QUAD | netgrant_flag::NETGRANT_PLASMA, netflag_flag::NETFLAG_DOQUAD | netflag_flag::NETFLAG_DOPLASMA>::value, "QUAD | PLASMA"); |
| 3268 |
#if DXX_BUILD_DESCENT == 2 |
| 3269 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_GAUSS, netflag_flag::NETFLAG_DOGAUSS>::value, "GAUSS"); |
| 3270 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_GAUSS | netgrant_flag::NETGRANT_PLASMA, netflag_flag::NETFLAG_DOGAUSS | netflag_flag::NETFLAG_DOPLASMA>::value, "GAUSS | PLASMA"); |
| 3271 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_GAUSS | netgrant_flag::NETGRANT_AFTERBURNER, netflag_flag::NETFLAG_DOGAUSS | netflag_flag::NETFLAG_DOAFTERBURNER>::value, "GAUSS | AFTERBURNER"); |
| 3272 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_GAUSS | netgrant_flag::NETGRANT_PLASMA | netgrant_flag::NETGRANT_AFTERBURNER, netflag_flag::NETFLAG_DOGAUSS | netflag_flag::NETFLAG_DOPLASMA | netflag_flag::NETFLAG_DOAFTERBURNER>::value, "GAUSS | PLASMA | AFTERBURNER"); |
| 3273 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_PLASMA | netgrant_flag::NETGRANT_AFTERBURNER, netflag_flag::NETFLAG_DOPLASMA | netflag_flag::NETFLAG_DOAFTERBURNER>::value, "PLASMA | AFTERBURNER"); |
| 3274 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_AFTERBURNER, netflag_flag::NETFLAG_DOAFTERBURNER>::value, "AFTERBURNER"); |
| 3275 |
static_assert(assert_netgrant_map_result<netgrant_flag::NETGRANT_HEADLIGHT, netflag_flag::NETFLAG_DOHEADLIGHT>::value, "HEADLIGHT"); |
| 3276 |
#endif |
| 3277 |
|
| 3278 |
class update_item_state |
| 3279 |
{ |
| 3280 |
std::bitset<MAX_OBJECTS> m_modified; |
| 3281 |
public: |
| 3282 |
bool must_skip(const vcobjidx_t i) const |
| 3283 |
{ |
| 3284 |
return m_modified.test(i); |
| 3285 |
} |
| 3286 |
void process_powerup(const d_vclip_array &Vclip, fvmsegptridx &, const object &, powerup_type_t); |
| 3287 |
}; |
| 3288 |
|
| 3289 |
class powerup_shuffle_state |
| 3290 |
{ |
| 3291 |
unsigned count{0}; |
| 3292 |
unsigned seed; |
| 3293 |
union { |
| 3294 |
std::array<vmobjptridx_t, MAX_OBJECTS> ptrs; |
| 3295 |
}; |
| 3296 |
public: |
| 3297 |
powerup_shuffle_state(const unsigned s) : |
| 3298 |
seed(s) |
| 3299 |
{ |
| 3300 |
} |
| 3301 |
void record_powerup(vmobjptridx_t); |
| 3302 |
void shuffle() const; |
| 3303 |
}; |
| 3304 |
|
| 3305 |
void update_item_state::process_powerup(const d_vclip_array &Vclip, fvmsegptridx &vmsegptridx, const object &o, const powerup_type_t id) |
| 3306 |
{ |
| 3307 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 3308 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 3309 |
uint_fast32_t count; |
| 3310 |
switch (id) |
| 3311 |
{ |
| 3312 |
case powerup_type_t::POW_LASER: |
| 3313 |
case powerup_type_t::POW_QUAD_FIRE: |
| 3314 |
case powerup_type_t::POW_VULCAN_WEAPON: |
| 3315 |
case powerup_type_t::POW_VULCAN_AMMO: |
| 3316 |
case powerup_type_t::POW_SPREADFIRE_WEAPON: |
| 3317 |
case powerup_type_t::POW_PLASMA_WEAPON: |
| 3318 |
case powerup_type_t::POW_FUSION_WEAPON: |
| 3319 |
#if DXX_BUILD_DESCENT == 2 |
| 3320 |
case powerup_type_t::POW_SUPER_LASER: |
| 3321 |
case powerup_type_t::POW_GAUSS_WEAPON: |
| 3322 |
case powerup_type_t::POW_HELIX_WEAPON: |
| 3323 |
case powerup_type_t::POW_PHOENIX_WEAPON: |
| 3324 |
case powerup_type_t::POW_OMEGA_WEAPON: |
| 3325 |
#endif |
| 3326 |
count = Netgame.DuplicatePowerups.get_primary_count(); |
| 3327 |
break; |
| 3328 |
case powerup_type_t::POW_MISSILE_1: |
| 3329 |
case powerup_type_t::POW_MISSILE_4: |
| 3330 |
case powerup_type_t::POW_HOMING_AMMO_1: |
| 3331 |
case powerup_type_t::POW_HOMING_AMMO_4: |
| 3332 |
case powerup_type_t::POW_PROXIMITY_WEAPON: |
| 3333 |
case powerup_type_t::POW_SMARTBOMB_WEAPON: |
| 3334 |
case powerup_type_t::POW_MEGA_WEAPON: |
| 3335 |
#if DXX_BUILD_DESCENT == 2 |
| 3336 |
case powerup_type_t::POW_SMISSILE1_1: |
| 3337 |
case powerup_type_t::POW_SMISSILE1_4: |
| 3338 |
case powerup_type_t::POW_GUIDED_MISSILE_1: |
| 3339 |
case powerup_type_t::POW_GUIDED_MISSILE_4: |
| 3340 |
case powerup_type_t::POW_SMART_MINE: |
| 3341 |
case powerup_type_t::POW_MERCURY_MISSILE_1: |
| 3342 |
case powerup_type_t::POW_MERCURY_MISSILE_4: |
| 3343 |
case powerup_type_t::POW_EARTHSHAKER_MISSILE: |
| 3344 |
#endif |
| 3345 |
count = Netgame.DuplicatePowerups.get_secondary_count(); |
| 3346 |
break; |
| 3347 |
#if DXX_BUILD_DESCENT == 2 |
| 3348 |
case powerup_type_t::POW_FULL_MAP: |
| 3349 |
case powerup_type_t::POW_CONVERTER: |
| 3350 |
case powerup_type_t::POW_AMMO_RACK: |
| 3351 |
case powerup_type_t::POW_AFTERBURNER: |
| 3352 |
case powerup_type_t::POW_HEADLIGHT: |
| 3353 |
count = Netgame.DuplicatePowerups.get_accessory_count(); |
| 3354 |
break; |
| 3355 |
#endif |
| 3356 |
default: |
| 3357 |
return; |
| 3358 |
} |
| 3359 |
if (!count) |
| 3360 |
return; |
| 3361 |
const auto &vc = Vclip[o.rtype.vclip_info.vclip_num]; |
| 3362 |
const auto vc_num_frames = vc.num_frames; |
| 3363 |
const auto &&segp = vmsegptridx(o.segnum); |
| 3364 |
const auto &seg_verts = segp->verts; |
| 3365 |
auto &vcvertptr = Vertices.vcptr; |
| 3366 |
for (uint_fast32_t i = count++; i; --i) |
| 3367 |
{ |
| 3368 |
assert(o.movement_source == object::movement_type::None); |
| 3369 |
assert(o.render_type == render_type::RT_POWERUP); |
| 3370 |
const auto &&no = obj_create(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, OBJ_POWERUP, underlying_value(id), segp, vm_vec_build_avg(o.pos, vcvertptr(seg_verts[static_cast<segment_relative_vertnum>(i % seg_verts.size())])), &vmd_identity_matrix, o.size, object::control_type::powerup, object::movement_type::None, render_type::RT_POWERUP); |
| 3371 |
if (no == object_none) |
| 3372 |
return; |
| 3373 |
m_modified.set(no); |
| 3374 |
no->rtype.vclip_info = o.rtype.vclip_info; |
| 3375 |
/* Vary the frame number so that the powerups are not animated |
| 3376 |
* in sync. |
| 3377 |
*/ |
| 3378 |
no->rtype.vclip_info.framenum = (o.rtype.vclip_info.framenum + (i * vc_num_frames) / count) % vc_num_frames; |
| 3379 |
no->ctype.powerup_info = o.ctype.powerup_info; |
| 3380 |
} |
| 3381 |
} |
| 3382 |
|
| 3383 |
class accumulate_object_count |
| 3384 |
{ |
| 3385 |
protected: |
| 3386 |
using array_reference = enumerated_array<uint32_t, MAX_POWERUP_TYPES, powerup_type_t> &; |
| 3387 |
array_reference current; |
| 3388 |
accumulate_object_count(array_reference a) : current(a) |
| 3389 |
{ |
| 3390 |
} |
| 3391 |
}; |
| 3392 |
|
| 3393 |
template <typename F, typename M> |
| 3394 |
class accumulate_flags_count : accumulate_object_count |
| 3395 |
{ |
| 3396 |
const F &flags; |
| 3397 |
public: |
| 3398 |
accumulate_flags_count(array_reference current, const F &f) : |
| 3399 |
accumulate_object_count{current}, flags(f) |
| 3400 |
{ |
| 3401 |
} |
| 3402 |
void process(const M mask, const powerup_type_t id) const |
| 3403 |
{ |
| 3404 |
if (flags & mask) |
| 3405 |
++current[id]; |
| 3406 |
} |
| 3407 |
}; |
| 3408 |
|
| 3409 |
} |
| 3410 |
|
| 3411 |
/* |
| 3412 |
* The place to do objects operations such as: |
| 3413 |
* Robot deletion for non-robot games, Powerup duplication, AllowedItems, Initial powerup counting. |
| 3414 |
* MUST be done before multi_level_sync() in case we join a running game and get updated objects there. We want the initial powerup setup for a level here! |
| 3415 |
*/ |
| 3416 |
void multi_prep_level_objects(const d_powerup_info_array &Powerup_info, const d_vclip_array &Vclip) |
| 3417 |
{ |
| 3418 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3419 |
auto &vmobjptridx = Objects.vmptridx; |
| 3420 |
if (!(Game_mode & GM_MULTI_COOP)) |
| 3421 |
{ |
| 3422 |
multi_update_objects_for_non_cooperative(); // Removes monsters from level |
| 3423 |
} |
| 3424 |
|
| 3425 |
constexpr unsigned MAX_ALLOWED_INVULNERABILITY = 3; |
| 3426 |
constexpr unsigned MAX_ALLOWED_CLOAK = 3; |
| 3427 |
const auto AllowedItems{Netgame.AllowedItems}; |
| 3428 |
const auto SpawnGrantedItems = map_granted_flags_to_netflag(Netgame.SpawnGrantedItems); |
| 3429 |
unsigned inv_remaining = (AllowedItems & netflag_flag::NETFLAG_DOINVUL) != netflag_flag::None ? MAX_ALLOWED_INVULNERABILITY : 0; |
| 3430 |
unsigned cloak_remaining = (AllowedItems & netflag_flag::NETFLAG_DOCLOAK) != netflag_flag::None ? MAX_ALLOWED_CLOAK : 0; |
| 3431 |
update_item_state duplicates; |
| 3432 |
range_for (const auto &&o, vmobjptridx) |
| 3433 |
{ |
| 3434 |
if ((o->type == OBJ_HOSTAGE) && !(Game_mode & GM_MULTI_COOP)) |
| 3435 |
{ |
| 3436 |
/* In non-cooperative multiplayer games, replace hostage powerups |
| 3437 |
* with shield powerups. |
| 3438 |
*/ |
| 3439 |
const auto &&objnum = obj_create(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, OBJ_POWERUP, underlying_value(powerup_type_t::POW_SHIELD_BOOST), vmsegptridx(o->segnum), o->pos, &vmd_identity_matrix, Powerup_info[powerup_type_t::POW_SHIELD_BOOST].size, object::control_type::powerup, object::movement_type::physics, render_type::RT_POWERUP); |
| 3440 |
obj_delete(LevelUniqueObjectState, Segments, o); |
| 3441 |
if (objnum != object_none) |
| 3442 |
{ |
| 3443 |
objnum->rtype.vclip_info.vclip_num = Powerup_info[powerup_type_t::POW_SHIELD_BOOST].vclip_num; |
| 3444 |
objnum->rtype.vclip_info.frametime = Vclip[objnum->rtype.vclip_info.vclip_num].frame_time; |
| 3445 |
objnum->rtype.vclip_info.framenum = 0; |
| 3446 |
objnum->mtype.phys_info.drag = 512; //1024; |
| 3447 |
objnum->mtype.phys_info.mass = F1_0; |
| 3448 |
objnum->mtype.phys_info.velocity = {}; |
| 3449 |
} |
| 3450 |
continue; |
| 3451 |
} |
| 3452 |
|
| 3453 |
if (o->type == OBJ_POWERUP && !duplicates.must_skip(o)) |
| 3454 |
{ |
| 3455 |
switch (const auto id = get_powerup_id(o)) |
| 3456 |
{ |
| 3457 |
case powerup_type_t::POW_EXTRA_LIFE: |
| 3458 |
set_powerup_id(Powerup_info, Vclip, o, powerup_type_t::POW_INVULNERABILITY); |
| 3459 |
[[fallthrough]]; |
| 3460 |
case powerup_type_t::POW_INVULNERABILITY: |
| 3461 |
if (inv_remaining) |
| 3462 |
-- inv_remaining; |
| 3463 |
else |
| 3464 |
set_powerup_id(Powerup_info, Vclip, o, powerup_type_t::POW_SHIELD_BOOST); |
| 3465 |
continue; |
| 3466 |
case powerup_type_t::POW_CLOAK: |
| 3467 |
if (cloak_remaining) |
| 3468 |
-- cloak_remaining; |
| 3469 |
else |
| 3470 |
set_powerup_id(Powerup_info, Vclip, o, powerup_type_t::POW_SHIELD_BOOST); |
| 3471 |
continue; |
| 3472 |
default: |
| 3473 |
if (multi_powerup_is_allowed(id, AllowedItems, SpawnGrantedItems) == netflag_flag::None) |
| 3474 |
bash_to_shield(Powerup_info, Vclip, o); |
| 3475 |
else |
| 3476 |
duplicates.process_powerup(Vclip, vmsegptridx, o, id); |
| 3477 |
continue; |
| 3478 |
} |
| 3479 |
} |
| 3480 |
} |
| 3481 |
|
| 3482 |
// After everything is done, count initial level inventory. |
| 3483 |
MultiLevelInv_InitializeCount(); |
| 3484 |
} |
| 3485 |
|
| 3486 |
void multi_prep_level_player(void) |
| 3487 |
{ |
| 3488 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3489 |
auto &vmobjptr = Objects.vmptr; |
| 3490 |
// Do any special stuff to the level required for games |
| 3491 |
// before we begin playing in it. |
| 3492 |
|
| 3493 |
// Player_num MUST be set before calling this procedure. |
| 3494 |
|
| 3495 |
// This function must be called before checksuming the Object array, |
| 3496 |
// since the resulting checksum with depend on the value of Player_num |
| 3497 |
// at the time this is called. |
| 3498 |
|
| 3499 |
Assert(Game_mode & GM_MULTI); |
| 3500 |
|
| 3501 |
Assert(NumNetPlayerPositions > 0); |
| 3502 |
|
| 3503 |
#if DXX_BUILD_DESCENT == 2 |
| 3504 |
hoard_highest_record_stats = {}; |
| 3505 |
Drop_afterburner_blob_flag=0; |
| 3506 |
#endif |
| 3507 |
Bounty_target = 0; |
| 3508 |
|
| 3509 |
multi_consistency_error(1); |
| 3510 |
|
| 3511 |
multi_sending_message.fill(msgsend_state::none); |
| 3512 |
if (imulti_new_game) |
| 3513 |
for (uint_fast32_t i = 0; i != Players.size(); i++) |
| 3514 |
init_player_stats_new_ship(i); |
| 3515 |
|
| 3516 |
for (unsigned i = 0; i < NumNetPlayerPositions; i++) |
| 3517 |
{ |
| 3518 |
const auto &&objp = vmobjptr(vcplayerptr(i)->objnum); |
| 3519 |
if (i != Player_num) |
| 3520 |
objp->control_source = object::control_type::remote; |
| 3521 |
objp->movement_source = object::movement_type::physics; |
| 3522 |
multi_reset_player_object(objp); |
| 3523 |
Netgame.players[i].LastPacketTime = 0; |
| 3524 |
} |
| 3525 |
|
| 3526 |
robot_controlled.fill(-1); |
| 3527 |
robot_agitation = {}; |
| 3528 |
robot_fired = {}; |
| 3529 |
|
| 3530 |
Viewer = ConsoleObject = &get_local_plrobj(); |
| 3531 |
|
| 3532 |
#if DXX_BUILD_DESCENT == 2 |
| 3533 |
if (game_mode_hoard(Game_mode)) |
| 3534 |
init_hoard_data(Vclip); |
| 3535 |
|
| 3536 |
if (game_mode_capture_flag(Game_mode) || game_mode_hoard(Game_mode)) |
| 3537 |
multi_apply_goal_textures(); |
| 3538 |
#endif |
| 3539 |
|
| 3540 |
multi_sort_kill_list(); |
| 3541 |
|
| 3542 |
multi_show_player_list(); |
| 3543 |
|
| 3544 |
ConsoleObject->control_source = object::control_type::flying; |
| 3545 |
|
| 3546 |
reset_player_object(*ConsoleObject); |
| 3547 |
|
| 3548 |
imulti_new_game=0; |
| 3549 |
} |
| 3550 |
|
| 3551 |
#if DXX_BUILD_DESCENT == 2 |
| 3552 |
namespace { |
| 3553 |
|
| 3554 |
void apply_segment_goal_texture(const d_level_unique_tmap_info_state &LevelUniqueTmapInfoState, unique_segment &seg, const texture1_value tex) |
| 3555 |
{ |
| 3556 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 3557 |
const auto bright_light = i2f(100); //make static light bright |
| 3558 |
seg.static_light = bright_light; |
| 3559 |
if (static_cast<unsigned>(tex) < TmapInfo.size()) |
| 3560 |
range_for (auto &s, seg.sides) |
| 3561 |
{ |
| 3562 |
s.tmap_num = tex; |
| 3563 |
range_for (auto &uvl, s.uvls) |
| 3564 |
uvl.l = bright_light; //max out |
| 3565 |
} |
| 3566 |
} |
| 3567 |
|
| 3568 |
texture_index find_goal_texture(const d_level_unique_tmap_info_state &LevelUniqueTmapInfoState, const tmapinfo_flag tmi_flag) |
| 3569 |
{ |
| 3570 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 3571 |
const auto &&r = partial_const_range(TmapInfo, NumTextures); |
| 3572 |
const auto &&predicate = [tmi_flag](const tmap_info &i) { |
| 3573 |
return (i.flags & tmi_flag); |
| 3574 |
}; |
| 3575 |
const auto begin = r.begin(); |
| 3576 |
return std::distance(begin, std::ranges::find_if(begin, r.end(), predicate)); |
| 3577 |
} |
| 3578 |
|
| 3579 |
const tmap_info &find_required_goal_texture(const d_level_unique_tmap_info_state &LevelUniqueTmapInfoState, const tmapinfo_flag tmi_flag) |
| 3580 |
{ |
| 3581 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 3582 |
const auto found_index = find_goal_texture(LevelUniqueTmapInfoState, tmi_flag); |
| 3583 |
std::size_t r = found_index; |
| 3584 |
if (r < TmapInfo.size()) |
| 3585 |
return TmapInfo[r]; |
| 3586 |
Int3(); // Hey, there is no goal texture for this PIG!!!! |
| 3587 |
// Edit bitmaps.tbl and designate two textures to be RED and BLUE |
| 3588 |
// goal textures |
| 3589 |
throw std::runtime_error("PIG missing goal texture"); |
| 3590 |
} |
| 3591 |
|
| 3592 |
} |
| 3593 |
|
| 3594 |
void multi_apply_goal_textures() |
| 3595 |
{ |
| 3596 |
texture1_value tex_blue, tex_red; |
| 3597 |
if (game_mode_hoard(Game_mode)) |
| 3598 |
tex_blue = tex_red = build_texture1_value(find_goal_texture(LevelUniqueTmapInfoState, tmapinfo_flag::goal_hoard)); |
| 3599 |
else |
| 3600 |
{ |
| 3601 |
tex_blue = build_texture1_value(find_goal_texture(LevelUniqueTmapInfoState, tmapinfo_flag::goal_blue)); |
| 3602 |
tex_red = build_texture1_value(find_goal_texture(LevelUniqueTmapInfoState, tmapinfo_flag::goal_red)); |
| 3603 |
} |
| 3604 |
for (auto &seg : vmsegptr) |
| 3605 |
{ |
| 3606 |
texture1_value tex; |
| 3607 |
if (seg.special == segment_special::goal_blue) |
| 3608 |
{ |
| 3609 |
tex = tex_blue; |
| 3610 |
} |
| 3611 |
else if (seg.special == segment_special::goal_red) |
| 3612 |
{ |
| 3613 |
// Make both textures the same if Hoard mode |
| 3614 |
tex = tex_red; |
| 3615 |
} |
| 3616 |
else |
| 3617 |
continue; |
| 3618 |
apply_segment_goal_texture(LevelUniqueTmapInfoState, seg, tex); |
| 3619 |
} |
| 3620 |
} |
| 3621 |
#endif |
| 3622 |
|
| 3623 |
namespace { |
| 3624 |
|
| 3625 |
static int object_allowed_in_anarchy(const object_base &objp) |
| 3626 |
{ |
| 3627 |
if (objp.type == OBJ_NONE || |
| 3628 |
objp.type == OBJ_PLAYER || |
| 3629 |
objp.type == OBJ_POWERUP || |
| 3630 |
objp.type == OBJ_CNTRLCEN || |
| 3631 |
objp.type == OBJ_HOSTAGE) |
| 3632 |
return 1; |
| 3633 |
#if DXX_BUILD_DESCENT == 2 |
| 3634 |
if (objp.type == OBJ_WEAPON && get_weapon_id(objp) == weapon_id_type::PMINE_ID) |
| 3635 |
return 1; |
| 3636 |
#endif |
| 3637 |
return 0; |
| 3638 |
} |
| 3639 |
|
| 3640 |
void powerup_shuffle_state::record_powerup(const vmobjptridx_t o) |
| 3641 |
{ |
| 3642 |
if (!seed) |
| 3643 |
return; |
| 3644 |
const auto id = get_powerup_id(o); |
| 3645 |
switch (id) |
| 3646 |
{ |
| 3647 |
/* record_powerup runs before object conversion or duplication, |
| 3648 |
* so object types that anarchy converts still have their |
| 3649 |
* original type when this switch runs. Therefore, |
| 3650 |
* powerup_type_t::POW_EXTRA_LIFE and the key powerups must be handled here, |
| 3651 |
* even though they are converted to other objects before play |
| 3652 |
* begins. If they were not handled, no object could exchange |
| 3653 |
* places with a converted object. |
| 3654 |
*/ |
| 3655 |
case powerup_type_t::POW_EXTRA_LIFE: |
| 3656 |
case powerup_type_t::POW_ENERGY: |
| 3657 |
case powerup_type_t::POW_SHIELD_BOOST: |
| 3658 |
case powerup_type_t::POW_LASER: |
| 3659 |
case powerup_type_t::POW_KEY_BLUE: |
| 3660 |
case powerup_type_t::POW_KEY_RED: |
| 3661 |
case powerup_type_t::POW_KEY_GOLD: |
| 3662 |
case powerup_type_t::POW_MISSILE_1: |
| 3663 |
case powerup_type_t::POW_MISSILE_4: |
| 3664 |
case powerup_type_t::POW_QUAD_FIRE: |
| 3665 |
case powerup_type_t::POW_VULCAN_WEAPON: |
| 3666 |
case powerup_type_t::POW_SPREADFIRE_WEAPON: |
| 3667 |
case powerup_type_t::POW_PLASMA_WEAPON: |
| 3668 |
case powerup_type_t::POW_FUSION_WEAPON: |
| 3669 |
case powerup_type_t::POW_PROXIMITY_WEAPON: |
| 3670 |
case powerup_type_t::POW_HOMING_AMMO_1: |
| 3671 |
case powerup_type_t::POW_HOMING_AMMO_4: |
| 3672 |
case powerup_type_t::POW_SMARTBOMB_WEAPON: |
| 3673 |
case powerup_type_t::POW_MEGA_WEAPON: |
| 3674 |
case powerup_type_t::POW_VULCAN_AMMO: |
| 3675 |
case powerup_type_t::POW_CLOAK: |
| 3676 |
case powerup_type_t::POW_INVULNERABILITY: |
| 3677 |
#if DXX_BUILD_DESCENT == 2 |
| 3678 |
case powerup_type_t::POW_GAUSS_WEAPON: |
| 3679 |
case powerup_type_t::POW_HELIX_WEAPON: |
| 3680 |
case powerup_type_t::POW_PHOENIX_WEAPON: |
| 3681 |
case powerup_type_t::POW_OMEGA_WEAPON: |
| 3682 |
|
| 3683 |
case powerup_type_t::POW_SUPER_LASER: |
| 3684 |
case powerup_type_t::POW_FULL_MAP: |
| 3685 |
case powerup_type_t::POW_CONVERTER: |
| 3686 |
case powerup_type_t::POW_AMMO_RACK: |
| 3687 |
case powerup_type_t::POW_AFTERBURNER: |
| 3688 |
case powerup_type_t::POW_HEADLIGHT: |
| 3689 |
|
| 3690 |
case powerup_type_t::POW_SMISSILE1_1: |
| 3691 |
case powerup_type_t::POW_SMISSILE1_4: |
| 3692 |
case powerup_type_t::POW_GUIDED_MISSILE_1: |
| 3693 |
case powerup_type_t::POW_GUIDED_MISSILE_4: |
| 3694 |
case powerup_type_t::POW_SMART_MINE: |
| 3695 |
case powerup_type_t::POW_MERCURY_MISSILE_1: |
| 3696 |
case powerup_type_t::POW_MERCURY_MISSILE_4: |
| 3697 |
case powerup_type_t::POW_EARTHSHAKER_MISSILE: |
| 3698 |
#endif |
| 3699 |
break; |
| 3700 |
default: |
| 3701 |
return; |
| 3702 |
} |
| 3703 |
if (count >= ptrs.size()) |
| 3704 |
return; |
| 3705 |
ptrs[count++] = o; |
| 3706 |
} |
| 3707 |
|
| 3708 |
void powerup_shuffle_state::shuffle() const |
| 3709 |
{ |
| 3710 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3711 |
auto &vmobjptr = Objects.vmptr; |
| 3712 |
if (!count) |
| 3713 |
return; |
| 3714 |
std::minstd_rand mr(seed); |
| 3715 |
for (unsigned j = count; --j;) |
| 3716 |
{ |
| 3717 |
const auto oi = std::uniform_int_distribution<unsigned>(0u, j)(mr); |
| 3718 |
if (oi == j) |
| 3719 |
/* Swapping an object with itself is a no-op. Skip the |
| 3720 |
* work. Do not re-roll, both to avoid the potential for an |
| 3721 |
* infinite loop on unlucky rolls and to ensure a uniform |
| 3722 |
* distribution of swaps. |
| 3723 |
*/ |
| 3724 |
continue; |
| 3725 |
const auto o0 = ptrs[j]; |
| 3726 |
const auto o1 = ptrs[oi]; |
| 3727 |
const auto os0 = o0->segnum; |
| 3728 |
const auto os1 = o1->segnum; |
| 3729 |
/* Disconnect both objects from their original segments. Swap |
| 3730 |
* their positions. Link each object to the segment that the |
| 3731 |
* other object previously used. This is necessary instead of |
| 3732 |
* using std::swap on object::segnum, since the segment's linked |
| 3733 |
* list of objects needs to be updated. |
| 3734 |
*/ |
| 3735 |
obj_unlink(vmobjptr, vmsegptr, *o0); |
| 3736 |
obj_unlink(vmobjptr, vmsegptr, *o1); |
| 3737 |
std::swap(o0->pos, o1->pos); |
| 3738 |
obj_link_unchecked(vmobjptr, o0, vmsegptridx(os1)); |
| 3739 |
obj_link_unchecked(vmobjptr, o1, vmsegptridx(os0)); |
| 3740 |
} |
| 3741 |
} |
| 3742 |
|
| 3743 |
void multi_update_objects_for_non_cooperative() |
| 3744 |
{ |
| 3745 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3746 |
auto &vmobjptridx = Objects.vmptridx; |
| 3747 |
// Go through the object list and remove any objects not used in |
| 3748 |
// 'Anarchy!' games. |
| 3749 |
|
| 3750 |
const auto game_mode{Game_mode}; |
| 3751 |
/* Shuffle objects before object duplication runs. Otherwise, |
| 3752 |
* duplication-eligible items would be duplicated, then scattered, |
| 3753 |
* causing the original site to be a treasure trove of swapped |
| 3754 |
* items. This way, duplicated items appear with their original. |
| 3755 |
*/ |
| 3756 |
powerup_shuffle_state powerup_shuffle(Netgame.ShufflePowerupSeed); |
| 3757 |
range_for (const auto &&objp, vmobjptridx) |
| 3758 |
{ |
| 3759 |
const auto obj_type = objp->type; |
| 3760 |
if (obj_type == OBJ_PLAYER || obj_type == OBJ_GHOST) |
| 3761 |
continue; |
| 3762 |
else if (obj_type == OBJ_ROBOT && (game_mode & GM_MULTI_ROBOTS)) |
| 3763 |
continue; |
| 3764 |
else if (obj_type == OBJ_POWERUP) |
| 3765 |
{ |
| 3766 |
powerup_shuffle.record_powerup(objp); |
| 3767 |
continue; |
| 3768 |
} |
| 3769 |
else if (!object_allowed_in_anarchy(objp) ) { |
| 3770 |
#if DXX_BUILD_DESCENT == 2 |
| 3771 |
// Before deleting object, if it's a robot, drop it's special powerup, if any |
| 3772 |
if (obj_type == OBJ_ROBOT) |
| 3773 |
if (objp->contains.count && objp->contains.type == contained_object_type::powerup) |
| 3774 |
object_create_robot_egg(LevelSharedRobotInfoState.Robot_info, objp); |
| 3775 |
#endif |
| 3776 |
obj_delete(LevelUniqueObjectState, Segments, objp); |
| 3777 |
} |
| 3778 |
} |
| 3779 |
powerup_shuffle.shuffle(); |
| 3780 |
} |
| 3781 |
|
| 3782 |
} |
| 3783 |
|
| 3784 |
} |
| 3785 |
|
| 3786 |
namespace { |
| 3787 |
|
| 3788 |
// Returns the Player_num of Master/Host of this game |
| 3789 |
playernum_t multi_who_is_master() |
| 3790 |
{ |
| 3791 |
return 0; |
| 3792 |
} |
| 3793 |
|
| 3794 |
} |
| 3795 |
|
| 3796 |
void change_playernum_to(const playernum_t new_Player_num) |
| 3797 |
{ |
| 3798 |
if (Player_num < Players.size()) |
| 3799 |
{ |
| 3800 |
vmplayerptr(new_Player_num)->callsign = get_local_player().callsign; |
| 3801 |
} |
| 3802 |
Player_num = new_Player_num; |
| 3803 |
} |
| 3804 |
|
| 3805 |
namespace dsx { |
| 3806 |
|
| 3807 |
#if DXX_BUILD_DESCENT == 1 |
| 3808 |
static |
| 3809 |
#endif |
| 3810 |
int multi_all_players_alive(const fvcobjptr &vcobjptr, const std::ranges::subrange<const player *> player_range) |
| 3811 |
{ |
| 3812 |
range_for (auto &plr, player_range) |
| 3813 |
{ |
| 3814 |
const auto connected{plr.connected}; |
| 3815 |
if (connected == player_connection_status::playing) |
| 3816 |
{ |
| 3817 |
if (vcobjptr(plr.objnum)->type == OBJ_GHOST) // player alive? |
| 3818 |
return 0; |
| 3819 |
} |
| 3820 |
else if (connected != player_connection_status::disconnected) // ... and actually playing? |
| 3821 |
return 0; |
| 3822 |
} |
| 3823 |
return (1); |
| 3824 |
} |
| 3825 |
|
| 3826 |
const char *multi_common_deny_save_game(const fvcobjptr &vcobjptr, const std::ranges::subrange<const player *> player_range) |
| 3827 |
{ |
| 3828 |
if (Network_status == network_state::endlevel) |
| 3829 |
return "Level is ending"; |
| 3830 |
if (!multi_all_players_alive(vcobjptr, player_range)) |
| 3831 |
return "All players must be alive and playing!"; |
| 3832 |
return deny_multi_save_game_duplicate_callsign(player_range); |
| 3833 |
} |
| 3834 |
|
| 3835 |
const char *multi_interactive_deny_save_game(const fvcobjptr &vcobjptr, const std::ranges::subrange<const player *> player_range, const d_level_unique_control_center_state &LevelUniqueControlCenterState) |
| 3836 |
{ |
| 3837 |
if (LevelUniqueControlCenterState.Control_center_destroyed) |
| 3838 |
return "Countdown in progress"; |
| 3839 |
return multi_common_deny_save_game(vcobjptr, player_range); |
| 3840 |
} |
| 3841 |
|
| 3842 |
void multi_send_drop_weapon(const vmobjptridx_t objp, int seed) |
| 3843 |
{ |
| 3844 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3845 |
auto &vmobjptridx = Objects.vmptridx; |
| 3846 |
int count{0}; |
| 3847 |
int ammo_count; |
| 3848 |
|
| 3849 |
multi_send_position(vmobjptridx(get_local_player().objnum)); |
| 3850 |
ammo_count = objp->ctype.powerup_info.count; |
| 3851 |
|
| 3852 |
#if DXX_BUILD_DESCENT == 2 |
| 3853 |
if (get_powerup_id(objp) == powerup_type_t::POW_OMEGA_WEAPON && ammo_count == F1_0) |
| 3854 |
ammo_count = F1_0 - 1; //make fit in short |
| 3855 |
#endif |
| 3856 |
|
| 3857 |
Assert(ammo_count < F1_0); //make sure fits in short |
| 3858 |
|
| 3859 |
count++; |
| 3860 |
multi_command<multiplayer_command_t::MULTI_DROP_WEAPON> multibuf; |
| 3861 |
multibuf[count++]=static_cast<char>(get_powerup_id(objp)); |
| 3862 |
PUT_INTEL_SHORT(&multibuf[count], objp); count += 2; |
| 3863 |
PUT_INTEL_SHORT(&multibuf[count], static_cast<uint16_t>(ammo_count)); count += 2; |
| 3864 |
PUT_INTEL_INT(&multibuf[count], seed); |
| 3865 |
count += 4; |
| 3866 |
|
| 3867 |
map_objnum_local_to_local(objp); |
| 3868 |
|
| 3869 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 3870 |
} |
| 3871 |
|
| 3872 |
namespace { |
| 3873 |
|
| 3874 |
static void multi_do_drop_weapon(fvmobjptr &vmobjptr, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_DROP_WEAPON> buf) |
| 3875 |
{ |
| 3876 |
const auto powerup_id = static_cast<powerup_type_t>(buf[1]); |
| 3877 |
const objnum_t remote_objnum{GET_INTEL_SHORT(&buf[2])}; |
| 3878 |
const uint16_t ammo{GET_INTEL_SHORT(&buf[4])}; |
| 3879 |
const auto seed{GET_INTEL_INT(&buf[6])}; |
| 3880 |
const auto &&objnum = spit_powerup(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, Vclip, vmobjptr(vcplayerptr(pnum)->objnum), powerup_id, seed); |
| 3881 |
if (objnum == object_none) |
| 3882 |
return; |
| 3883 |
objnum->ctype.powerup_info.count = ammo; |
| 3884 |
map_objnum_local_to_remote(objnum, remote_objnum, pnum); |
| 3885 |
} |
| 3886 |
|
| 3887 |
} |
| 3888 |
|
| 3889 |
// We collected some ammo from a vulcan/gauss cannon powerup. Now we need to let everyone else know about its new ammo count. |
| 3890 |
void multi_send_vulcan_weapon_ammo_adjust(const vmobjptridx_t objnum) |
| 3891 |
{ |
| 3892 |
const auto &&[obj_owner, remote_objnum] = objnum_local_to_remote(objnum); |
| 3893 |
multi_command<multiplayer_command_t::MULTI_VULWPN_AMMO_ADJ> multibuf; |
| 3894 |
PUT_INTEL_SHORT(&multibuf[1], remote_objnum); // Map to network objnums |
| 3895 |
|
| 3896 |
multibuf[3] = obj_owner; |
| 3897 |
|
| 3898 |
const uint16_t ammo_count = objnum->ctype.powerup_info.count; |
| 3899 |
PUT_INTEL_SHORT(&multibuf[4], ammo_count); |
| 3900 |
|
| 3901 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 3902 |
|
| 3903 |
if (Network_send_objects && multi::dispatch->objnum_is_past(objnum)) |
| 3904 |
{ |
| 3905 |
Network_send_objnum = -1; |
| 3906 |
} |
| 3907 |
} |
| 3908 |
|
| 3909 |
namespace { |
| 3910 |
|
| 3911 |
static void multi_do_vulcan_weapon_ammo_adjust(fvmobjptr &vmobjptr, const multiplayer_rspan<multiplayer_command_t::MULTI_VULWPN_AMMO_ADJ> buf) |
| 3912 |
{ |
| 3913 |
// which object to update |
| 3914 |
const objnum_t objnum{GET_INTEL_SHORT(&buf[1])}; |
| 3915 |
// which remote list is it entered in |
| 3916 |
auto obj_owner = buf[3]; |
| 3917 |
|
| 3918 |
assert(objnum != object_none); |
| 3919 |
|
| 3920 |
if (objnum < 1) |
| 3921 |
return; |
| 3922 |
|
| 3923 |
auto local_objnum = objnum_remote_to_local(objnum, obj_owner); // translate to local objnum |
| 3924 |
|
| 3925 |
if (local_objnum == object_none) |
| 3926 |
{ |
| 3927 |
return; |
| 3928 |
} |
| 3929 |
|
| 3930 |
const auto &&obj = vmobjptr(local_objnum); |
| 3931 |
if (obj->type != OBJ_POWERUP) |
| 3932 |
{ |
| 3933 |
return; |
| 3934 |
} |
| 3935 |
|
| 3936 |
if (Network_send_objects && multi::dispatch->objnum_is_past(local_objnum)) |
| 3937 |
{ |
| 3938 |
Network_send_objnum = -1; |
| 3939 |
} |
| 3940 |
|
| 3941 |
const auto ammo{GET_INTEL_SHORT(&buf[4])}; |
| 3942 |
obj->ctype.powerup_info.count = ammo; |
| 3943 |
} |
| 3944 |
|
| 3945 |
} |
| 3946 |
|
| 3947 |
#if DXX_BUILD_DESCENT == 2 |
| 3948 |
namespace { |
| 3949 |
|
| 3950 |
struct multi_guided_info |
| 3951 |
{ |
| 3952 |
uint8_t pnum; |
| 3953 |
uint8_t release; |
| 3954 |
shortpos sp; |
| 3955 |
}; |
| 3956 |
|
| 3957 |
DEFINE_MULTIPLAYER_SERIAL_MESSAGE(multiplayer_command_t::MULTI_GUIDED, multi_guided_info, g, (g.pnum, g.release, g.sp)); |
| 3958 |
|
| 3959 |
[[nodiscard]] |
| 3960 |
shortpos create_shortpos_little(const d_level_shared_segment_state &LevelSharedSegmentState, const object_base &objp) |
| 3961 |
{ |
| 3962 |
auto spp{create_shortpos_native(LevelSharedSegmentState, objp)}; |
| 3963 |
// swap the short values for the big-endian machines. |
| 3964 |
|
| 3965 |
if constexpr (words_bigendian) |
| 3966 |
{ |
| 3967 |
spp.xo = INTEL_SHORT(spp.xo); |
| 3968 |
spp.yo = INTEL_SHORT(spp.yo); |
| 3969 |
spp.zo = INTEL_SHORT(spp.zo); |
| 3970 |
spp.segment = segnum_t{INTEL_SHORT(underlying_value(spp.segment))}; |
| 3971 |
spp.velx = INTEL_SHORT(spp.velx); |
| 3972 |
spp.vely = INTEL_SHORT(spp.vely); |
| 3973 |
spp.velz = INTEL_SHORT(spp.velz); |
| 3974 |
} |
| 3975 |
return spp; |
| 3976 |
} |
| 3977 |
|
| 3978 |
} |
| 3979 |
|
| 3980 |
void multi_send_guided_info(const object_base &miss, const char done) |
| 3981 |
{ |
| 3982 |
multi_guided_info gi; |
| 3983 |
gi.pnum = static_cast<uint8_t>(Player_num); |
| 3984 |
gi.release = done; |
| 3985 |
gi.sp = create_shortpos_little(LevelSharedSegmentState, miss); |
| 3986 |
multi_serialize_write(multiplayer_data_priority::_0, gi); |
| 3987 |
} |
| 3988 |
|
| 3989 |
namespace { |
| 3990 |
|
| 3991 |
static void multi_do_guided(d_level_unique_object_state &LevelUniqueObjectState, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_GUIDED> buf) |
| 3992 |
{ |
| 3993 |
multi_guided_info b; |
| 3994 |
multi_serialize_read(buf, b); |
| 3995 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 3996 |
auto &vmobjptr = Objects.vmptr; |
| 3997 |
|
| 3998 |
if (b.release) |
| 3999 |
{ |
| 4000 |
release_remote_guided_missile(LevelUniqueObjectState, pnum); |
| 4001 |
return; |
| 4002 |
} |
| 4003 |
|
| 4004 |
const auto &&gimobj = LevelUniqueObjectState.Guided_missile.get_player_active_guided_missile(LevelUniqueObjectState.get_objects().vmptridx, pnum); |
| 4005 |
if (gimobj == nullptr) |
| 4006 |
return; |
| 4007 |
const vmobjptridx_t guided_missile = gimobj; |
| 4008 |
multi_object_warp_to_shortpos(guided_missile, b.sp); |
| 4009 |
update_object_seg(vmobjptr, LevelSharedSegmentState, LevelUniqueSegmentState, guided_missile); |
| 4010 |
} |
| 4011 |
|
| 4012 |
} |
| 4013 |
|
| 4014 |
void multi_send_stolen_items () |
| 4015 |
{ |
| 4016 |
multi_command<multiplayer_command_t::MULTI_STOLEN_ITEMS> multibuf; |
| 4017 |
auto &Stolen_items = LevelUniqueObjectState.ThiefState.Stolen_items; |
| 4018 |
std::transform(Stolen_items.begin(), Stolen_items.end(), std::next(multibuf.begin()), underlying_value<powerup_type_t>); |
| 4019 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4020 |
} |
| 4021 |
|
| 4022 |
namespace { |
| 4023 |
|
| 4024 |
static void multi_do_stolen_items(d_thief_unique_state &ThiefUniqueState, const multiplayer_rspan<multiplayer_command_t::MULTI_STOLEN_ITEMS> buf) |
| 4025 |
{ |
| 4026 |
for (auto &&[untrusted_network_powerup_value, local_stolen_item] : zip(buf.subspan<1>(), ThiefUniqueState.Stolen_items)) |
| 4027 |
{ |
| 4028 |
local_stolen_item = (untrusted_network_powerup_value < MAX_POWERUP_TYPES) ? powerup_type_t{untrusted_network_powerup_value} : ThiefUniqueState.stolen_item_type_none; |
| 4029 |
} |
| 4030 |
} |
| 4031 |
|
| 4032 |
} |
| 4033 |
|
| 4034 |
void multi_send_wall_status_specific(const playernum_t pnum, wallnum_t wallnum, uint8_t type, const wall_flags flags, const wall_state state) |
| 4035 |
{ |
| 4036 |
// Send wall states a specific rejoining player |
| 4037 |
|
| 4038 |
int count{0}; |
| 4039 |
|
| 4040 |
Assert (Game_mode & GM_NETWORK); |
| 4041 |
//Assert (pnum>-1 && pnum<N_players); |
| 4042 |
|
| 4043 |
count++; |
| 4044 |
multi_command<multiplayer_command_t::MULTI_WALL_STATUS> multibuf; |
| 4045 |
PUT_INTEL_SHORT(&multibuf[count], static_cast<uint16_t>(wallnum)); |
| 4046 |
count+=2; |
| 4047 |
multibuf[count]=type; count++; |
| 4048 |
multibuf[count] = underlying_value(flags); count++; |
| 4049 |
multibuf[count] = underlying_value(state); count++; |
| 4050 |
|
| 4051 |
multi_send_data_direct(multibuf, pnum, 2); |
| 4052 |
} |
| 4053 |
|
| 4054 |
namespace { |
| 4055 |
|
| 4056 |
static void multi_do_wall_status(fvmwallptr &vmwallptr, const multiplayer_rspan<multiplayer_command_t::MULTI_WALL_STATUS> buf) |
| 4057 |
{ |
| 4058 |
ubyte flag,type,state; |
| 4059 |
|
| 4060 |
const wallnum_t wallnum{GET_INTEL_SHORT(&buf[1])}; |
| 4061 |
type=buf[3]; |
| 4062 |
flag=buf[4]; |
| 4063 |
state=buf[5]; |
| 4064 |
|
| 4065 |
auto &w = *vmwallptr(wallnum); |
| 4066 |
w.type = type; |
| 4067 |
w.flags = wall_flags{flag}; |
| 4068 |
w.state = wall_state{state}; |
| 4069 |
|
| 4070 |
if (w.type == WALL_OPEN) |
| 4071 |
digi_kill_sound_linked_to_segment(w.segnum, w.sidenum, sound_effect::SOUND_FORCEFIELD_HUM); |
| 4072 |
} |
| 4073 |
|
| 4074 |
} |
| 4075 |
#endif |
| 4076 |
|
| 4077 |
} |
| 4078 |
|
| 4079 |
void multi_send_kill_goal_counts() |
| 4080 |
{ |
| 4081 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4082 |
auto &vcobjptr = Objects.vcptr; |
| 4083 |
int count{1}; |
| 4084 |
|
| 4085 |
multi_command<multiplayer_command_t::MULTI_KILLGOALS> multibuf; |
| 4086 |
range_for (auto &i, Players) |
| 4087 |
{ |
| 4088 |
auto &obj = *vcobjptr(i.objnum); |
| 4089 |
auto &player_info = obj.ctype.player_info; |
| 4090 |
multibuf[count] = player_info.KillGoalCount; |
| 4091 |
count++; |
| 4092 |
} |
| 4093 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4094 |
} |
| 4095 |
|
| 4096 |
namespace { |
| 4097 |
|
| 4098 |
static void multi_do_kill_goal_counts(fvmobjptr &vmobjptr, const multiplayer_rspan<multiplayer_command_t::MULTI_KILLGOALS> buf) |
| 4099 |
{ |
| 4100 |
int count{1}; |
| 4101 |
|
| 4102 |
range_for (auto &i, Players) |
| 4103 |
{ |
| 4104 |
auto &obj = *vmobjptr(i.objnum); |
| 4105 |
auto &player_info = obj.ctype.player_info; |
| 4106 |
player_info.KillGoalCount = buf[count]; |
| 4107 |
count++; |
| 4108 |
} |
| 4109 |
} |
| 4110 |
|
| 4111 |
void multi_send_heartbeat () |
| 4112 |
{ |
| 4113 |
if (!Netgame.PlayTimeAllowed.count()) |
| 4114 |
return; |
| 4115 |
|
| 4116 |
multi_command<multiplayer_command_t::MULTI_HEARTBEAT> multibuf; |
| 4117 |
PUT_INTEL_INT(&multibuf[1], ThisLevelTime.count()); |
| 4118 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 4119 |
} |
| 4120 |
|
| 4121 |
static void multi_do_heartbeat(const multiplayer_rspan<multiplayer_command_t::MULTI_HEARTBEAT> buf) |
| 4122 |
{ |
| 4123 |
const fix num{GET_INTEL_INT<int32_t>(&buf[1])}; |
| 4124 |
ThisLevelTime = d_time_fix(num); |
| 4125 |
} |
| 4126 |
|
| 4127 |
} |
| 4128 |
|
| 4129 |
namespace dsx { |
| 4130 |
|
| 4131 |
void multi_check_for_killgoal_winner(const d_robot_info_array &Robot_info) |
| 4132 |
{ |
| 4133 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 4134 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4135 |
auto &vcobjptr = Objects.vcptr; |
| 4136 |
if (LevelUniqueControlCenterState.Control_center_destroyed) |
| 4137 |
return; |
| 4138 |
|
| 4139 |
/* For historical compatibility, this routine has some quirks with |
| 4140 |
* scoring: |
| 4141 |
* - When two or more players have the same number of kills, this |
| 4142 |
* routine always chooses the lowest index player. No opportunity |
| 4143 |
* is provided for the players to score a tie-breaking kill, nor |
| 4144 |
* is any other property (such as remaining shields) considered. |
| 4145 |
* Historical versions had additional quirks relating to |
| 4146 |
* zero/negative kills, but those quirks have been removed. |
| 4147 |
*/ |
| 4148 |
const auto &local_player = get_local_player(); |
| 4149 |
const player *bestplr = nullptr; |
| 4150 |
int highest_kill_goal_count{0}; |
| 4151 |
range_for (auto &i, partial_const_range(Players, N_players)) |
| 4152 |
{ |
| 4153 |
auto &obj = *vcobjptr(i.objnum); |
| 4154 |
auto &player_info = obj.ctype.player_info; |
| 4155 |
const auto KillGoalCount = player_info.KillGoalCount; |
| 4156 |
if (highest_kill_goal_count < KillGoalCount) |
| 4157 |
{ |
| 4158 |
highest_kill_goal_count = KillGoalCount; |
| 4159 |
bestplr = &i; |
| 4160 |
} |
| 4161 |
} |
| 4162 |
if (!bestplr) |
| 4163 |
{ |
| 4164 |
/* No player has at least one kill */ |
| 4165 |
HUD_init_message_literal(HM_MULTI, "No one has scored any kills!"); |
| 4166 |
} |
| 4167 |
else if (bestplr == &local_player) |
| 4168 |
{ |
| 4169 |
HUD_init_message(HM_MULTI, "You have the best score at %d kills!", highest_kill_goal_count); |
| 4170 |
} |
| 4171 |
else |
| 4172 |
HUD_init_message(HM_MULTI, "%s has the best score with %d kills!", static_cast<const char *>(bestplr->callsign), highest_kill_goal_count); |
| 4173 |
net_destroy_controlcen(Objects, Robot_info); |
| 4174 |
} |
| 4175 |
|
| 4176 |
#if DXX_BUILD_DESCENT == 2 |
| 4177 |
// Sync our seismic time with other players |
| 4178 |
void multi_send_seismic(fix duration) |
| 4179 |
{ |
| 4180 |
int count{1}; |
| 4181 |
multi_command<multiplayer_command_t::MULTI_SEISMIC> multibuf; |
| 4182 |
PUT_INTEL_INT(&multibuf[count], duration); count += sizeof(duration); |
| 4183 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4184 |
} |
| 4185 |
|
| 4186 |
namespace { |
| 4187 |
|
| 4188 |
static void multi_do_seismic(multiplayer_rspan<multiplayer_command_t::MULTI_SEISMIC> buf) |
| 4189 |
{ |
| 4190 |
const fix duration{GET_INTEL_INT<int32_t>(&buf[1])}; |
| 4191 |
LevelUniqueSeismicState.Seismic_disturbance_end_time = GameTime64 + duration; |
| 4192 |
digi_play_sample (sound_effect::SOUND_SEISMIC_DISTURBANCE_START, F1_0); |
| 4193 |
} |
| 4194 |
|
| 4195 |
} |
| 4196 |
|
| 4197 |
void multi_send_light_specific (const playernum_t pnum, const vcsegptridx_t segnum, const sidemask_t val) |
| 4198 |
{ |
| 4199 |
int count{1}; |
| 4200 |
|
| 4201 |
Assert (Game_mode & GM_NETWORK); |
| 4202 |
// Assert (pnum>-1 && pnum<N_players); |
| 4203 |
|
| 4204 |
multi_command<multiplayer_command_t::MULTI_LIGHT> multibuf; |
| 4205 |
PUT_INTEL_SEGNUM(&multibuf[count], segnum); |
| 4206 |
count += sizeof(uint16_t); |
| 4207 |
multibuf[count] = underlying_value(val); count++; |
| 4208 |
|
| 4209 |
range_for (auto &i, segnum->unique_segment::sides) |
| 4210 |
{ |
| 4211 |
PUT_INTEL_SHORT(&multibuf[count], static_cast<uint16_t>(i.tmap_num2)); |
| 4212 |
count+=2; |
| 4213 |
} |
| 4214 |
multi_send_data_direct(multibuf, pnum, 2); |
| 4215 |
} |
| 4216 |
|
| 4217 |
namespace { |
| 4218 |
|
| 4219 |
static void multi_do_light(const multiplayer_rspan<multiplayer_command_t::MULTI_LIGHT> buf) |
| 4220 |
{ |
| 4221 |
const auto sides = buf[3]; |
| 4222 |
|
| 4223 |
const auto &&usegp = vmsegptridx.check_untrusted(segnum_t{GET_INTEL_SHORT(&buf[1])}); |
| 4224 |
if (!usegp) |
| 4225 |
return; |
| 4226 |
const auto &&segp = *usegp; |
| 4227 |
auto &side_array = segp->unique_segment::sides; |
| 4228 |
for (const auto i : MAX_SIDES_PER_SEGMENT) |
| 4229 |
{ |
| 4230 |
if (sides & underlying_value(build_sidemask(i))) |
| 4231 |
{ |
| 4232 |
auto &LevelSharedDestructibleLightState = LevelSharedSegmentState.DestructibleLights; |
| 4233 |
subtract_light(LevelSharedDestructibleLightState, segp, i); |
| 4234 |
const auto tmap_num2 = texture2_value{GET_INTEL_SHORT(&buf[4 + (2 * underlying_value(i))])}; |
| 4235 |
if (get_texture_index(tmap_num2) >= Textures.size()) |
| 4236 |
continue; |
| 4237 |
side_array[i].tmap_num2 = tmap_num2; |
| 4238 |
} |
| 4239 |
} |
| 4240 |
} |
| 4241 |
|
| 4242 |
static void multi_do_flags(fvmobjptr &vmobjptr, const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_FLAGS> buf) |
| 4243 |
{ |
| 4244 |
if (pnum!=Player_num) |
| 4245 |
{ |
| 4246 |
const auto flags{GET_INTEL_INT(&buf[2])}; |
| 4247 |
vmobjptr(vcplayerptr(pnum)->objnum)->ctype.player_info.powerup_flags = player_flags(flags); |
| 4248 |
} |
| 4249 |
} |
| 4250 |
|
| 4251 |
} |
| 4252 |
|
| 4253 |
void multi_send_flags (const playernum_t pnum) |
| 4254 |
{ |
| 4255 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4256 |
auto &vmobjptr = Objects.vmptr; |
| 4257 |
multi_command<multiplayer_command_t::MULTI_FLAGS> multibuf; |
| 4258 |
multibuf[1]=pnum; |
| 4259 |
PUT_INTEL_INT(&multibuf[2], vmobjptr(vcplayerptr(pnum)->objnum)->ctype.player_info.powerup_flags.get_player_flags()); |
| 4260 |
|
| 4261 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4262 |
} |
| 4263 |
|
| 4264 |
void multi_send_drop_blobs (const playernum_t pnum) |
| 4265 |
{ |
| 4266 |
multi_command<multiplayer_command_t::MULTI_DROP_BLOB> multibuf; |
| 4267 |
multibuf[1]=pnum; |
| 4268 |
|
| 4269 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 4270 |
} |
| 4271 |
|
| 4272 |
namespace { |
| 4273 |
|
| 4274 |
static void multi_do_drop_blob(fvmobjptr &vmobjptr, const playernum_t pnum) |
| 4275 |
{ |
| 4276 |
drop_afterburner_blobs (vmobjptr(vcplayerptr(pnum)->objnum), 2, i2f(5) / 2, -1); |
| 4277 |
} |
| 4278 |
|
| 4279 |
} |
| 4280 |
|
| 4281 |
void multi_send_sound_function (char whichfunc, char sound) |
| 4282 |
{ |
| 4283 |
multi_command<multiplayer_command_t::MULTI_SOUND_FUNCTION> multibuf; |
| 4284 |
multibuf[1]=Player_num; |
| 4285 |
multibuf[2]=whichfunc; |
| 4286 |
multibuf[3] = sound; // this would probably work on the PC as well. Jason? |
| 4287 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4288 |
} |
| 4289 |
|
| 4290 |
#define AFTERBURNER_LOOP_START 20098 |
| 4291 |
#define AFTERBURNER_LOOP_END 25776 |
| 4292 |
|
| 4293 |
namespace { |
| 4294 |
|
| 4295 |
static void multi_do_sound_function(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_SOUND_FUNCTION> buf) |
| 4296 |
{ |
| 4297 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4298 |
auto &vcobjptridx = Objects.vcptridx; |
| 4299 |
// for afterburner |
| 4300 |
|
| 4301 |
if (get_local_player().connected != player_connection_status::playing) |
| 4302 |
return; |
| 4303 |
|
| 4304 |
const auto plobj = vcobjptridx(vcplayerptr(pnum)->objnum); |
| 4305 |
const auto whichfunc = buf[2]; |
| 4306 |
if (whichfunc==0) |
| 4307 |
digi_kill_sound_linked_to_object(plobj); |
| 4308 |
else if (whichfunc==3) |
| 4309 |
{ |
| 4310 |
const uint8_t sound{buf[3]}; |
| 4311 |
digi_link_sound_to_object3(static_cast<sound_effect>(sound), plobj, 1, F1_0, sound_stack::allow_stacking, vm_distance{i2f(256)}, AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END); |
| 4312 |
} |
| 4313 |
} |
| 4314 |
|
| 4315 |
} |
| 4316 |
|
| 4317 |
void multi_send_capture_bonus (const playernum_t pnum) |
| 4318 |
{ |
| 4319 |
multi_command<multiplayer_command_t::MULTI_CAPTURE_BONUS> multibuf; |
| 4320 |
assert(game_mode_capture_flag(Game_mode)); |
| 4321 |
|
| 4322 |
multibuf[1]=pnum; |
| 4323 |
|
| 4324 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4325 |
multi_do_capture_bonus (pnum); |
| 4326 |
} |
| 4327 |
|
| 4328 |
void multi_send_orb_bonus (const playernum_t pnum, const uint8_t hoard_orbs) |
| 4329 |
{ |
| 4330 |
multi_command<multiplayer_command_t::MULTI_ORB_BONUS> multibuf; |
| 4331 |
assert(game_mode_hoard(Game_mode)); |
| 4332 |
|
| 4333 |
multibuf[1]=pnum; |
| 4334 |
multibuf[2] = hoard_orbs; |
| 4335 |
|
| 4336 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4337 |
multi_do_orb_bonus(pnum, multibuf); |
| 4338 |
} |
| 4339 |
|
| 4340 |
namespace { |
| 4341 |
|
| 4342 |
void multi_do_capture_bonus(const playernum_t pnum) |
| 4343 |
{ |
| 4344 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4345 |
auto &vmobjptr = Objects.vmptr; |
| 4346 |
// Figure out the results of a network kills and add it to the |
| 4347 |
// appropriate player's tally. |
| 4348 |
|
| 4349 |
int TheGoal; |
| 4350 |
|
| 4351 |
if (pnum==Player_num) |
| 4352 |
HUD_init_message_literal(HM_MULTI, "You have Scored!"); |
| 4353 |
else |
| 4354 |
HUD_init_message(HM_MULTI, "%s has Scored!", static_cast<const char *>(vcplayerptr(pnum)->callsign)); |
| 4355 |
|
| 4356 |
digi_play_sample(pnum == Player_num |
| 4357 |
? sound_effect::SOUND_HUD_YOU_GOT_GOAL |
| 4358 |
: (multi_get_team_from_player(Netgame, pnum) == team_number::blue |
| 4359 |
? sound_effect::SOUND_HUD_BLUE_GOT_GOAL |
| 4360 |
: sound_effect::SOUND_HUD_RED_GOT_GOAL |
| 4361 |
), F1_0*2); |
| 4362 |
|
| 4363 |
|
| 4364 |
team_kills[multi_get_team_from_player(Netgame, pnum)] += 5; |
| 4365 |
auto &plr = *vcplayerptr(pnum); |
| 4366 |
auto &player_info = vmobjptr(plr.objnum)->ctype.player_info; |
| 4367 |
player_info.powerup_flags &= ~PLAYER_FLAGS_FLAG; // Clear capture flag |
| 4368 |
player_info.net_kills_total += 5; |
| 4369 |
player_info.KillGoalCount += 5; |
| 4370 |
|
| 4371 |
if (Netgame.KillGoal>0) |
| 4372 |
{ |
| 4373 |
TheGoal=Netgame.KillGoal*5; |
| 4374 |
|
| 4375 |
if (player_info.KillGoalCount >= TheGoal) |
| 4376 |
{ |
| 4377 |
if (pnum==Player_num) |
| 4378 |
{ |
| 4379 |
HUD_init_message_literal(HM_MULTI, "You reached the kill goal!"); |
| 4380 |
get_local_plrobj().shields = i2f(200); |
| 4381 |
} |
| 4382 |
else |
| 4383 |
HUD_init_message(HM_MULTI, "%s has reached the kill goal!",static_cast<const char *>(vcplayerptr(pnum)->callsign)); |
| 4384 |
net_destroy_controlcen(Objects, LevelSharedRobotInfoState.Robot_info); |
| 4385 |
} |
| 4386 |
} |
| 4387 |
|
| 4388 |
multi_sort_kill_list(); |
| 4389 |
multi_show_player_list(); |
| 4390 |
} |
| 4391 |
|
| 4392 |
static int GetOrbBonus (char num) |
| 4393 |
{ |
| 4394 |
int bonus; |
| 4395 |
|
| 4396 |
bonus=num*(num+1)/2; |
| 4397 |
return (bonus); |
| 4398 |
} |
| 4399 |
|
| 4400 |
void multi_do_orb_bonus(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_ORB_BONUS> buf) |
| 4401 |
{ |
| 4402 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4403 |
auto &vmobjptr = Objects.vmptr; |
| 4404 |
// Figure out the results of a network kills and add it to the |
| 4405 |
// appropriate player's tally. |
| 4406 |
|
| 4407 |
int TheGoal; |
| 4408 |
int bonus=GetOrbBonus (buf[2]); |
| 4409 |
|
| 4410 |
if (pnum==Player_num) |
| 4411 |
HUD_init_message(HM_MULTI, "You have scored %d points!",bonus); |
| 4412 |
else |
| 4413 |
HUD_init_message(HM_MULTI, "%s has scored with %d orbs!",static_cast<const char *>(vcplayerptr(pnum)->callsign), buf[2]); |
| 4414 |
|
| 4415 |
if (pnum==Player_num) |
| 4416 |
digi_start_sound_queued (sound_effect::SOUND_HUD_YOU_GOT_GOAL,F1_0*2); |
| 4417 |
else |
| 4418 |
digi_play_sample((Game_mode & GM_TEAM) |
| 4419 |
? (multi_get_team_from_player(Netgame, pnum) == team_number::blue |
| 4420 |
? sound_effect::SOUND_HUD_BLUE_GOT_GOAL |
| 4421 |
: sound_effect::SOUND_HUD_RED_GOT_GOAL |
| 4422 |
) : sound_effect::SOUND_OPPONENT_HAS_SCORED, F1_0*2); |
| 4423 |
|
| 4424 |
if (bonus > hoard_highest_record_stats.points) |
| 4425 |
{ |
| 4426 |
hoard_highest_record_stats.player = pnum; |
| 4427 |
hoard_highest_record_stats.points = bonus; |
| 4428 |
if (pnum==Player_num) |
| 4429 |
HUD_init_message(HM_MULTI, "You have the record with %d points!",bonus); |
| 4430 |
else |
| 4431 |
HUD_init_message(HM_MULTI, "%s has the record with %d points!",static_cast<const char *>(vcplayerptr(pnum)->callsign),bonus); |
| 4432 |
digi_play_sample (sound_effect::SOUND_BUDDY_MET_GOAL,F1_0*2); |
| 4433 |
} |
| 4434 |
|
| 4435 |
|
| 4436 |
team_kills[multi_get_team_from_player(Netgame, pnum)] += bonus; |
| 4437 |
auto &plr = *vcplayerptr(pnum); |
| 4438 |
auto &player_info = vmobjptr(plr.objnum)->ctype.player_info; |
| 4439 |
player_info.powerup_flags &= ~PLAYER_FLAGS_FLAG; // Clear orb flag |
| 4440 |
player_info.net_kills_total += bonus; |
| 4441 |
player_info.KillGoalCount += bonus; |
| 4442 |
|
| 4443 |
team_kills[multi_get_team_from_player(Netgame, pnum)]%=1000; |
| 4444 |
player_info.net_kills_total%=1000; |
| 4445 |
player_info.KillGoalCount %= 1000; |
| 4446 |
|
| 4447 |
if (Netgame.KillGoal>0) |
| 4448 |
{ |
| 4449 |
TheGoal=Netgame.KillGoal*5; |
| 4450 |
|
| 4451 |
if (player_info.KillGoalCount >= TheGoal) |
| 4452 |
{ |
| 4453 |
if (pnum==Player_num) |
| 4454 |
{ |
| 4455 |
HUD_init_message_literal(HM_MULTI, "You reached the kill goal!"); |
| 4456 |
get_local_plrobj().shields = i2f(200); |
| 4457 |
} |
| 4458 |
else |
| 4459 |
HUD_init_message(HM_MULTI, "%s has reached the kill goal!",static_cast<const char *>(vcplayerptr(pnum)->callsign)); |
| 4460 |
net_destroy_controlcen(Objects, LevelSharedRobotInfoState.Robot_info); |
| 4461 |
} |
| 4462 |
} |
| 4463 |
multi_sort_kill_list(); |
| 4464 |
multi_show_player_list(); |
| 4465 |
} |
| 4466 |
|
| 4467 |
} |
| 4468 |
|
| 4469 |
void multi_send_got_flag (const playernum_t pnum) |
| 4470 |
{ |
| 4471 |
multi_command<multiplayer_command_t::MULTI_GOT_FLAG> multibuf; |
| 4472 |
multibuf[1]=pnum; |
| 4473 |
|
| 4474 |
digi_start_sound_queued (sound_effect::SOUND_HUD_YOU_GOT_FLAG,F1_0*2); |
| 4475 |
|
| 4476 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4477 |
multi_send_flags (Player_num); |
| 4478 |
} |
| 4479 |
|
| 4480 |
void multi_send_got_orb (const playernum_t pnum) |
| 4481 |
{ |
| 4482 |
multi_command<multiplayer_command_t::MULTI_GOT_ORB> multibuf; |
| 4483 |
multibuf[1]=pnum; |
| 4484 |
|
| 4485 |
digi_play_sample (sound_effect::SOUND_YOU_GOT_ORB,F1_0*2); |
| 4486 |
|
| 4487 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4488 |
multi_send_flags (Player_num); |
| 4489 |
} |
| 4490 |
|
| 4491 |
namespace { |
| 4492 |
|
| 4493 |
static void multi_do_got_flag (const playernum_t pnum) |
| 4494 |
{ |
| 4495 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4496 |
auto &vmobjptr = Objects.vmptr; |
| 4497 |
digi_start_sound_queued(pnum == Player_num |
| 4498 |
? sound_effect::SOUND_HUD_YOU_GOT_FLAG |
| 4499 |
: (multi_get_team_from_player(Netgame, pnum) == team_number::blue |
| 4500 |
? sound_effect::SOUND_HUD_BLUE_GOT_FLAG |
| 4501 |
: sound_effect::SOUND_HUD_RED_GOT_FLAG |
| 4502 |
), F1_0*2); |
| 4503 |
vmobjptr(vcplayerptr(pnum)->objnum)->ctype.player_info.powerup_flags |= PLAYER_FLAGS_FLAG; |
| 4504 |
HUD_init_message(HM_MULTI, "%s picked up a flag!",static_cast<const char *>(vcplayerptr(pnum)->callsign)); |
| 4505 |
} |
| 4506 |
|
| 4507 |
static void multi_do_got_orb (const playernum_t pnum) |
| 4508 |
{ |
| 4509 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4510 |
auto &vmobjptr = Objects.vmptr; |
| 4511 |
assert(game_mode_hoard(Game_mode)); |
| 4512 |
|
| 4513 |
digi_play_sample((Game_mode & GM_TEAM) && multi_get_team_from_player(Netgame, pnum) == multi_get_team_from_player(Netgame, Player_num) |
| 4514 |
? sound_effect::SOUND_FRIEND_GOT_ORB |
| 4515 |
: sound_effect::SOUND_OPPONENT_GOT_ORB, F1_0*2); |
| 4516 |
|
| 4517 |
const auto &&objp = vmobjptr(vcplayerptr(pnum)->objnum); |
| 4518 |
objp->ctype.player_info.powerup_flags |= PLAYER_FLAGS_FLAG; |
| 4519 |
HUD_init_message(HM_MULTI, "%s picked up an orb!",static_cast<const char *>(vcplayerptr(pnum)->callsign)); |
| 4520 |
} |
| 4521 |
|
| 4522 |
static void DropOrb () |
| 4523 |
{ |
| 4524 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4525 |
auto &vmobjptr = Objects.vmptr; |
| 4526 |
int seed; |
| 4527 |
|
| 4528 |
if (!game_mode_hoard(Game_mode)) |
| 4529 |
Int3(); // How did we get here? Get Leighton! |
| 4530 |
|
| 4531 |
auto &player_info = get_local_plrobj().ctype.player_info; |
| 4532 |
auto &proximity = player_info.hoard.orbs; |
| 4533 |
if (!proximity) |
| 4534 |
{ |
| 4535 |
HUD_init_message_literal(HM_MULTI, "No orbs to drop!"); |
| 4536 |
return; |
| 4537 |
} |
| 4538 |
|
| 4539 |
seed = d_rand(); |
| 4540 |
|
| 4541 |
const auto &&objnum = spit_powerup(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, Vclip, *ConsoleObject, powerup_type_t::POW_HOARD_ORB, seed); |
| 4542 |
if (objnum == object_none) |
| 4543 |
{ |
| 4544 |
HUD_init_message_literal(HM_MULTI, "Failed to drop orb!"); |
| 4545 |
return; |
| 4546 |
} |
| 4547 |
|
| 4548 |
HUD_init_message_literal(HM_MULTI, "Orb dropped!"); |
| 4549 |
digi_play_sample (sound_effect::SOUND_DROP_WEAPON,F1_0); |
| 4550 |
|
| 4551 |
multi_send_drop_flag(objnum, seed); |
| 4552 |
-- proximity; |
| 4553 |
|
| 4554 |
// If empty, tell everyone to stop drawing the box around me |
| 4555 |
if (!proximity) |
| 4556 |
{ |
| 4557 |
player_info.powerup_flags &=~(PLAYER_FLAGS_FLAG); |
| 4558 |
multi_send_flags (Player_num); |
| 4559 |
} |
| 4560 |
} |
| 4561 |
|
| 4562 |
} |
| 4563 |
|
| 4564 |
void DropFlag () |
| 4565 |
{ |
| 4566 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4567 |
auto &vmobjptr = Objects.vmptr; |
| 4568 |
int seed; |
| 4569 |
|
| 4570 |
if (game_mode_hoard(Game_mode)) |
| 4571 |
{ |
| 4572 |
DropOrb(); |
| 4573 |
return; |
| 4574 |
} |
| 4575 |
else if (!game_mode_capture_flag(Game_mode)) |
| 4576 |
return; |
| 4577 |
|
| 4578 |
auto &player_info = get_local_plrobj().ctype.player_info; |
| 4579 |
if (!(player_info.powerup_flags & PLAYER_FLAGS_FLAG)) |
| 4580 |
{ |
| 4581 |
HUD_init_message_literal(HM_MULTI, "No flag to drop!"); |
| 4582 |
return; |
| 4583 |
} |
| 4584 |
seed = d_rand(); |
| 4585 |
const auto &&objnum = spit_powerup(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, Vclip, *ConsoleObject, multi_get_team_from_player(Netgame, Player_num) == team_number::blue ? powerup_type_t::POW_FLAG_RED : powerup_type_t::POW_FLAG_BLUE, seed); |
| 4586 |
if (objnum == object_none) |
| 4587 |
{ |
| 4588 |
HUD_init_message_literal(HM_MULTI, "Failed to drop flag!"); |
| 4589 |
return; |
| 4590 |
} |
| 4591 |
|
| 4592 |
HUD_init_message_literal(HM_MULTI, "Flag dropped!"); |
| 4593 |
digi_play_sample (sound_effect::SOUND_DROP_WEAPON,F1_0); |
| 4594 |
|
| 4595 |
if (game_mode_capture_flag(Game_mode)) |
| 4596 |
multi_send_drop_flag(objnum,seed); |
| 4597 |
|
| 4598 |
player_info.powerup_flags &=~(PLAYER_FLAGS_FLAG); |
| 4599 |
} |
| 4600 |
|
| 4601 |
namespace { |
| 4602 |
|
| 4603 |
void multi_send_drop_flag(const vmobjptridx_t objp, int seed) |
| 4604 |
{ |
| 4605 |
multi_command<multiplayer_command_t::MULTI_DROP_FLAG> multibuf; |
| 4606 |
int count{0}; |
| 4607 |
count++; |
| 4608 |
multibuf[count++]=static_cast<char>(get_powerup_id(objp)); |
| 4609 |
|
| 4610 |
PUT_INTEL_SHORT(&multibuf[count], objp.get_unchecked_index()); |
| 4611 |
count += 2; |
| 4612 |
PUT_INTEL_INT(&multibuf[count], seed); |
| 4613 |
|
| 4614 |
map_objnum_local_to_local(objp); |
| 4615 |
|
| 4616 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4617 |
} |
| 4618 |
|
| 4619 |
static void multi_do_drop_flag(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_DROP_FLAG> buf) |
| 4620 |
{ |
| 4621 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 4622 |
auto &vmobjptr = Objects.vmptr; |
| 4623 |
const auto powerup_id = static_cast<powerup_type_t>(buf[1]); |
| 4624 |
const objnum_t remote_objnum{GET_INTEL_SHORT(&buf[2])}; |
| 4625 |
const auto seed{GET_INTEL_INT<int32_t>(&buf[6])}; |
| 4626 |
|
| 4627 |
auto &plrobj{*vmobjptr(vcplayerptr(pnum)->objnum)}; |
| 4628 |
|
| 4629 |
const imobjidx_t objnum{spit_powerup(LevelUniqueObjectState, LevelSharedSegmentState, LevelUniqueSegmentState, Vclip, plrobj, powerup_id, seed)}; |
| 4630 |
if (objnum == object_none) |
| 4631 |
return; |
| 4632 |
|
| 4633 |
map_objnum_local_to_remote(objnum, remote_objnum, pnum); |
| 4634 |
if (!game_mode_hoard(Game_mode)) |
| 4635 |
plrobj.ctype.player_info.powerup_flags &= ~(PLAYER_FLAGS_FLAG); |
| 4636 |
} |
| 4637 |
|
| 4638 |
} |
| 4639 |
#endif |
| 4640 |
|
| 4641 |
netflag_flag multi_powerup_is_allowed(const powerup_type_t id, const netflag_flag AllowedItems) |
| 4642 |
{ |
| 4643 |
return multi_powerup_is_allowed(id, AllowedItems, map_granted_flags_to_netflag(Netgame.SpawnGrantedItems)); |
| 4644 |
} |
| 4645 |
|
| 4646 |
netflag_flag multi_powerup_is_allowed(const powerup_type_t id, const netflag_flag BaseAllowedItems, const netflag_flag SpawnGrantedItems) |
| 4647 |
{ |
| 4648 |
const auto AllowedItems = BaseAllowedItems & ~SpawnGrantedItems; |
| 4649 |
switch (id) |
| 4650 |
{ |
| 4651 |
case powerup_type_t::POW_KEY_BLUE: |
| 4652 |
case powerup_type_t::POW_KEY_GOLD: |
| 4653 |
case powerup_type_t::POW_KEY_RED: |
| 4654 |
/* Callers only test whether the result is netflag_flag::None or |
| 4655 |
* not, and do not expect a specific value. */ |
| 4656 |
return static_cast<netflag_flag>(Game_mode & GM_MULTI_COOP); |
| 4657 |
case powerup_type_t::POW_INVULNERABILITY: |
| 4658 |
return AllowedItems & netflag_flag::NETFLAG_DOINVUL; |
| 4659 |
case powerup_type_t::POW_CLOAK: |
| 4660 |
return AllowedItems & netflag_flag::NETFLAG_DOCLOAK; |
| 4661 |
case powerup_type_t::POW_LASER: |
| 4662 |
if (map_granted_flags_to_laser_level(Netgame.SpawnGrantedItems) >= MAX_LASER_LEVEL) |
| 4663 |
/* If players are granted maximum level lasers, then disallow |
| 4664 |
* placing laser powerups. |
| 4665 |
*/ |
| 4666 |
return netflag_flag::None; |
| 4667 |
return AllowedItems & netflag_flag::NETFLAG_DOLASER; |
| 4668 |
case powerup_type_t::POW_QUAD_FIRE: |
| 4669 |
return AllowedItems & netflag_flag::NETFLAG_DOQUAD; |
| 4670 |
case powerup_type_t::POW_VULCAN_WEAPON: |
| 4671 |
return AllowedItems & netflag_flag::NETFLAG_DOVULCAN; |
| 4672 |
case powerup_type_t::POW_SPREADFIRE_WEAPON: |
| 4673 |
return AllowedItems & netflag_flag::NETFLAG_DOSPREAD; |
| 4674 |
case powerup_type_t::POW_PLASMA_WEAPON: |
| 4675 |
return AllowedItems & netflag_flag::NETFLAG_DOPLASMA; |
| 4676 |
case powerup_type_t::POW_FUSION_WEAPON: |
| 4677 |
return AllowedItems & netflag_flag::NETFLAG_DOFUSION; |
| 4678 |
case powerup_type_t::POW_HOMING_AMMO_1: |
| 4679 |
case powerup_type_t::POW_HOMING_AMMO_4: |
| 4680 |
return AllowedItems & netflag_flag::NETFLAG_DOHOMING; |
| 4681 |
case powerup_type_t::POW_PROXIMITY_WEAPON: |
| 4682 |
return AllowedItems & netflag_flag::NETFLAG_DOPROXIM; |
| 4683 |
case powerup_type_t::POW_SMARTBOMB_WEAPON: |
| 4684 |
return AllowedItems & netflag_flag::NETFLAG_DOSMART; |
| 4685 |
case powerup_type_t::POW_MEGA_WEAPON: |
| 4686 |
return AllowedItems & netflag_flag::NETFLAG_DOMEGA; |
| 4687 |
case powerup_type_t::POW_VULCAN_AMMO: |
| 4688 |
#if DXX_BUILD_DESCENT == 1 |
| 4689 |
return BaseAllowedItems & netflag_flag::NETFLAG_DOVULCAN; |
| 4690 |
#elif DXX_BUILD_DESCENT == 2 |
| 4691 |
return BaseAllowedItems & (netflag_flag::NETFLAG_DOVULCAN | netflag_flag::NETFLAG_DOGAUSS); |
| 4692 |
#endif |
| 4693 |
#if DXX_BUILD_DESCENT == 2 |
| 4694 |
case powerup_type_t::POW_SUPER_LASER: |
| 4695 |
if (map_granted_flags_to_laser_level(Netgame.SpawnGrantedItems) >= MAX_SUPER_LASER_LEVEL) |
| 4696 |
/* If players are granted maximum level super lasers, then |
| 4697 |
* disallow placing super laser powerups. |
| 4698 |
*/ |
| 4699 |
return netflag_flag::None; |
| 4700 |
return AllowedItems & netflag_flag::NETFLAG_DOSUPERLASER; |
| 4701 |
case powerup_type_t::POW_GAUSS_WEAPON: |
| 4702 |
return AllowedItems & netflag_flag::NETFLAG_DOGAUSS; |
| 4703 |
case powerup_type_t::POW_HELIX_WEAPON: |
| 4704 |
return AllowedItems & netflag_flag::NETFLAG_DOHELIX; |
| 4705 |
case powerup_type_t::POW_PHOENIX_WEAPON: |
| 4706 |
return AllowedItems & netflag_flag::NETFLAG_DOPHOENIX; |
| 4707 |
case powerup_type_t::POW_OMEGA_WEAPON: |
| 4708 |
return AllowedItems & netflag_flag::NETFLAG_DOOMEGA; |
| 4709 |
case powerup_type_t::POW_SMISSILE1_1: |
| 4710 |
case powerup_type_t::POW_SMISSILE1_4: |
| 4711 |
return AllowedItems & netflag_flag::NETFLAG_DOFLASH; |
| 4712 |
case powerup_type_t::POW_GUIDED_MISSILE_1: |
| 4713 |
case powerup_type_t::POW_GUIDED_MISSILE_4: |
| 4714 |
return AllowedItems & netflag_flag::NETFLAG_DOGUIDED; |
| 4715 |
case powerup_type_t::POW_SMART_MINE: |
| 4716 |
return AllowedItems & netflag_flag::NETFLAG_DOSMARTMINE; |
| 4717 |
case powerup_type_t::POW_MERCURY_MISSILE_1: |
| 4718 |
case powerup_type_t::POW_MERCURY_MISSILE_4: |
| 4719 |
return AllowedItems & netflag_flag::NETFLAG_DOMERCURY; |
| 4720 |
case powerup_type_t::POW_EARTHSHAKER_MISSILE: |
| 4721 |
return AllowedItems & netflag_flag::NETFLAG_DOSHAKER; |
| 4722 |
case powerup_type_t::POW_AFTERBURNER: |
| 4723 |
return AllowedItems & netflag_flag::NETFLAG_DOAFTERBURNER; |
| 4724 |
case powerup_type_t::POW_CONVERTER: |
| 4725 |
return AllowedItems & netflag_flag::NETFLAG_DOCONVERTER; |
| 4726 |
case powerup_type_t::POW_AMMO_RACK: |
| 4727 |
return AllowedItems & netflag_flag::NETFLAG_DOAMMORACK; |
| 4728 |
case powerup_type_t::POW_HEADLIGHT: |
| 4729 |
return AllowedItems & netflag_flag::NETFLAG_DOHEADLIGHT; |
| 4730 |
case powerup_type_t::POW_FLAG_BLUE: |
| 4731 |
case powerup_type_t::POW_FLAG_RED: |
| 4732 |
return netflag_flag{game_mode_capture_flag(Game_mode)}; |
| 4733 |
#endif |
| 4734 |
default: |
| 4735 |
return netflag_flag{1}; |
| 4736 |
} |
| 4737 |
} |
| 4738 |
|
| 4739 |
#if DXX_BUILD_DESCENT == 2 |
| 4740 |
void multi_send_finish_game () |
| 4741 |
{ |
| 4742 |
multi_command<multiplayer_command_t::MULTI_FINISH_GAME> multibuf; |
| 4743 |
multibuf[1]=Player_num; |
| 4744 |
|
| 4745 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4746 |
} |
| 4747 |
|
| 4748 |
namespace { |
| 4749 |
|
| 4750 |
static void multi_do_finish_game() |
| 4751 |
{ |
| 4752 |
if (Current_level_num != Current_mission->last_level) |
| 4753 |
return; |
| 4754 |
|
| 4755 |
do_final_boss_hacks(); |
| 4756 |
} |
| 4757 |
|
| 4758 |
} |
| 4759 |
|
| 4760 |
void multi_send_trigger_specific(const playernum_t pnum, const trgnum_t trig) |
| 4761 |
{ |
| 4762 |
multi_command<multiplayer_command_t::MULTI_START_TRIGGER> multibuf; |
| 4763 |
static_assert(sizeof(trgnum_t) == sizeof(uint8_t), "trigger number could be truncated"); |
| 4764 |
multibuf[1] = static_cast<uint8_t>(trig); |
| 4765 |
|
| 4766 |
multi_send_data_direct(multibuf, pnum, 2); |
| 4767 |
} |
| 4768 |
|
| 4769 |
namespace { |
| 4770 |
|
| 4771 |
static void multi_do_start_trigger(const multiplayer_rspan<multiplayer_command_t::MULTI_START_TRIGGER> buf) |
| 4772 |
{ |
| 4773 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 4774 |
auto &vmtrgptr = Triggers.vmptr; |
| 4775 |
const auto &&utrg = vmtrgptr.check_untrusted(static_cast<trgnum_t>(buf[1])); |
| 4776 |
if (!utrg) |
| 4777 |
return; |
| 4778 |
auto &trg = **utrg; |
| 4779 |
trg.flags |= trigger_behavior_flags::disabled; |
| 4780 |
} |
| 4781 |
|
| 4782 |
} |
| 4783 |
#endif |
| 4784 |
|
| 4785 |
namespace { |
| 4786 |
static void multi_adjust_lifetime_ranking(int &k, const int count) |
| 4787 |
{ |
| 4788 |
if (!(Game_mode & GM_NETWORK)) |
| 4789 |
return; |
| 4790 |
|
| 4791 |
const auto oldrank = GetMyNetRanking(); |
| 4792 |
k += count; |
| 4793 |
const auto newrank = GetMyNetRanking(); |
| 4794 |
if (oldrank != newrank) |
| 4795 |
{ |
| 4796 |
Netgame.players[Player_num].rank = newrank; |
| 4797 |
multi_send_ranking(newrank); |
| 4798 |
if (!PlayerCfg.NoRankings) |
| 4799 |
{ |
| 4800 |
HUD_init_message(HM_MULTI, "You have been %smoted to %s!", newrank > oldrank ? "pro" : "de", RankStrings[newrank]); |
| 4801 |
#if DXX_BUILD_DESCENT == 1 |
| 4802 |
digi_play_sample (sound_effect::SOUND_CONTROL_CENTER_WARNING_SIREN,F1_0*2); |
| 4803 |
#elif DXX_BUILD_DESCENT == 2 |
| 4804 |
digi_play_sample (sound_effect::SOUND_BUDDY_MET_GOAL,F1_0*2); |
| 4805 |
#endif |
| 4806 |
} |
| 4807 |
} |
| 4808 |
} |
| 4809 |
} |
| 4810 |
|
| 4811 |
#if !(!defined(RELEASE) && DXX_BUILD_DESCENT == 2) |
| 4812 |
namespace { |
| 4813 |
#endif |
| 4814 |
void multi_add_lifetime_kills(const int count) |
| 4815 |
{ |
| 4816 |
// This function adds a kill to lifetime stats of this player, and possibly |
| 4817 |
// gives a promotion. If so, it will tell everyone else |
| 4818 |
|
| 4819 |
multi_adjust_lifetime_ranking(PlayerCfg.NetlifeKills, count); |
| 4820 |
} |
| 4821 |
#if !(!defined(RELEASE) && DXX_BUILD_DESCENT == 2) |
| 4822 |
} |
| 4823 |
#endif |
| 4824 |
|
| 4825 |
namespace { |
| 4826 |
void multi_add_lifetime_killed () |
| 4827 |
{ |
| 4828 |
// This function adds a "killed" to lifetime stats of this player, and possibly |
| 4829 |
// gives a demotion. If so, it will tell everyone else |
| 4830 |
|
| 4831 |
if (Game_mode & GM_MULTI_COOP) |
| 4832 |
return; |
| 4833 |
|
| 4834 |
multi_adjust_lifetime_ranking(PlayerCfg.NetlifeKilled, 1); |
| 4835 |
} |
| 4836 |
} |
| 4837 |
} |
| 4838 |
|
| 4839 |
namespace { |
| 4840 |
|
| 4841 |
void multi_send_ranking (const netplayer_info::player_rank newrank) |
| 4842 |
{ |
| 4843 |
multi_command<multiplayer_command_t::MULTI_RANK> multibuf; |
| 4844 |
multibuf[1]=static_cast<char>(Player_num); |
| 4845 |
multibuf[2] = underlying_value(newrank); |
| 4846 |
|
| 4847 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4848 |
} |
| 4849 |
|
| 4850 |
static void multi_do_ranking(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_RANK> buf) |
| 4851 |
{ |
| 4852 |
const auto rank = build_rank_from_untrusted(buf[2]); |
| 4853 |
if (rank == netplayer_info::player_rank::None) |
| 4854 |
return; |
| 4855 |
if (!RankStrings.valid_index(rank)) |
| 4856 |
return; |
| 4857 |
|
| 4858 |
auto &netrank = Netgame.players[pnum].rank; |
| 4859 |
if (netrank == rank) |
| 4860 |
return; |
| 4861 |
const auto rankstr = (netrank < rank) ? "pro" : "de"; |
| 4862 |
netrank = rank; |
| 4863 |
|
| 4864 |
if (!PlayerCfg.NoRankings) |
| 4865 |
HUD_init_message(HM_MULTI, "%s has been %smoted to %s!",static_cast<const char *>(vcplayerptr(pnum)->callsign), rankstr, RankStrings[rank]); |
| 4866 |
} |
| 4867 |
|
| 4868 |
} |
| 4869 |
|
| 4870 |
namespace dcx { |
| 4871 |
|
| 4872 |
// Decide if fire from "killer" is friendly. If yes return 1 (no harm to me) otherwise 0 (damage me) |
| 4873 |
int multi_maybe_disable_friendly_fire(const object_base *const killer) |
| 4874 |
{ |
| 4875 |
if (!(Game_mode & GM_NETWORK)) // no Multiplayer game -> always harm me! |
| 4876 |
return 0; |
| 4877 |
if (!Netgame.NoFriendlyFire) // friendly fire is activated -> harm me! |
| 4878 |
return 0; |
| 4879 |
if (!killer) // no actual killer -> harm me! |
| 4880 |
return 0; |
| 4881 |
if (killer->type != OBJ_PLAYER) // not a player -> harm me! |
| 4882 |
return 0; |
| 4883 |
if (auto is_coop = Game_mode & GM_MULTI_COOP) // coop mode -> don't harm me! |
| 4884 |
return is_coop; |
| 4885 |
else if (Game_mode & GM_TEAM) // team mode - find out if killer is in my team |
| 4886 |
{ |
| 4887 |
if (multi_get_team_from_player(Netgame, Player_num) == multi_get_team_from_player(Netgame, get_player_id(*killer))) // in my team -> don't harm me! |
| 4888 |
return 1; |
| 4889 |
else // opposite team -> harm me! |
| 4890 |
return 0; |
| 4891 |
} |
| 4892 |
return 0; // all other cases -> harm me! |
| 4893 |
} |
| 4894 |
|
| 4895 |
namespace { |
| 4896 |
|
| 4897 |
void multi_new_bounty_target(playernum_t pnum, const char *const callsign) |
| 4898 |
{ |
| 4899 |
/* If it's already the same, don't do it */ |
| 4900 |
if (Bounty_target == pnum) |
| 4901 |
return; |
| 4902 |
/* Set the target */ |
| 4903 |
Bounty_target = pnum; |
| 4904 |
/* Send a message */ |
| 4905 |
const auto ship_color{static_cast<player_ship_color>(pnum)}; |
| 4906 |
HUD_init_message(HM_MULTI, "%c%c%s is the new target!", CC_COLOR, BM_XRGB(player_rgb[ship_color].r, player_rgb[ship_color].g, player_rgb[ship_color].b), callsign); |
| 4907 |
} |
| 4908 |
|
| 4909 |
} |
| 4910 |
|
| 4911 |
} |
| 4912 |
|
| 4913 |
/* Bounty packer sender and handler */ |
| 4914 |
void multi_send_bounty( void ) |
| 4915 |
{ |
| 4916 |
/* Test game mode */ |
| 4917 |
if( !( Game_mode & GM_BOUNTY ) ) |
| 4918 |
return; |
| 4919 |
if ( !multi_i_am_master() ) |
| 4920 |
return; |
| 4921 |
|
| 4922 |
multi_command<multiplayer_command_t::MULTI_DO_BOUNTY> multibuf; |
| 4923 |
/* Add opcode, target ID and how often we re-assigned */ |
| 4924 |
multibuf[1] = static_cast<char>(Bounty_target); |
| 4925 |
|
| 4926 |
/* Send data */ |
| 4927 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 4928 |
} |
| 4929 |
|
| 4930 |
namespace dsx { |
| 4931 |
|
| 4932 |
namespace { |
| 4933 |
|
| 4934 |
static void multi_do_bounty(const multiplayer_rspan<multiplayer_command_t::MULTI_DO_BOUNTY> buf) |
| 4935 |
{ |
| 4936 |
if ( multi_i_am_master() ) |
| 4937 |
return; |
| 4938 |
const unsigned pnum = buf[1]; |
| 4939 |
multi_new_bounty_target_with_sound(pnum, vcplayerptr(pnum)->callsign); |
| 4940 |
} |
| 4941 |
|
| 4942 |
void multi_new_bounty_target_with_sound(const playernum_t pnum, const char *const callsign) |
| 4943 |
{ |
| 4944 |
#if DXX_BUILD_DESCENT == 1 |
| 4945 |
digi_play_sample( sound_effect::SOUND_CONTROL_CENTER_WARNING_SIREN, F1_0 * 3 ); |
| 4946 |
#elif DXX_BUILD_DESCENT == 2 |
| 4947 |
digi_play_sample( sound_effect::SOUND_BUDDY_MET_GOAL, F1_0 * 2 ); |
| 4948 |
#endif |
| 4949 |
multi_new_bounty_target(pnum, callsign); |
| 4950 |
} |
| 4951 |
|
| 4952 |
static void multi_do_save_game(const multiplayer_rspan<multiplayer_command_t::MULTI_SAVE_GAME> buf) |
| 4953 |
{ |
| 4954 |
int count{1}; |
| 4955 |
ubyte slot; |
| 4956 |
d_game_unique_state::savegame_description desc; |
| 4957 |
|
| 4958 |
slot = buf[count]; count += 1; |
| 4959 |
const auto id{GET_INTEL_INT(&buf[count])}; count += 4; |
| 4960 |
memcpy(desc.data(), &buf[count], desc.size()); |
| 4961 |
desc.back() = 0; |
| 4962 |
|
| 4963 |
multi_save_game(static_cast<unsigned>(slot), id, desc); |
| 4964 |
} |
| 4965 |
|
| 4966 |
} |
| 4967 |
|
| 4968 |
} |
| 4969 |
|
| 4970 |
namespace { |
| 4971 |
|
| 4972 |
static void multi_do_restore_game(const multiplayer_rspan<multiplayer_command_t::MULTI_RESTORE_GAME> buf) |
| 4973 |
{ |
| 4974 |
int count{1}; |
| 4975 |
ubyte slot; |
| 4976 |
|
| 4977 |
slot = buf[count]; count += 1; |
| 4978 |
const unsigned id{GET_INTEL_INT(&buf[count])}; count += 4; |
| 4979 |
|
| 4980 |
multi_restore_game( slot, id ); |
| 4981 |
} |
| 4982 |
|
| 4983 |
} |
| 4984 |
|
| 4985 |
namespace dcx { |
| 4986 |
namespace { |
| 4987 |
|
| 4988 |
template <multiplayer_command_t C, std::size_t Extent> |
| 4989 |
static constexpr auto multi_subspan_first(const std::span<const uint8_t, Extent> &data) |
| 4990 |
{ |
| 4991 |
return data.template first<command_length<C>>(); |
| 4992 |
} |
| 4993 |
|
| 4994 |
static void multi_send_save_game(const d_game_unique_state::save_slot slot, const unsigned id, const d_game_unique_state::savegame_description &desc) |
| 4995 |
{ |
| 4996 |
int count{0}; |
| 4997 |
|
| 4998 |
count += 1; |
| 4999 |
multi_command<multiplayer_command_t::MULTI_SAVE_GAME> multibuf; |
| 5000 |
multibuf[count] = static_cast<uint8_t>(slot); count += 1; // Save slot=0 |
| 5001 |
PUT_INTEL_INT(&multibuf[count], id ); count += 4; // Save id |
| 5002 |
memcpy(&multibuf[count], desc.data(), desc.size()); |
| 5003 |
|
| 5004 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 5005 |
} |
| 5006 |
|
| 5007 |
static void multi_send_restore_game(ubyte slot, uint id) |
| 5008 |
{ |
| 5009 |
int count{0}; |
| 5010 |
|
| 5011 |
count += 1; |
| 5012 |
multi_command<multiplayer_command_t::MULTI_RESTORE_GAME> multibuf; |
| 5013 |
multibuf[count] = slot; count += 1; // Save slot=0 |
| 5014 |
PUT_INTEL_INT(&multibuf[count], id ); count += 4; // Save id |
| 5015 |
|
| 5016 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 5017 |
} |
| 5018 |
|
| 5019 |
static void multi_do_msgsend_state(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_TYPING_STATE> buf) |
| 5020 |
{ |
| 5021 |
multi_sending_message[pnum] = msgsend_state{buf[2]}; |
| 5022 |
} |
| 5023 |
|
| 5024 |
} |
| 5025 |
} |
| 5026 |
|
| 5027 |
namespace dsx { |
| 5028 |
|
| 5029 |
void multi_initiate_save_game() |
| 5030 |
{ |
| 5031 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5032 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 5033 |
auto &vcobjptr = Objects.vcptr; |
| 5034 |
|
| 5035 |
if (const auto reason = multi_i_am_master() ? multi_interactive_deny_save_game(vcobjptr, partial_range(Players, N_players), LevelUniqueControlCenterState) : "Only the host is allowed to save a game!") |
| 5036 |
{ |
| 5037 |
HUD_init_message(HM_MULTI, "Cannot save: %s", reason); |
| 5038 |
return; |
| 5039 |
} |
| 5040 |
|
| 5041 |
d_game_unique_state::savegame_file_path filename{}; |
| 5042 |
d_game_unique_state::savegame_description desc{}; |
| 5043 |
const auto slot = state_get_save_file(*grd_curcanv, filename, &desc, blind_save::no); |
| 5044 |
if (!GameUniqueState.valid_save_slot(slot)) |
| 5045 |
return; |
| 5046 |
const auto &&player_range = partial_const_range(Players, N_players); |
| 5047 |
// Execute "alive" and "duplicate callsign" checks again in case things changed while host decided upon the savegame. |
| 5048 |
if (const auto reason = multi_interactive_deny_save_game(vcobjptr, player_range, LevelUniqueControlCenterState)) |
| 5049 |
{ |
| 5050 |
HUD_init_message(HM_MULTI, "Cannot save: %s", reason); |
| 5051 |
return; |
| 5052 |
} |
| 5053 |
multi_execute_save_game(slot, desc, player_range); |
| 5054 |
} |
| 5055 |
|
| 5056 |
void multi_execute_save_game(const d_game_unique_state::save_slot slot, const d_game_unique_state::savegame_description &desc, const std::ranges::subrange<const player *> player_range) |
| 5057 |
{ |
| 5058 |
// Make a unique game id |
| 5059 |
fix game_id; |
| 5060 |
game_id = static_cast<fix>(timer_query()); |
| 5061 |
game_id ^= N_players<<4; |
| 5062 |
range_for (auto &i, player_range) |
| 5063 |
{ |
| 5064 |
fix call2i; |
| 5065 |
memcpy(&call2i, static_cast<const char *>(i.callsign), sizeof(fix)); |
| 5066 |
game_id ^= call2i; |
| 5067 |
} |
| 5068 |
if ( game_id == 0 ) |
| 5069 |
game_id = 1; // 0 is invalid |
| 5070 |
|
| 5071 |
multi_send_save_game( slot, game_id, desc ); |
| 5072 |
multi_do_frame(); |
| 5073 |
multi_save_game(static_cast<unsigned>(slot), game_id, desc); |
| 5074 |
} |
| 5075 |
|
| 5076 |
void multi_initiate_restore_game() |
| 5077 |
{ |
| 5078 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5079 |
auto &vcobjptr = Objects.vcptr; |
| 5080 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 5081 |
|
| 5082 |
if (Network_status == network_state::endlevel || LevelUniqueControlCenterState.Control_center_destroyed) |
| 5083 |
return; |
| 5084 |
|
| 5085 |
if (const auto reason = multi_i_am_master() ? multi_interactive_deny_save_game(vcobjptr, partial_const_range(Players, N_players), LevelUniqueControlCenterState) : "Only host is allowed to load a game!") |
| 5086 |
{ |
| 5087 |
HUD_init_message(HM_MULTI, "Cannot load: %s", reason); |
| 5088 |
return; |
| 5089 |
} |
| 5090 |
d_game_unique_state::savegame_file_path filename; |
| 5091 |
const auto eslot = state_get_restore_file(*grd_curcanv, filename, blind_save::no); |
| 5092 |
if (!GameUniqueState.valid_load_slot(eslot)) |
| 5093 |
return; |
| 5094 |
/* Recheck the interactive conditions, but not the host status. If |
| 5095 |
* this system was the host before, it must still be the host now. |
| 5096 |
*/ |
| 5097 |
if (const auto reason = multi_interactive_deny_save_game(vcobjptr, partial_const_range(Players, N_players), LevelUniqueControlCenterState)) |
| 5098 |
{ |
| 5099 |
HUD_init_message(HM_MULTI, "Cannot load: %s", reason); |
| 5100 |
return; |
| 5101 |
} |
| 5102 |
state_game_id = state_get_game_id(filename); |
| 5103 |
if (!state_game_id) |
| 5104 |
return; |
| 5105 |
const unsigned slot = static_cast<unsigned>(eslot); |
| 5106 |
multi_send_restore_game(slot,state_game_id); |
| 5107 |
multi_do_frame(); |
| 5108 |
multi_restore_game(slot,state_game_id); |
| 5109 |
} |
| 5110 |
|
| 5111 |
namespace { |
| 5112 |
|
| 5113 |
void multi_save_game(const unsigned slot, const unsigned id, const d_game_unique_state::savegame_description &desc) |
| 5114 |
{ |
| 5115 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 5116 |
char filename[PATH_MAX]; |
| 5117 |
|
| 5118 |
if (Network_status == network_state::endlevel || LevelUniqueControlCenterState.Control_center_destroyed) |
| 5119 |
return; |
| 5120 |
|
| 5121 |
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.mg%x"), static_cast<const char *>(get_local_player().callsign), slot); |
| 5122 |
HUD_init_message(HM_MULTI, "Saving game #%d, '%s'", slot, desc.data()); |
| 5123 |
state_game_id = id; |
| 5124 |
pause_game_world_time p; |
| 5125 |
state_save_all_sub(filename, desc.data()); |
| 5126 |
} |
| 5127 |
|
| 5128 |
void multi_restore_game(const unsigned slot, const unsigned id) |
| 5129 |
{ |
| 5130 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 5131 |
d_game_unique_state::savegame_file_path filename; |
| 5132 |
|
| 5133 |
if (Network_status == network_state::endlevel || LevelUniqueControlCenterState.Control_center_destroyed) |
| 5134 |
return; |
| 5135 |
|
| 5136 |
auto &plr = get_local_player(); |
| 5137 |
snprintf(filename.data(), filename.size(), PLAYER_DIRECTORY_STRING("%s.mg%x"), static_cast<const char *>(plr.callsign), slot); |
| 5138 |
|
| 5139 |
for (unsigned i = 0, n = N_players; i < n; ++i) |
| 5140 |
multi_strip_robots(i); |
| 5141 |
if (multi_i_am_master()) // put all players to wait-state again so we can sync up properly |
| 5142 |
range_for (auto &i, Players) |
| 5143 |
if (i.connected == player_connection_status::playing && &i != &plr) |
| 5144 |
i.connected = player_connection_status::waiting; |
| 5145 |
|
| 5146 |
const auto thisid = state_get_game_id(filename); |
| 5147 |
if (thisid!=id) |
| 5148 |
{ |
| 5149 |
nm_messagebox_str(menu_title{nullptr}, nm_messagebox_tie(TXT_OK), menu_subtitle{"A multi-save game was restored\nthat you are missing or does not\nmatch that of the others.\nYou must rejoin if you wish to\ncontinue."}); |
| 5150 |
return; |
| 5151 |
} |
| 5152 |
|
| 5153 |
#if DXX_BUILD_DESCENT == 2 |
| 5154 |
auto &LevelSharedDestructibleLightState = LevelSharedSegmentState.DestructibleLights; |
| 5155 |
#endif |
| 5156 |
state_restore_all_sub( |
| 5157 |
#if DXX_BUILD_DESCENT == 2 |
| 5158 |
LevelSharedDestructibleLightState, secret_restore::none, |
| 5159 |
#endif |
| 5160 |
filename.data()); |
| 5161 |
multi_send_score(); // send my restored scores. I sent 0 when I loaded the level anyways... |
| 5162 |
} |
| 5163 |
|
| 5164 |
} |
| 5165 |
|
| 5166 |
} |
| 5167 |
|
| 5168 |
void multi_send_msgsend_state(const msgsend_state state) |
| 5169 |
{ |
| 5170 |
multi_command<multiplayer_command_t::MULTI_TYPING_STATE> multibuf; |
| 5171 |
/* Obsolete - reclaim player number field on next multiplayer protocol version bump */ |
| 5172 |
multibuf[1] = Player_num; |
| 5173 |
multibuf[2] = static_cast<char>(state); |
| 5174 |
|
| 5175 |
multi_send_data(multibuf, multiplayer_data_priority::_2); |
| 5176 |
} |
| 5177 |
|
| 5178 |
namespace { |
| 5179 |
|
| 5180 |
// Specific variables related to our game mode we want the clients to know about |
| 5181 |
void multi_send_gmode_update() |
| 5182 |
{ |
| 5183 |
if (!multi_i_am_master()) |
| 5184 |
return; |
| 5185 |
if (!(Game_mode & GM_TEAM || Game_mode & GM_BOUNTY)) // expand if necessary |
| 5186 |
return; |
| 5187 |
multi_command<multiplayer_command_t::MULTI_GMODE_UPDATE> multibuf; |
| 5188 |
multibuf[1] = Netgame.team_vector; |
| 5189 |
multibuf[2] = Bounty_target; |
| 5190 |
|
| 5191 |
multi_send_data(multibuf, multiplayer_data_priority::_0); |
| 5192 |
} |
| 5193 |
|
| 5194 |
static void multi_do_gmode_update(const multiplayer_rspan<multiplayer_command_t::MULTI_GMODE_UPDATE> buf) |
| 5195 |
{ |
| 5196 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5197 |
auto &vmobjptr = Objects.vmptr; |
| 5198 |
if (multi_i_am_master()) |
| 5199 |
return; |
| 5200 |
if (Game_mode & GM_TEAM) |
| 5201 |
{ |
| 5202 |
if (buf[1] != Netgame.team_vector) |
| 5203 |
{ |
| 5204 |
Netgame.team_vector = buf[1]; |
| 5205 |
range_for (auto &t, partial_const_range(Players, N_players)) |
| 5206 |
if (t.connected != player_connection_status::disconnected) |
| 5207 |
multi_reset_object_texture (vmobjptr(t.objnum)); |
| 5208 |
reset_cockpit(); |
| 5209 |
} |
| 5210 |
} |
| 5211 |
if (Game_mode & GM_BOUNTY) |
| 5212 |
{ |
| 5213 |
Bounty_target = buf[2]; // accept silently - message about change we SHOULD have gotten due to kill computation |
| 5214 |
} |
| 5215 |
} |
| 5216 |
|
| 5217 |
} |
| 5218 |
|
| 5219 |
/* |
| 5220 |
* Send player inventory to all other players. Intended to be used for the host to repopulate the level with new powerups. |
| 5221 |
* Could also be used to let host decide which powerups a client is allowed to collect and/or drop, anti-cheat functions (needs shield/energy update then and more frequent updates/triggers). |
| 5222 |
*/ |
| 5223 |
namespace dsx { |
| 5224 |
void multi_send_player_inventory(const multiplayer_data_priority priority) |
| 5225 |
{ |
| 5226 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5227 |
auto &vmobjptr = Objects.vmptr; |
| 5228 |
multi_command<multiplayer_command_t::MULTI_PLAYER_INV> multibuf; |
| 5229 |
int count{0}; |
| 5230 |
|
| 5231 |
count++; |
| 5232 |
multibuf[count++] = Player_num; |
| 5233 |
|
| 5234 |
auto &player_info = get_local_plrobj().ctype.player_info; |
| 5235 |
PUT_WEAPON_FLAGS(multibuf, count, player_info.primary_weapon_flags); |
| 5236 |
multibuf[count++] = static_cast<char>(player_info.laser_level); |
| 5237 |
|
| 5238 |
auto &secondary_ammo = player_info.secondary_ammo; |
| 5239 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::HOMING_INDEX]; |
| 5240 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::CONCUSSION_INDEX]; |
| 5241 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMART_INDEX]; |
| 5242 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::MEGA_INDEX]; |
| 5243 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::PROXIMITY_INDEX]; |
| 5244 |
|
| 5245 |
#if DXX_BUILD_DESCENT == 2 |
| 5246 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMISSILE1_INDEX]; |
| 5247 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::GUIDED_INDEX]; |
| 5248 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMART_MINE_INDEX]; |
| 5249 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMISSILE4_INDEX]; |
| 5250 |
multibuf[count++] = secondary_ammo[secondary_weapon_index_t::SMISSILE5_INDEX]; |
| 5251 |
#endif |
| 5252 |
|
| 5253 |
PUT_INTEL_SHORT(&multibuf[count], player_info.vulcan_ammo); |
| 5254 |
count += 2; |
| 5255 |
PUT_INTEL_INT(&multibuf[count], player_info.powerup_flags.get_player_flags()); |
| 5256 |
count += 4; |
| 5257 |
|
| 5258 |
multi_send_data(multibuf, priority); |
| 5259 |
} |
| 5260 |
|
| 5261 |
namespace { |
| 5262 |
|
| 5263 |
static void multi_do_player_inventory(const playernum_t pnum, const multiplayer_rspan<multiplayer_command_t::MULTI_PLAYER_INV> buf) |
| 5264 |
{ |
| 5265 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5266 |
auto &vmobjptridx = Objects.vmptridx; |
| 5267 |
int count; |
| 5268 |
|
| 5269 |
#ifdef NDEBUG |
| 5270 |
if (pnum >= N_players || pnum == Player_num) |
| 5271 |
return; |
| 5272 |
#else |
| 5273 |
Assert(pnum < N_players); |
| 5274 |
Assert(pnum != Player_num); |
| 5275 |
#endif |
| 5276 |
|
| 5277 |
count = 2; |
| 5278 |
#if DXX_BUILD_DESCENT == 1 |
| 5279 |
#define GET_WEAPON_FLAGS(buf,count) buf[count++] |
| 5280 |
#elif DXX_BUILD_DESCENT == 2 |
| 5281 |
#define GET_WEAPON_FLAGS(buf,count) (count += sizeof(uint16_t), GET_INTEL_SHORT(&buf[(count - sizeof(uint16_t))])) |
| 5282 |
#endif |
| 5283 |
const auto &&objp = vmobjptridx(vcplayerptr(pnum)->objnum); |
| 5284 |
auto &player_info = objp->ctype.player_info; |
| 5285 |
player_info.primary_weapon_flags = GET_WEAPON_FLAGS(buf, count); |
| 5286 |
player_info.laser_level = laser_level{buf[count]}; |
| 5287 |
count++; |
| 5288 |
|
| 5289 |
auto &secondary_ammo = player_info.secondary_ammo; |
| 5290 |
secondary_ammo[secondary_weapon_index_t::HOMING_INDEX] = buf[count]; count++; |
| 5291 |
secondary_ammo[secondary_weapon_index_t::CONCUSSION_INDEX] = buf[count];count++; |
| 5292 |
secondary_ammo[secondary_weapon_index_t::SMART_INDEX] = buf[count]; count++; |
| 5293 |
secondary_ammo[secondary_weapon_index_t::MEGA_INDEX] = buf[count]; count++; |
| 5294 |
secondary_ammo[secondary_weapon_index_t::PROXIMITY_INDEX] = buf[count]; count++; |
| 5295 |
|
| 5296 |
#if DXX_BUILD_DESCENT == 2 |
| 5297 |
secondary_ammo[secondary_weapon_index_t::SMISSILE1_INDEX] = buf[count]; count++; |
| 5298 |
secondary_ammo[secondary_weapon_index_t::GUIDED_INDEX] = buf[count]; count++; |
| 5299 |
secondary_ammo[secondary_weapon_index_t::SMART_MINE_INDEX]= buf[count]; count++; |
| 5300 |
secondary_ammo[secondary_weapon_index_t::SMISSILE4_INDEX] = buf[count]; count++; |
| 5301 |
secondary_ammo[secondary_weapon_index_t::SMISSILE5_INDEX] = buf[count]; count++; |
| 5302 |
#endif |
| 5303 |
|
| 5304 |
player_info.vulcan_ammo = GET_INTEL_SHORT(&buf[count]); count += 2; |
| 5305 |
player_info.powerup_flags = player_flags(GET_INTEL_INT(&buf[count])); count += 4; |
| 5306 |
} |
| 5307 |
|
| 5308 |
/* |
| 5309 |
* Count the inventory of the level. Initial (start) or current (now). |
| 5310 |
* In 'current', also consider player inventories (and the thief bot). |
| 5311 |
* NOTE: We add actual ammo amount - we do not want to count in 'amount of powerups'. Makes it easier to keep track of overhead (proximities, vulcan ammo) |
| 5312 |
*/ |
| 5313 |
static void MultiLevelInv_CountLevelPowerups() |
| 5314 |
{ |
| 5315 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5316 |
auto &vmobjptridx = Objects.vmptridx; |
| 5317 |
if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI_COOP)) |
| 5318 |
return; |
| 5319 |
MultiLevelInv.Current = {}; |
| 5320 |
|
| 5321 |
range_for (const auto &&objp, vmobjptridx) |
| 5322 |
{ |
| 5323 |
if (objp->type == OBJ_WEAPON) // keep live bombs in inventory so they will respawn after they're gone |
| 5324 |
{ |
| 5325 |
auto wid = get_weapon_id(objp); |
| 5326 |
if (wid == weapon_id_type::PROXIMITY_ID) |
| 5327 |
MultiLevelInv.Current[powerup_type_t::POW_PROXIMITY_WEAPON]++; |
| 5328 |
#if DXX_BUILD_DESCENT == 2 |
| 5329 |
if (wid == weapon_id_type::SUPERPROX_ID) |
| 5330 |
MultiLevelInv.Current[powerup_type_t::POW_SMART_MINE]++; |
| 5331 |
#endif |
| 5332 |
} |
| 5333 |
if (objp->type != OBJ_POWERUP) |
| 5334 |
continue; |
| 5335 |
auto pid = get_powerup_id(objp); |
| 5336 |
switch (pid) |
| 5337 |
{ |
| 5338 |
case powerup_type_t::POW_VULCAN_WEAPON: |
| 5339 |
#if DXX_BUILD_DESCENT == 2 |
| 5340 |
case powerup_type_t::POW_GAUSS_WEAPON: |
| 5341 |
#endif |
| 5342 |
MultiLevelInv.Current[powerup_type_t::POW_VULCAN_AMMO] += objp->ctype.powerup_info.count; // add contained ammo so we do not lose this from level when used up |
| 5343 |
/* fall through to increment Current[pid] */ |
| 5344 |
[[fallthrough]]; |
| 5345 |
case powerup_type_t::POW_LASER: |
| 5346 |
case powerup_type_t::POW_QUAD_FIRE: |
| 5347 |
case powerup_type_t::POW_SPREADFIRE_WEAPON: |
| 5348 |
case powerup_type_t::POW_PLASMA_WEAPON: |
| 5349 |
case powerup_type_t::POW_FUSION_WEAPON: |
| 5350 |
case powerup_type_t::POW_MISSILE_1: |
| 5351 |
case powerup_type_t::POW_HOMING_AMMO_1: |
| 5352 |
case powerup_type_t::POW_SMARTBOMB_WEAPON: |
| 5353 |
case powerup_type_t::POW_MEGA_WEAPON: |
| 5354 |
case powerup_type_t::POW_CLOAK: |
| 5355 |
case powerup_type_t::POW_INVULNERABILITY: |
| 5356 |
#if DXX_BUILD_DESCENT == 2 |
| 5357 |
case powerup_type_t::POW_SUPER_LASER: |
| 5358 |
case powerup_type_t::POW_HELIX_WEAPON: |
| 5359 |
case powerup_type_t::POW_PHOENIX_WEAPON: |
| 5360 |
case powerup_type_t::POW_OMEGA_WEAPON: |
| 5361 |
case powerup_type_t::POW_SMISSILE1_1: |
| 5362 |
case powerup_type_t::POW_GUIDED_MISSILE_1: |
| 5363 |
case powerup_type_t::POW_MERCURY_MISSILE_1: |
| 5364 |
case powerup_type_t::POW_EARTHSHAKER_MISSILE: |
| 5365 |
case powerup_type_t::POW_FULL_MAP: |
| 5366 |
case powerup_type_t::POW_CONVERTER: |
| 5367 |
case powerup_type_t::POW_AMMO_RACK: |
| 5368 |
case powerup_type_t::POW_AFTERBURNER: |
| 5369 |
case powerup_type_t::POW_HEADLIGHT: |
| 5370 |
case powerup_type_t::POW_FLAG_BLUE: |
| 5371 |
case powerup_type_t::POW_FLAG_RED: |
| 5372 |
#endif |
| 5373 |
MultiLevelInv.Current[pid]++; |
| 5374 |
break; |
| 5375 |
case powerup_type_t::POW_MISSILE_4: |
| 5376 |
case powerup_type_t::POW_HOMING_AMMO_4: |
| 5377 |
#if DXX_BUILD_DESCENT == 2 |
| 5378 |
case powerup_type_t::POW_SMISSILE1_4: |
| 5379 |
case powerup_type_t::POW_GUIDED_MISSILE_4: |
| 5380 |
case powerup_type_t::POW_MERCURY_MISSILE_4: |
| 5381 |
#endif |
| 5382 |
MultiLevelInv.Current[static_cast<powerup_type_t>(underlying_value(pid) - 1)] += 4; |
| 5383 |
break; |
| 5384 |
case powerup_type_t::POW_PROXIMITY_WEAPON: |
| 5385 |
#if DXX_BUILD_DESCENT == 2 |
| 5386 |
case powerup_type_t::POW_SMART_MINE: |
| 5387 |
#endif |
| 5388 |
MultiLevelInv.Current[pid] += 4; // count the actual bombs |
| 5389 |
break; |
| 5390 |
case powerup_type_t::POW_VULCAN_AMMO: |
| 5391 |
MultiLevelInv.Current[pid] += VULCAN_AMMO_AMOUNT; // count the actual ammo |
| 5392 |
break; |
| 5393 |
default: |
| 5394 |
break; // All other items either do not exist or we NEVER want to have them respawn. |
| 5395 |
} |
| 5396 |
} |
| 5397 |
} |
| 5398 |
|
| 5399 |
static void MultiLevelInv_CountPlayerInventory() |
| 5400 |
{ |
| 5401 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5402 |
auto &vcobjptr = Objects.vcptr; |
| 5403 |
auto &Current = MultiLevelInv.Current; |
| 5404 |
for (playernum_t i = 0; i < MAX_PLAYERS; i++) |
| 5405 |
{ |
| 5406 |
if (vcplayerptr(i)->connected != player_connection_status::playing) |
| 5407 |
continue; |
| 5408 |
auto &obj = *vcobjptr(vcplayerptr(i)->objnum); |
| 5409 |
if (obj.type == OBJ_GHOST) // Player is dead. Their items are dropped now. |
| 5410 |
continue; |
| 5411 |
auto &player_info = obj.ctype.player_info; |
| 5412 |
// NOTE: We do not need to consider Granted Spawn Items here. These are replaced with shields and even if not, the repopulation function will take care of it. |
| 5413 |
#if DXX_BUILD_DESCENT == 2 |
| 5414 |
if (player_info.laser_level > MAX_LASER_LEVEL) |
| 5415 |
{ |
| 5416 |
/* |
| 5417 |
* We do not know exactly how many normal lasers the player collected before going super so assume they have all. |
| 5418 |
* This loss possible is insignificant since we have super lasers and normal ones may respawn some time after this player dies. |
| 5419 |
*/ |
| 5420 |
Current[powerup_type_t::POW_LASER] += 4; |
| 5421 |
Current[powerup_type_t::POW_SUPER_LASER] += static_cast<unsigned>(player_info.laser_level) - static_cast<unsigned>(MAX_LASER_LEVEL) + 1; // Laser levels start at 0! |
| 5422 |
} |
| 5423 |
else |
| 5424 |
#endif |
| 5425 |
{ |
| 5426 |
Current[powerup_type_t::POW_LASER] += static_cast<unsigned>(player_info.laser_level) + 1; // Laser levels start at 0! |
| 5427 |
} |
| 5428 |
accumulate_flags_count<player_flags, PLAYER_FLAG> powerup_flags(Current, player_info.powerup_flags); |
| 5429 |
accumulate_flags_count<player_info::primary_weapon_flag_type, unsigned> primary_weapon_flags(Current, player_info.primary_weapon_flags); |
| 5430 |
powerup_flags.process(PLAYER_FLAGS_QUAD_LASERS, powerup_type_t::POW_QUAD_FIRE); |
| 5431 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::VULCAN_INDEX), powerup_type_t::POW_VULCAN_WEAPON); |
| 5432 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::SPREADFIRE_INDEX), powerup_type_t::POW_SPREADFIRE_WEAPON); |
| 5433 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::PLASMA_INDEX), powerup_type_t::POW_PLASMA_WEAPON); |
| 5434 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::FUSION_INDEX), powerup_type_t::POW_FUSION_WEAPON); |
| 5435 |
powerup_flags.process(PLAYER_FLAGS_CLOAKED, powerup_type_t::POW_CLOAK); |
| 5436 |
powerup_flags.process(PLAYER_FLAGS_INVULNERABLE, powerup_type_t::POW_INVULNERABILITY); |
| 5437 |
// NOTE: The following can probably be simplified. |
| 5438 |
#if DXX_BUILD_DESCENT == 2 |
| 5439 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::GAUSS_INDEX), powerup_type_t::POW_GAUSS_WEAPON); |
| 5440 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::HELIX_INDEX), powerup_type_t::POW_HELIX_WEAPON); |
| 5441 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::PHOENIX_INDEX), powerup_type_t::POW_PHOENIX_WEAPON); |
| 5442 |
primary_weapon_flags.process(HAS_PRIMARY_FLAG(primary_weapon_index_t::OMEGA_INDEX), powerup_type_t::POW_OMEGA_WEAPON); |
| 5443 |
powerup_flags.process(PLAYER_FLAGS_MAP_ALL, powerup_type_t::POW_FULL_MAP); |
| 5444 |
powerup_flags.process(PLAYER_FLAGS_CONVERTER, powerup_type_t::POW_CONVERTER); |
| 5445 |
powerup_flags.process(PLAYER_FLAGS_AMMO_RACK, powerup_type_t::POW_AMMO_RACK); |
| 5446 |
powerup_flags.process(PLAYER_FLAGS_AFTERBURNER, powerup_type_t::POW_AFTERBURNER); |
| 5447 |
powerup_flags.process(PLAYER_FLAGS_HEADLIGHT, powerup_type_t::POW_HEADLIGHT); |
| 5448 |
if ((Game_mode & GM_CAPTURE) && (player_info.powerup_flags & PLAYER_FLAGS_FLAG)) |
| 5449 |
{ |
| 5450 |
++Current[(multi_get_team_from_player(Netgame, i) == team_number::blue) ? powerup_type_t::POW_FLAG_RED : powerup_type_t::POW_FLAG_BLUE]; |
| 5451 |
} |
| 5452 |
#endif |
| 5453 |
Current[powerup_type_t::POW_VULCAN_AMMO] += player_info.vulcan_ammo; |
| 5454 |
Current[powerup_type_t::POW_MISSILE_1] += player_info.secondary_ammo[secondary_weapon_index_t::CONCUSSION_INDEX]; |
| 5455 |
Current[powerup_type_t::POW_HOMING_AMMO_1] += player_info.secondary_ammo[secondary_weapon_index_t::HOMING_INDEX]; |
| 5456 |
Current[powerup_type_t::POW_PROXIMITY_WEAPON] += player_info.secondary_ammo[secondary_weapon_index_t::PROXIMITY_INDEX]; |
| 5457 |
Current[powerup_type_t::POW_SMARTBOMB_WEAPON] += player_info.secondary_ammo[secondary_weapon_index_t::SMART_INDEX]; |
| 5458 |
Current[powerup_type_t::POW_MEGA_WEAPON] += player_info.secondary_ammo[secondary_weapon_index_t::MEGA_INDEX]; |
| 5459 |
#if DXX_BUILD_DESCENT == 2 |
| 5460 |
Current[powerup_type_t::POW_SMISSILE1_1] += player_info.secondary_ammo[secondary_weapon_index_t::SMISSILE1_INDEX]; |
| 5461 |
Current[powerup_type_t::POW_GUIDED_MISSILE_1] += player_info.secondary_ammo[secondary_weapon_index_t::GUIDED_INDEX]; |
| 5462 |
Current[powerup_type_t::POW_SMART_MINE] += player_info.secondary_ammo[secondary_weapon_index_t::SMART_MINE_INDEX]; |
| 5463 |
Current[powerup_type_t::POW_MERCURY_MISSILE_1] += player_info.secondary_ammo[secondary_weapon_index_t::SMISSILE4_INDEX]; |
| 5464 |
Current[powerup_type_t::POW_EARTHSHAKER_MISSILE] += player_info.secondary_ammo[secondary_weapon_index_t::SMISSILE5_INDEX]; |
| 5465 |
#endif |
| 5466 |
} |
| 5467 |
#if DXX_BUILD_DESCENT == 2 |
| 5468 |
if (Game_mode & GM_MULTI_ROBOTS) // Add (possible) thief inventory |
| 5469 |
{ |
| 5470 |
range_for (auto &i, LevelUniqueObjectState.ThiefState.Stolen_items) |
| 5471 |
{ |
| 5472 |
if (!Current.valid_index(i) || i == powerup_type_t::POW_ENERGY || i == powerup_type_t::POW_SHIELD_BOOST) |
| 5473 |
continue; |
| 5474 |
auto &c = Current[i]; |
| 5475 |
// NOTE: We don't need to consider vulcan ammo or 4pack items as the thief should not steal those items. |
| 5476 |
if (i == powerup_type_t::POW_PROXIMITY_WEAPON || i == powerup_type_t::POW_SMART_MINE) |
| 5477 |
c += 4; |
| 5478 |
else |
| 5479 |
++c; |
| 5480 |
} |
| 5481 |
} |
| 5482 |
#endif |
| 5483 |
} |
| 5484 |
} |
| 5485 |
} |
| 5486 |
|
| 5487 |
void MultiLevelInv_InitializeCount() |
| 5488 |
{ |
| 5489 |
MultiLevelInv_CountLevelPowerups(); |
| 5490 |
MultiLevelInv.Initial = MultiLevelInv.Current; |
| 5491 |
MultiLevelInv.RespawnTimer = {}; |
| 5492 |
} |
| 5493 |
|
| 5494 |
void MultiLevelInv_Recount() |
| 5495 |
{ |
| 5496 |
MultiLevelInv_CountLevelPowerups(); |
| 5497 |
MultiLevelInv_CountPlayerInventory(); |
| 5498 |
} |
| 5499 |
|
| 5500 |
// Takes a powerup type and checks if we are allowed to spawn it. |
| 5501 |
namespace dsx { |
| 5502 |
bool MultiLevelInv_AllowSpawn(powerup_type_t powerup_type) |
| 5503 |
{ |
| 5504 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 5505 |
if ((Game_mode & GM_MULTI_COOP) || LevelUniqueControlCenterState.Control_center_destroyed || Network_status != network_state::playing) |
| 5506 |
return 0; |
| 5507 |
|
| 5508 |
int req_amount{1}; // required amount of item to drop a powerup. |
| 5509 |
|
| 5510 |
if (powerup_type == powerup_type_t::POW_VULCAN_AMMO) |
| 5511 |
req_amount = VULCAN_AMMO_AMOUNT; |
| 5512 |
else if (powerup_type == powerup_type_t::POW_PROXIMITY_WEAPON |
| 5513 |
#if DXX_BUILD_DESCENT == 2 |
| 5514 |
|| powerup_type == powerup_type_t::POW_SMART_MINE |
| 5515 |
#endif |
| 5516 |
) |
| 5517 |
req_amount = 4; |
| 5518 |
|
| 5519 |
if (MultiLevelInv.Initial[powerup_type] == 0 || MultiLevelInv.Current[powerup_type] > MultiLevelInv.Initial[powerup_type]) // Item does not exist in level or we have too many. |
| 5520 |
return 0; |
| 5521 |
else if (MultiLevelInv.Initial[powerup_type] - MultiLevelInv.Current[powerup_type] >= req_amount) |
| 5522 |
return 1; |
| 5523 |
return 0; |
| 5524 |
} |
| 5525 |
|
| 5526 |
namespace { |
| 5527 |
|
| 5528 |
// Repopulate the level with missing items. |
| 5529 |
void MultiLevelInv_Repopulate(fix frequency) |
| 5530 |
{ |
| 5531 |
auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; |
| 5532 |
if (!multi_i_am_master() || (Game_mode & GM_MULTI_COOP) || LevelUniqueControlCenterState.Control_center_destroyed) |
| 5533 |
return; |
| 5534 |
|
| 5535 |
MultiLevelInv_Recount(); // recount current items |
| 5536 |
for (const uint8_t i : constant_xrange<uint8_t, uint8_t{0}, uint8_t{MAX_POWERUP_TYPES}>{}) |
| 5537 |
{ |
| 5538 |
const powerup_type_t pi{i}; |
| 5539 |
auto &rt = MultiLevelInv.RespawnTimer[pi]; |
| 5540 |
if (MultiLevelInv_AllowSpawn(pi)) |
| 5541 |
rt += frequency; |
| 5542 |
else |
| 5543 |
{ |
| 5544 |
rt = 0; |
| 5545 |
continue; |
| 5546 |
} |
| 5547 |
|
| 5548 |
if (rt >= F1_0*2) |
| 5549 |
{ |
| 5550 |
con_printf(CON_VERBOSE, "MultiLevelInv_Repopulate type: %i - Init: %i Cur: %i", i, MultiLevelInv.Initial[pi], MultiLevelInv.Current[pi]); |
| 5551 |
rt = 0; |
| 5552 |
maybe_drop_net_powerup(pi, 0, 1); |
| 5553 |
} |
| 5554 |
} |
| 5555 |
} |
| 5556 |
|
| 5557 |
} |
| 5558 |
|
| 5559 |
#if DXX_BUILD_DESCENT == 2 |
| 5560 |
namespace { |
| 5561 |
|
| 5562 |
/// |
| 5563 |
/// CODE TO LOAD HOARD DATA |
| 5564 |
/// |
| 5565 |
|
| 5566 |
class hoard_resources_type |
| 5567 |
{ |
| 5568 |
static constexpr std::integral_constant<bitmap_index, bitmap_index{UINT16_MAX}> invalid_bm_idx{}; |
| 5569 |
static constexpr auto invalid_snd_idx = std::integral_constant<unsigned, ~0u>{}; |
| 5570 |
public: |
| 5571 |
bitmap_index bm_idx = invalid_bm_idx; |
| 5572 |
unsigned snd_idx = invalid_snd_idx; |
| 5573 |
void reset(); |
| 5574 |
~hoard_resources_type() |
| 5575 |
{ |
| 5576 |
reset(); |
| 5577 |
} |
| 5578 |
}; |
| 5579 |
|
| 5580 |
static hoard_resources_type hoard_resources; |
| 5581 |
|
| 5582 |
} |
| 5583 |
|
| 5584 |
int HoardEquipped() |
| 5585 |
{ |
| 5586 |
static int checked=-1; |
| 5587 |
|
| 5588 |
if (unlikely(checked == -1)) |
| 5589 |
{ |
| 5590 |
checked = PHYSFSX_exists_ignorecase(hoard_ham_basename); |
| 5591 |
} |
| 5592 |
return (checked); |
| 5593 |
} |
| 5594 |
|
| 5595 |
std::array<grs_main_bitmap, 2> Orb_icons; |
| 5596 |
|
| 5597 |
void hoard_resources_type::reset() |
| 5598 |
{ |
| 5599 |
if (bm_idx != invalid_bm_idx) |
| 5600 |
d_free(GameBitmaps[std::exchange(bm_idx, invalid_bm_idx)].bm_mdata); |
| 5601 |
if (snd_idx != invalid_snd_idx) |
| 5602 |
{ |
| 5603 |
const auto idx = std::exchange(snd_idx, invalid_snd_idx); |
| 5604 |
range_for (auto &i, partial_range(GameSounds, idx, idx + 4)) |
| 5605 |
i.data.reset(); |
| 5606 |
} |
| 5607 |
range_for (auto &i, Orb_icons) |
| 5608 |
i.reset(); |
| 5609 |
} |
| 5610 |
|
| 5611 |
void init_hoard_data(d_vclip_array &Vclip) |
| 5612 |
{ |
| 5613 |
auto &Effects = LevelUniqueEffectsClipState.Effects; |
| 5614 |
hoard_resources.reset(); |
| 5615 |
unsigned n_orb_frames,n_goal_frames; |
| 5616 |
int orb_w,orb_h; |
| 5617 |
palette_array_t palette; |
| 5618 |
uint8_t *bitmap_data1; |
| 5619 |
int save_pos; |
| 5620 |
uint16_t bitmap_num = Num_bitmap_files; |
| 5621 |
hoard_resources.bm_idx = bitmap_index{bitmap_num}; |
| 5622 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 5623 |
|
| 5624 |
auto &&[ifile, physfserr] = PHYSFSX_openReadBuffered(hoard_ham_basename); |
| 5625 |
if (!ifile) |
| 5626 |
Error("Failed to open <hoard.ham>: %s", PHYSFS_getErrorByCode(physfserr)); |
| 5627 |
|
| 5628 |
n_orb_frames = PHYSFSX_readSLE16(ifile); |
| 5629 |
orb_w = PHYSFSX_readSLE16(ifile); |
| 5630 |
orb_h = PHYSFSX_readSLE16(ifile); |
| 5631 |
save_pos = PHYSFS_tell(ifile); |
| 5632 |
PHYSFSX_fseek(ifile,sizeof(palette)+n_orb_frames*orb_w*orb_h,SEEK_CUR); |
| 5633 |
n_goal_frames = PHYSFSX_readSLE16(ifile); |
| 5634 |
PHYSFS_seek(ifile, save_pos); |
| 5635 |
|
| 5636 |
//Allocate memory for bitmaps |
| 5637 |
MALLOC( bitmap_data1, ubyte, n_orb_frames*orb_w*orb_h + n_goal_frames*64*64 ); |
| 5638 |
|
| 5639 |
//Create orb vclip |
| 5640 |
const auto nvc = Vclip.valid_index(Num_vclips); |
| 5641 |
if (!nvc) |
| 5642 |
throw std::runtime_error("too many vclips"); |
| 5643 |
++ Num_vclips; |
| 5644 |
const auto orb_vclip{*nvc}; |
| 5645 |
auto &vcorb = Vclip[orb_vclip]; |
| 5646 |
vcorb.play_time = F1_0/2; |
| 5647 |
vcorb.num_frames = n_orb_frames; |
| 5648 |
vcorb.frame_time = vcorb.play_time / vcorb.num_frames; |
| 5649 |
vcorb.flags = 0; |
| 5650 |
vcorb.sound_num = sound_effect::None; |
| 5651 |
vcorb.light_value = F1_0; |
| 5652 |
for (auto &i : partial_range(vcorb.frames, n_orb_frames)) |
| 5653 |
{ |
| 5654 |
const bitmap_index bi{bitmap_num}; |
| 5655 |
i = bi; |
| 5656 |
gr_init_bitmap(GameBitmaps[bi], bm_mode::linear, 0, 0, orb_w, orb_h, orb_w, bitmap_data1); |
| 5657 |
gr_set_transparent(GameBitmaps[bi], 1); |
| 5658 |
bitmap_data1 += orb_w*orb_h; |
| 5659 |
bitmap_num++; |
| 5660 |
Assert(bitmap_num < MAX_BITMAP_FILES); |
| 5661 |
} |
| 5662 |
|
| 5663 |
//Create obj powerup |
| 5664 |
Powerup_info[powerup_type_t::POW_HOARD_ORB].vclip_num = orb_vclip; |
| 5665 |
Powerup_info[powerup_type_t::POW_HOARD_ORB].hit_sound = sound_effect::None; |
| 5666 |
Powerup_info[powerup_type_t::POW_HOARD_ORB].size = Powerup_info[powerup_type_t::POW_SHIELD_BOOST].size; |
| 5667 |
Powerup_info[powerup_type_t::POW_HOARD_ORB].light = Powerup_info[powerup_type_t::POW_SHIELD_BOOST].light; |
| 5668 |
|
| 5669 |
//Create orb goal wall effect |
| 5670 |
const auto goal_eclip = Num_effects++; |
| 5671 |
assert(goal_eclip < Effects.size()); |
| 5672 |
Effects[goal_eclip] = Effects[94]; //copy from blue goal |
| 5673 |
Effects[goal_eclip].changing_wall_texture = NumTextures; |
| 5674 |
Effects[goal_eclip].vc.num_frames=n_goal_frames; |
| 5675 |
|
| 5676 |
TmapInfo[NumTextures] = find_required_goal_texture(LevelUniqueTmapInfoState, tmapinfo_flag::goal_blue); |
| 5677 |
TmapInfo[NumTextures].eclip_num = goal_eclip; |
| 5678 |
TmapInfo[NumTextures].flags = static_cast<tmapinfo_flags>(tmapinfo_flag::goal_hoard); |
| 5679 |
NumTextures++; |
| 5680 |
Assert(NumTextures < MAX_TEXTURES); |
| 5681 |
range_for (auto &i, partial_range(Effects[goal_eclip].vc.frames, n_goal_frames)) |
| 5682 |
{ |
| 5683 |
const bitmap_index bi{bitmap_num}; |
| 5684 |
i = bi; |
| 5685 |
gr_init_bitmap(GameBitmaps[bi], bm_mode::linear, 0, 0, 64, 64, 64, bitmap_data1); |
| 5686 |
bitmap_data1 += 64*64; |
| 5687 |
bitmap_num++; |
| 5688 |
Assert(bitmap_num < MAX_BITMAP_FILES); |
| 5689 |
} |
| 5690 |
|
| 5691 |
//Load and remap bitmap data for orb |
| 5692 |
PHYSFSX_readBytes(ifile, palette, sizeof(palette[0]) * std::size(palette)); |
| 5693 |
range_for (auto &i, partial_const_range(vcorb.frames, n_orb_frames)) |
| 5694 |
{ |
| 5695 |
grs_bitmap *const bm = &GameBitmaps[i]; |
| 5696 |
PHYSFSX_readBytes(ifile, bm->get_bitmap_data(), orb_w * orb_h); |
| 5697 |
gr_remap_bitmap_good(*bm, palette, 255, -1); |
| 5698 |
} |
| 5699 |
|
| 5700 |
//Load and remap bitmap data for goal texture |
| 5701 |
PHYSFSX_skipBytes<2>(ifile); //skip frame count |
| 5702 |
PHYSFSX_readBytes(ifile, palette, sizeof(palette[0]) * std::size(palette)); |
| 5703 |
range_for (auto &i, partial_const_range(Effects[goal_eclip].vc.frames, n_goal_frames)) |
| 5704 |
{ |
| 5705 |
grs_bitmap *const bm = &GameBitmaps[i]; |
| 5706 |
PHYSFSX_readBytes(ifile, bm->get_bitmap_data(), 64 * 64); |
| 5707 |
gr_remap_bitmap_good(*bm, palette, 255, -1); |
| 5708 |
} |
| 5709 |
|
| 5710 |
//Load and remap bitmap data for HUD icons |
| 5711 |
range_for (auto &i, Orb_icons) |
| 5712 |
{ |
| 5713 |
const unsigned icon_w = PHYSFSX_readSLE16(ifile); |
| 5714 |
if (icon_w > 32) |
| 5715 |
return; |
| 5716 |
const unsigned icon_h = PHYSFSX_readSLE16(ifile); |
| 5717 |
if (icon_h > 32) |
| 5718 |
return; |
| 5719 |
const unsigned extent = icon_w * icon_h; |
| 5720 |
RAIIdmem<uint8_t[]> bitmap_data2; |
| 5721 |
MALLOC(bitmap_data2, uint8_t[], extent); |
| 5722 |
PHYSFSX_readBytes(ifile, palette, sizeof(palette[0]) * std::size(palette)); |
| 5723 |
PHYSFSX_readBytes(ifile, bitmap_data2.get(), extent); |
| 5724 |
gr_init_main_bitmap(i, bm_mode::linear, 0, 0, icon_w, icon_h, icon_w, std::move(bitmap_data2)); |
| 5725 |
gr_set_transparent(i, 1); |
| 5726 |
gr_remap_bitmap_good(i, palette, 255, -1); |
| 5727 |
} |
| 5728 |
|
| 5729 |
//Load sounds for orb game |
| 5730 |
hoard_resources.snd_idx = Num_sound_files; |
| 5731 |
const auto SndDigiSampleRate{GameArg.SndDigiSampleRate}; |
| 5732 |
range_for (const unsigned i, xrange(4u)) |
| 5733 |
{ |
| 5734 |
int len; |
| 5735 |
|
| 5736 |
len = PHYSFSX_readInt(ifile); //get 11k len |
| 5737 |
|
| 5738 |
if (SndDigiSampleRate == sound_sample_rate::_22k) |
| 5739 |
{ |
| 5740 |
PHYSFSX_fseek(ifile,len,SEEK_CUR); //skip over 11k sample |
| 5741 |
len = PHYSFSX_readInt(ifile); //get 22k len |
| 5742 |
} |
| 5743 |
|
| 5744 |
auto &gs = GameSounds[Num_sound_files+i]; |
| 5745 |
gs.length = len; |
| 5746 |
gs.data = digi_sound::allocated_data{std::make_unique<uint8_t[]>(len), game_sound_offset{}}; |
| 5747 |
PHYSFSX_readBytes(ifile, gs.data.get(), len); |
| 5748 |
|
| 5749 |
if (SndDigiSampleRate == sound_sample_rate::_11k) |
| 5750 |
{ |
| 5751 |
len = PHYSFSX_readInt(ifile); //get 22k len |
| 5752 |
PHYSFSX_fseek(ifile,len,SEEK_CUR); //skip over 22k sample |
| 5753 |
} |
| 5754 |
AltSounds[sound_effect::SOUND_YOU_GOT_ORB+i] = Sounds[sound_effect::SOUND_YOU_GOT_ORB+i] = static_cast<sound_effect>(Num_sound_files + i); |
| 5755 |
} |
| 5756 |
} |
| 5757 |
|
| 5758 |
#if DXX_USE_EDITOR |
| 5759 |
void save_hoard_data(void) |
| 5760 |
{ |
| 5761 |
static constexpr char sounds[][13] = {"selforb.raw","selforb.r22", //sound_effect::SOUND_YOU_GOT_ORB |
| 5762 |
"teamorb.raw","teamorb.r22", //sound_effect::SOUND_FRIEND_GOT_ORB |
| 5763 |
"enemyorb.raw","enemyorb.r22", //sound_effect::SOUND_OPPONENT_GOT_ORB |
| 5764 |
"OPSCORE1.raw","OPSCORE1.r22"}; //sound_effect::SOUND_OPPONENT_HAS_SCORED |
| 5765 |
auto ofile{PHYSFSX_openWriteBuffered(hoard_ham_basename).first}; |
| 5766 |
if (!ofile) |
| 5767 |
return; |
| 5768 |
|
| 5769 |
{ |
| 5770 |
const auto read_result = iff_read_animbrush("orb.abm"); |
| 5771 |
auto &bm = read_result.bm; |
| 5772 |
auto &palette = read_result.palette; |
| 5773 |
const auto nframes = read_result.n_bitmaps; |
| 5774 |
assert(read_result.status == iff_status_code::no_error); |
| 5775 |
PHYSFS_writeULE16(ofile, nframes); |
| 5776 |
PHYSFS_writeULE16(ofile, bm[0]->bm_w); |
| 5777 |
PHYSFS_writeULE16(ofile, bm[0]->bm_h); |
| 5778 |
PHYSFSX_writeBytes(ofile, palette.data(), sizeof(palette[0]) * palette.size()); |
| 5779 |
range_for (auto &i, partial_const_range(bm, nframes)) |
| 5780 |
PHYSFSX_writeBytes(ofile, i->bm_data, i->bm_w * i->bm_h); |
| 5781 |
} |
| 5782 |
|
| 5783 |
{ |
| 5784 |
const auto read_result = iff_read_animbrush("orbgoal.abm"); |
| 5785 |
auto &bm = read_result.bm; |
| 5786 |
auto &palette = read_result.palette; |
| 5787 |
const auto nframes = read_result.n_bitmaps; |
| 5788 |
assert(read_result.status == iff_status_code::no_error); |
| 5789 |
Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64); |
| 5790 |
PHYSFS_writeULE16(ofile, nframes); |
| 5791 |
PHYSFSX_writeBytes(ofile, palette.data(), sizeof(palette[0]) * palette.size()); |
| 5792 |
range_for (auto &i, partial_const_range(bm, nframes)) |
| 5793 |
PHYSFSX_writeBytes(ofile, i->bm_data, i->bm_w * i->bm_h); |
| 5794 |
} |
| 5795 |
|
| 5796 |
range_for (const unsigned i, xrange(2u)) |
| 5797 |
{ |
| 5798 |
palette_array_t palette; |
| 5799 |
grs_bitmap icon; |
| 5800 |
const auto iff_error{iff_read_bitmap(i ? "orbb.bbm" : "orb.bbm", icon, &palette)}; |
| 5801 |
(void)iff_error; |
| 5802 |
assert(iff_error == iff_status_code::no_error); |
| 5803 |
PHYSFS_writeULE16(ofile, icon.bm_w); |
| 5804 |
PHYSFS_writeULE16(ofile, icon.bm_h); |
| 5805 |
PHYSFSX_writeBytes(ofile, palette.data(), sizeof(palette[0]) * palette.size()); |
| 5806 |
PHYSFSX_writeBytes(ofile, icon.bm_data, icon.bm_w * icon.bm_h); |
| 5807 |
} |
| 5808 |
range_for (auto &i, sounds) |
| 5809 |
if (RAIIPHYSFS_File ifile{PHYSFS_openRead(i)}) |
| 5810 |
{ |
| 5811 |
int size; |
| 5812 |
size = PHYSFS_fileLength(ifile); |
| 5813 |
const auto buf = std::make_unique<uint8_t[]>(size); |
| 5814 |
PHYSFSX_readBytes(ifile, buf, size); |
| 5815 |
PHYSFS_writeULE32(ofile, size); |
| 5816 |
PHYSFSX_writeBytes(ofile, buf, size); |
| 5817 |
} |
| 5818 |
} |
| 5819 |
#endif |
| 5820 |
#endif |
| 5821 |
|
| 5822 |
namespace { |
| 5823 |
|
| 5824 |
static void multi_process_data(const d_level_shared_robot_info_state &LevelSharedRobotInfoState, const playernum_t pnum, const std::span<const uint8_t> data, const multiplayer_command_t type) |
| 5825 |
{ |
| 5826 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 5827 |
auto &imobjptridx = Objects.imptridx; |
| 5828 |
auto &vmobjptr = Objects.vmptr; |
| 5829 |
auto &vmobjptridx = Objects.vmptridx; |
| 5830 |
// Take an entire message (that has already been checked for validity, |
| 5831 |
// if necessary) and act on it. |
| 5832 |
auto &Walls = LevelUniqueWallSubsystemState.Walls; |
| 5833 |
auto &vmwallptr = Walls.vmptr; |
| 5834 |
switch (type) |
| 5835 |
{ |
| 5836 |
case multiplayer_command_t::MULTI_POSITION: |
| 5837 |
multi_do_position(Objects, pnum, multi_subspan_first<multiplayer_command_t::MULTI_POSITION>(data)); |
| 5838 |
break; |
| 5839 |
case multiplayer_command_t::MULTI_REAPPEAR: |
| 5840 |
multi_do_reappear(pnum, multi_subspan_first<multiplayer_command_t::MULTI_REAPPEAR>(data)); |
| 5841 |
break; |
| 5842 |
case multiplayer_command_t::MULTI_FIRE: |
| 5843 |
case multiplayer_command_t::MULTI_FIRE_TRACK: |
| 5844 |
case multiplayer_command_t::MULTI_FIRE_BOMB: |
| 5845 |
multi_do_fire(vmobjptridx, pnum, multi_subspan_first<multiplayer_command_t::MULTI_FIRE>(data), |
| 5846 |
type == multiplayer_command_t::MULTI_FIRE_TRACK |
| 5847 |
? objnum_remote_to_local(GET_INTEL_SHORT(&data[17]), data[19]) |
| 5848 |
: object_none, |
| 5849 |
type == multiplayer_command_t::MULTI_FIRE_BOMB |
| 5850 |
? std::optional(GET_INTEL_SHORT(&data[17])) |
| 5851 |
: std::nullopt); |
| 5852 |
break; |
| 5853 |
case multiplayer_command_t::MULTI_REMOVE_OBJECT: |
| 5854 |
multi_do_remobj(vmobjptr, multi_subspan_first<multiplayer_command_t::MULTI_REMOVE_OBJECT>(data)); |
| 5855 |
break; |
| 5856 |
case multiplayer_command_t::MULTI_PLAYER_DERES: |
| 5857 |
multi_do_player_deres(LevelSharedRobotInfoState.Robot_info, Objects, pnum, multi_subspan_first<multiplayer_command_t::MULTI_PLAYER_DERES>(data)); |
| 5858 |
break; |
| 5859 |
case multiplayer_command_t::MULTI_MESSAGE: |
| 5860 |
multi_do_message(pnum, multi_subspan_first<multiplayer_command_t::MULTI_MESSAGE>(data)); |
| 5861 |
break; |
| 5862 |
case multiplayer_command_t::MULTI_QUIT: |
| 5863 |
multi_do_quit(pnum); |
| 5864 |
break; |
| 5865 |
case multiplayer_command_t::MULTI_CONTROLCEN: |
| 5866 |
multi_do_controlcen_destroy(LevelSharedRobotInfoState.Robot_info, imobjptridx, multi_subspan_first<multiplayer_command_t::MULTI_CONTROLCEN>(data)); |
| 5867 |
break; |
| 5868 |
case multiplayer_command_t::MULTI_DROP_WEAPON: |
| 5869 |
multi_do_drop_weapon(vmobjptr, pnum, multi_subspan_first<multiplayer_command_t::MULTI_DROP_WEAPON>(data)); |
| 5870 |
break; |
| 5871 |
case multiplayer_command_t::MULTI_VULWPN_AMMO_ADJ: |
| 5872 |
multi_do_vulcan_weapon_ammo_adjust(vmobjptr, multi_subspan_first<multiplayer_command_t::MULTI_VULWPN_AMMO_ADJ>(data)); |
| 5873 |
break; |
| 5874 |
#if DXX_BUILD_DESCENT == 2 |
| 5875 |
case multiplayer_command_t::MULTI_SOUND_FUNCTION: |
| 5876 |
multi_do_sound_function(pnum, multi_subspan_first<multiplayer_command_t::MULTI_SOUND_FUNCTION>(data)); |
| 5877 |
break; |
| 5878 |
case multiplayer_command_t::MULTI_MARKER: |
| 5879 |
multi_do_drop_marker(Objects, vmsegptridx, pnum, multi_subspan_first<multiplayer_command_t::MULTI_MARKER>(data)); |
| 5880 |
break; |
| 5881 |
case multiplayer_command_t::MULTI_DROP_FLAG: |
| 5882 |
multi_do_drop_flag(pnum, multi_subspan_first<multiplayer_command_t::MULTI_DROP_FLAG>(data)); |
| 5883 |
break; |
| 5884 |
case multiplayer_command_t::MULTI_GUIDED: |
| 5885 |
multi_do_guided(LevelUniqueObjectState, pnum, multi_subspan_first<multiplayer_command_t::MULTI_GUIDED>(data)); |
| 5886 |
break; |
| 5887 |
case multiplayer_command_t::MULTI_STOLEN_ITEMS: |
| 5888 |
multi_do_stolen_items(LevelUniqueObjectState.ThiefState, multi_subspan_first<multiplayer_command_t::MULTI_STOLEN_ITEMS>(data)); |
| 5889 |
break; |
| 5890 |
case multiplayer_command_t::MULTI_WALL_STATUS: |
| 5891 |
multi_do_wall_status(vmwallptr, multi_subspan_first<multiplayer_command_t::MULTI_WALL_STATUS>(data)); |
| 5892 |
break; |
| 5893 |
case multiplayer_command_t::MULTI_SEISMIC: |
| 5894 |
multi_do_seismic(multi_subspan_first<multiplayer_command_t::MULTI_SEISMIC>(data)); |
| 5895 |
break; |
| 5896 |
case multiplayer_command_t::MULTI_LIGHT: |
| 5897 |
multi_do_light(multi_subspan_first<multiplayer_command_t::MULTI_LIGHT>(data)); |
| 5898 |
break; |
| 5899 |
#endif |
| 5900 |
case multiplayer_command_t::MULTI_ENDLEVEL_START: |
| 5901 |
multi_do_escape(vmobjptridx, pnum, multi_subspan_first<multiplayer_command_t::MULTI_ENDLEVEL_START>(data)); |
| 5902 |
break; |
| 5903 |
case multiplayer_command_t::MULTI_CLOAK: |
| 5904 |
multi_do_cloak(vmobjptr, pnum); |
| 5905 |
break; |
| 5906 |
case multiplayer_command_t::MULTI_DECLOAK: |
| 5907 |
multi_do_decloak(pnum); break; |
| 5908 |
case multiplayer_command_t::MULTI_DOOR_OPEN: |
| 5909 |
multi_do_door_open(vmwallptr, multi_subspan_first<multiplayer_command_t::MULTI_DOOR_OPEN>(data)); |
| 5910 |
break; |
| 5911 |
case multiplayer_command_t::MULTI_CREATE_EXPLOSION: |
| 5912 |
multi_do_create_explosion(vmobjptridx, pnum); |
| 5913 |
break; |
| 5914 |
case multiplayer_command_t::MULTI_CONTROLCEN_FIRE: |
| 5915 |
multi_do_controlcen_fire(multi_subspan_first<multiplayer_command_t::MULTI_CONTROLCEN_FIRE>(data)); |
| 5916 |
break; |
| 5917 |
case multiplayer_command_t::MULTI_CREATE_POWERUP: |
| 5918 |
multi_do_create_powerup(vmsegptridx, pnum, multi_subspan_first<multiplayer_command_t::MULTI_CREATE_POWERUP>(data)); |
| 5919 |
break; |
| 5920 |
case multiplayer_command_t::MULTI_PLAY_SOUND: |
| 5921 |
multi_do_play_sound(Objects, pnum, multi_subspan_first<multiplayer_command_t::MULTI_PLAY_SOUND>(data)); |
| 5922 |
break; |
| 5923 |
#if DXX_BUILD_DESCENT == 2 |
| 5924 |
case multiplayer_command_t::MULTI_CAPTURE_BONUS: |
| 5925 |
multi_do_capture_bonus(pnum); break; |
| 5926 |
case multiplayer_command_t::MULTI_ORB_BONUS: |
| 5927 |
multi_do_orb_bonus(pnum, multi_subspan_first<multiplayer_command_t::MULTI_ORB_BONUS>(data)); |
| 5928 |
break; |
| 5929 |
case multiplayer_command_t::MULTI_GOT_FLAG: |
| 5930 |
multi_do_got_flag(pnum); break; |
| 5931 |
case multiplayer_command_t::MULTI_GOT_ORB: |
| 5932 |
multi_do_got_orb(pnum); break; |
| 5933 |
case multiplayer_command_t::MULTI_FINISH_GAME: |
| 5934 |
multi_do_finish_game(); |
| 5935 |
break; // do this one regardless of endsequence |
| 5936 |
#endif |
| 5937 |
case multiplayer_command_t::MULTI_RANK: |
| 5938 |
multi_do_ranking (pnum, multi_subspan_first<multiplayer_command_t::MULTI_RANK>(data)); |
| 5939 |
break; |
| 5940 |
case multiplayer_command_t::MULTI_ROBOT_CLAIM: |
| 5941 |
multi_do_claim_robot(pnum, multi_subspan_first<multiplayer_command_t::MULTI_ROBOT_CLAIM>(data)); |
| 5942 |
break; |
| 5943 |
case multiplayer_command_t::MULTI_ROBOT_POSITION: |
| 5944 |
multi_do_robot_position(pnum, multi_subspan_first<multiplayer_command_t::MULTI_ROBOT_POSITION>(data)); |
| 5945 |
break; |
| 5946 |
case multiplayer_command_t::MULTI_ROBOT_EXPLODE: |
| 5947 |
multi_do_robot_explode(LevelSharedRobotInfoState.Robot_info, multi_subspan_first<multiplayer_command_t::MULTI_ROBOT_EXPLODE>(data)); |
| 5948 |
break; |
| 5949 |
case multiplayer_command_t::MULTI_ROBOT_RELEASE: |
| 5950 |
multi_do_release_robot(pnum, multi_subspan_first<multiplayer_command_t::MULTI_ROBOT_RELEASE>(data)); |
| 5951 |
break; |
| 5952 |
case multiplayer_command_t::MULTI_ROBOT_FIRE: |
| 5953 |
multi_do_robot_fire(multi_subspan_first<multiplayer_command_t::MULTI_ROBOT_FIRE>(data)); |
| 5954 |
break; |
| 5955 |
case multiplayer_command_t::MULTI_SCORE: |
| 5956 |
multi_do_score(vmobjptr, pnum, multi_subspan_first<multiplayer_command_t::MULTI_SCORE>(data)); |
| 5957 |
break; |
| 5958 |
case multiplayer_command_t::MULTI_CREATE_ROBOT: |
| 5959 |
multi_do_create_robot(LevelSharedRobotInfoState.Robot_info, Vclip, pnum, multi_subspan_first<multiplayer_command_t::MULTI_CREATE_ROBOT>(data)); |
| 5960 |
break; |
| 5961 |
case multiplayer_command_t::MULTI_TRIGGER: |
| 5962 |
multi_do_trigger(pnum, multi_subspan_first<multiplayer_command_t::MULTI_TRIGGER>(data)); |
| 5963 |
break; |
| 5964 |
#if DXX_BUILD_DESCENT == 2 |
| 5965 |
case multiplayer_command_t::MULTI_START_TRIGGER: |
| 5966 |
multi_do_start_trigger(multi_subspan_first<multiplayer_command_t::MULTI_START_TRIGGER>(data)); |
| 5967 |
break; |
| 5968 |
case multiplayer_command_t::MULTI_EFFECT_BLOWUP: |
| 5969 |
multi_do_effect_blowup(pnum, multi_subspan_first<multiplayer_command_t::MULTI_EFFECT_BLOWUP>(data)); |
| 5970 |
break; |
| 5971 |
case multiplayer_command_t::MULTI_FLAGS: |
| 5972 |
multi_do_flags(vmobjptr, pnum, multi_subspan_first<multiplayer_command_t::MULTI_FLAGS>(data)); |
| 5973 |
break; |
| 5974 |
case multiplayer_command_t::MULTI_DROP_BLOB: |
| 5975 |
multi_do_drop_blob(vmobjptr, pnum); |
| 5976 |
break; |
| 5977 |
case multiplayer_command_t::MULTI_UPDATE_BUDDY_STATE: |
| 5978 |
multi_recv_escort_goal(LevelUniqueObjectState.BuddyState, multi_subspan_first<multiplayer_command_t::MULTI_UPDATE_BUDDY_STATE>(data)); |
| 5979 |
break; |
| 5980 |
#endif |
| 5981 |
case multiplayer_command_t::MULTI_BOSS_TELEPORT: |
| 5982 |
multi_do_boss_teleport(LevelSharedRobotInfoState.Robot_info, Vclip, pnum, multi_subspan_first<multiplayer_command_t::MULTI_BOSS_TELEPORT>(data)); |
| 5983 |
break; |
| 5984 |
case multiplayer_command_t::MULTI_BOSS_CLOAK: |
| 5985 |
multi_do_boss_cloak(multi_subspan_first<multiplayer_command_t::MULTI_BOSS_CLOAK>(data)); |
| 5986 |
break; |
| 5987 |
case multiplayer_command_t::MULTI_BOSS_START_GATE: |
| 5988 |
multi_do_boss_start_gate(multi_subspan_first<multiplayer_command_t::MULTI_BOSS_START_GATE>(data)); |
| 5989 |
break; |
| 5990 |
case multiplayer_command_t::MULTI_BOSS_STOP_GATE: |
| 5991 |
multi_do_boss_stop_gate(multi_subspan_first<multiplayer_command_t::MULTI_BOSS_STOP_GATE>(data)); |
| 5992 |
break; |
| 5993 |
case multiplayer_command_t::MULTI_BOSS_CREATE_ROBOT: |
| 5994 |
multi_do_boss_create_robot(pnum, multi_subspan_first<multiplayer_command_t::MULTI_BOSS_CREATE_ROBOT>(data)); |
| 5995 |
break; |
| 5996 |
case multiplayer_command_t::MULTI_CREATE_ROBOT_POWERUPS: |
| 5997 |
multi_do_create_robot_powerups(pnum, multi_subspan_first<multiplayer_command_t::MULTI_CREATE_ROBOT_POWERUPS>(data)); |
| 5998 |
break; |
| 5999 |
case multiplayer_command_t::MULTI_HOSTAGE_DOOR: |
| 6000 |
multi_do_hostage_door_status(vmsegptridx, Walls, multi_subspan_first<multiplayer_command_t::MULTI_HOSTAGE_DOOR>(data)); |
| 6001 |
break; |
| 6002 |
case multiplayer_command_t::MULTI_SAVE_GAME: |
| 6003 |
multi_do_save_game(multi_subspan_first<multiplayer_command_t::MULTI_SAVE_GAME>(data)); |
| 6004 |
break; |
| 6005 |
case multiplayer_command_t::MULTI_RESTORE_GAME: |
| 6006 |
multi_do_restore_game(multi_subspan_first<multiplayer_command_t::MULTI_RESTORE_GAME>(data)); |
| 6007 |
break; |
| 6008 |
case multiplayer_command_t::MULTI_HEARTBEAT: |
| 6009 |
multi_do_heartbeat(multi_subspan_first<multiplayer_command_t::MULTI_HEARTBEAT>(data)); |
| 6010 |
break; |
| 6011 |
case multiplayer_command_t::MULTI_KILLGOALS: |
| 6012 |
multi_do_kill_goal_counts(vmobjptr, multi_subspan_first<multiplayer_command_t::MULTI_KILLGOALS>(data)); |
| 6013 |
break; |
| 6014 |
case multiplayer_command_t::MULTI_DO_BOUNTY: |
| 6015 |
multi_do_bounty(multi_subspan_first<multiplayer_command_t::MULTI_DO_BOUNTY>(data)); |
| 6016 |
break; |
| 6017 |
case multiplayer_command_t::MULTI_TYPING_STATE: |
| 6018 |
multi_do_msgsend_state(pnum, multi_subspan_first<multiplayer_command_t::MULTI_TYPING_STATE>(data)); |
| 6019 |
break; |
| 6020 |
case multiplayer_command_t::MULTI_GMODE_UPDATE: |
| 6021 |
multi_do_gmode_update(multi_subspan_first<multiplayer_command_t::MULTI_GMODE_UPDATE>(data)); |
| 6022 |
break; |
| 6023 |
case multiplayer_command_t::MULTI_KILL_HOST: |
| 6024 |
multi_do_kill_host(Objects, pnum, multi_subspan_first<multiplayer_command_t::MULTI_KILL_HOST>(data)); |
| 6025 |
break; |
| 6026 |
case multiplayer_command_t::MULTI_KILL_CLIENT: |
| 6027 |
multi_do_kill_client(Objects, pnum, multi_subspan_first<multiplayer_command_t::MULTI_KILL_CLIENT>(data)); |
| 6028 |
break; |
| 6029 |
case multiplayer_command_t::MULTI_PLAYER_INV: |
| 6030 |
multi_do_player_inventory(pnum, multi_subspan_first<multiplayer_command_t::MULTI_PLAYER_INV>(data)); |
| 6031 |
break; |
| 6032 |
} |
| 6033 |
} |
| 6034 |
|
| 6035 |
} |
| 6036 |
|
| 6037 |
// Following functions convert object to object_rw and back. |
| 6038 |
// turn object to object_rw for sending |
| 6039 |
void multi_object_to_object_rw(const object &obj, object_rw *obj_rw) |
| 6040 |
{ |
| 6041 |
/* Avoid leaking any uninitialized bytes onto the network. Some of |
| 6042 |
* the unions are incompletely initialized for some branches. |
| 6043 |
* |
| 6044 |
* For poison enabled builds, poison any uninitialized fields. |
| 6045 |
* Everything that the peer should read will be initialized by the |
| 6046 |
* end of this function. |
| 6047 |
*/ |
| 6048 |
*obj_rw = {}; |
| 6049 |
DXX_POISON_DEFINED_VAR(*obj_rw, 0xfd); |
| 6050 |
obj_rw->signature = INTEL_SHORT(static_cast<uint16_t>(obj.signature)); |
| 6051 |
obj_rw->type = obj.type; |
| 6052 |
obj_rw->id = obj.id; |
| 6053 |
/* next, prev not maintained here */ |
| 6054 |
obj_rw->control_source = underlying_value(obj.control_source); |
| 6055 |
obj_rw->movement_source = underlying_value(obj.movement_source); |
| 6056 |
const auto rtype = obj.render_type; |
| 6057 |
obj_rw->render_type = underlying_value(rtype); |
| 6058 |
obj_rw->flags = obj.flags; |
| 6059 |
obj_rw->segnum = INTEL_SHORT(obj.segnum); |
| 6060 |
/* attached_obj not maintained here */ |
| 6061 |
{ |
| 6062 |
const auto pos = build_little_endian_vector_from_native_endian(obj.pos); |
| 6063 |
obj_rw->pos = pos; |
| 6064 |
obj_rw->last_pos = pos; |
| 6065 |
} |
| 6066 |
obj_rw->orient = build_little_endian_matrix_from_native_endian(obj.orient); |
| 6067 |
obj_rw->size = INTEL_INT(obj.size); |
| 6068 |
obj_rw->shields = INTEL_INT(obj.shields); |
| 6069 |
obj_rw->contains_type = underlying_value(obj.contains.type); |
| 6070 |
obj_rw->contains_id = underlying_value(obj.contains.id.robot); |
| 6071 |
obj_rw->contains_count= obj.contains.count; |
| 6072 |
obj_rw->matcen_creator= obj.matcen_creator; |
| 6073 |
obj_rw->lifeleft = INTEL_INT(obj.lifeleft); |
| 6074 |
|
| 6075 |
switch (typename object::movement_type{obj_rw->movement_source}) |
| 6076 |
{ |
| 6077 |
case object::movement_type::None: |
| 6078 |
obj_rw->mtype = {}; |
| 6079 |
break; |
| 6080 |
case object::movement_type::physics: |
| 6081 |
obj_rw->mtype.phys_info.velocity = build_little_endian_vector_from_native_endian(obj.mtype.phys_info.velocity); |
| 6082 |
obj_rw->mtype.phys_info.thrust = build_little_endian_vector_from_native_endian(obj.mtype.phys_info.thrust); |
| 6083 |
obj_rw->mtype.phys_info.mass = INTEL_INT(obj.mtype.phys_info.mass); |
| 6084 |
obj_rw->mtype.phys_info.drag = INTEL_INT(obj.mtype.phys_info.drag); |
| 6085 |
obj_rw->mtype.phys_info.rotvel = build_little_endian_vector_from_native_endian(obj.mtype.phys_info.rotvel); |
| 6086 |
obj_rw->mtype.phys_info.rotthrust = build_little_endian_vector_from_native_endian(obj.mtype.phys_info.rotthrust); |
| 6087 |
obj_rw->mtype.phys_info.turnroll = INTEL_INT(obj.mtype.phys_info.turnroll); |
| 6088 |
obj_rw->mtype.phys_info.flags = INTEL_SHORT(obj.mtype.phys_info.flags); |
| 6089 |
break; |
| 6090 |
|
| 6091 |
case object::movement_type::spinning: |
| 6092 |
obj_rw->mtype.spin_rate = build_little_endian_vector_from_native_endian(obj.mtype.spin_rate); |
| 6093 |
break; |
| 6094 |
} |
| 6095 |
|
| 6096 |
switch (typename object::control_type{obj_rw->control_source}) |
| 6097 |
{ |
| 6098 |
case object::control_type::weapon: |
| 6099 |
obj_rw->ctype.laser_info.parent_type = INTEL_SHORT(obj.ctype.laser_info.parent_type); |
| 6100 |
obj_rw->ctype.laser_info.parent_num = INTEL_SHORT(obj.ctype.laser_info.parent_num); |
| 6101 |
obj_rw->ctype.laser_info.parent_signature = INTEL_INT(static_cast<uint16_t>(obj.ctype.laser_info.parent_signature)); |
| 6102 |
if (const auto c = obj.ctype.laser_info.creation_time - GameTime64; c < F1_0*(-18000)) |
| 6103 |
obj_rw->ctype.laser_info.creation_time = INTEL_INT(F1_0*(-18000)); |
| 6104 |
else |
| 6105 |
obj_rw->ctype.laser_info.creation_time = INTEL_INT(static_cast<int>(c)); |
| 6106 |
obj_rw->ctype.laser_info.last_hitobj = INTEL_SHORT(obj.ctype.laser_info.get_last_hitobj()); |
| 6107 |
obj_rw->ctype.laser_info.track_goal = INTEL_SHORT(obj.ctype.laser_info.track_goal); |
| 6108 |
obj_rw->ctype.laser_info.multiplier = INTEL_INT(obj.ctype.laser_info.multiplier); |
| 6109 |
break; |
| 6110 |
|
| 6111 |
case object::control_type::explosion: |
| 6112 |
obj_rw->ctype.expl_info.spawn_time = INTEL_INT(obj.ctype.expl_info.spawn_time); |
| 6113 |
obj_rw->ctype.expl_info.delete_time = INTEL_INT(obj.ctype.expl_info.delete_time); |
| 6114 |
obj_rw->ctype.expl_info.delete_objnum = INTEL_SHORT(obj.ctype.expl_info.delete_objnum); |
| 6115 |
obj_rw->ctype.expl_info.attach_parent = INTEL_SHORT(obj.ctype.expl_info.attach_parent); |
| 6116 |
obj_rw->ctype.expl_info.prev_attach = INTEL_SHORT(obj.ctype.expl_info.prev_attach); |
| 6117 |
obj_rw->ctype.expl_info.next_attach = INTEL_SHORT(obj.ctype.expl_info.next_attach); |
| 6118 |
break; |
| 6119 |
|
| 6120 |
case object::control_type::ai: |
| 6121 |
{ |
| 6122 |
obj_rw->ctype.ai_info.behavior = static_cast<uint8_t>(obj.ctype.ai_info.behavior); |
| 6123 |
obj_rw->ctype.ai_info.flags[0] = underlying_value(obj.ctype.ai_info.CURRENT_GUN); |
| 6124 |
obj_rw->ctype.ai_info.flags[1] = obj.ctype.ai_info.CURRENT_STATE; |
| 6125 |
obj_rw->ctype.ai_info.flags[2] = obj.ctype.ai_info.GOAL_STATE; |
| 6126 |
obj_rw->ctype.ai_info.flags[3] = obj.ctype.ai_info.PATH_DIR; |
| 6127 |
#if DXX_BUILD_DESCENT == 1 |
| 6128 |
obj_rw->ctype.ai_info.flags[4] = obj.ctype.ai_info.SUBMODE; |
| 6129 |
#elif DXX_BUILD_DESCENT == 2 |
| 6130 |
obj_rw->ctype.ai_info.flags[4] = obj.ctype.ai_info.SUB_FLAGS; |
| 6131 |
#endif |
| 6132 |
obj_rw->ctype.ai_info.flags[5] = underlying_value(obj.ctype.ai_info.GOALSIDE); |
| 6133 |
obj_rw->ctype.ai_info.flags[6] = obj.ctype.ai_info.CLOAKED; |
| 6134 |
obj_rw->ctype.ai_info.flags[7] = obj.ctype.ai_info.SKIP_AI_COUNT; |
| 6135 |
obj_rw->ctype.ai_info.flags[8] = obj.ctype.ai_info.REMOTE_OWNER; |
| 6136 |
obj_rw->ctype.ai_info.flags[9] = obj.ctype.ai_info.REMOTE_SLOT_NUM; |
| 6137 |
obj_rw->ctype.ai_info.hide_segment = INTEL_SHORT(obj.ctype.ai_info.hide_segment); |
| 6138 |
obj_rw->ctype.ai_info.hide_index = INTEL_SHORT(obj.ctype.ai_info.hide_index); |
| 6139 |
obj_rw->ctype.ai_info.path_length = INTEL_SHORT(obj.ctype.ai_info.path_length); |
| 6140 |
#if DXX_BUILD_DESCENT == 1 |
| 6141 |
obj_rw->ctype.ai_info.cur_path_index = INTEL_SHORT(obj.ctype.ai_info.cur_path_index); |
| 6142 |
#elif DXX_BUILD_DESCENT == 2 |
| 6143 |
obj_rw->ctype.ai_info.cur_path_index = obj.ctype.ai_info.cur_path_index; |
| 6144 |
#endif |
| 6145 |
obj_rw->ctype.ai_info.danger_laser_num = INTEL_SHORT(obj.ctype.ai_info.danger_laser_num); |
| 6146 |
if (obj.ctype.ai_info.danger_laser_num != object_none) |
| 6147 |
obj_rw->ctype.ai_info.danger_laser_signature = INTEL_INT(static_cast<uint16_t>(obj.ctype.ai_info.danger_laser_signature)); |
| 6148 |
else |
| 6149 |
obj_rw->ctype.ai_info.danger_laser_signature = 0; |
| 6150 |
#if DXX_BUILD_DESCENT == 1 |
| 6151 |
obj_rw->ctype.ai_info.follow_path_start_seg = segment_none; |
| 6152 |
obj_rw->ctype.ai_info.follow_path_end_seg = segment_none; |
| 6153 |
#elif DXX_BUILD_DESCENT == 2 |
| 6154 |
obj_rw->ctype.ai_info.dying_sound_playing = obj.ctype.ai_info.dying_sound_playing; |
| 6155 |
if (obj.ctype.ai_info.dying_start_time == 0) // if bot not dead, anything but 0 will kill it |
| 6156 |
obj_rw->ctype.ai_info.dying_start_time = 0; |
| 6157 |
else |
| 6158 |
obj_rw->ctype.ai_info.dying_start_time = INTEL_INT(static_cast<int>(obj.ctype.ai_info.dying_start_time - GameTime64)); |
| 6159 |
#endif |
| 6160 |
break; |
| 6161 |
} |
| 6162 |
|
| 6163 |
case object::control_type::light: |
| 6164 |
obj_rw->ctype.light_info.intensity = INTEL_INT(obj.ctype.light_info.intensity); |
| 6165 |
break; |
| 6166 |
|
| 6167 |
case object::control_type::powerup: |
| 6168 |
obj_rw->ctype.powerup_info.count = INTEL_INT(obj.ctype.powerup_info.count); |
| 6169 |
#if DXX_BUILD_DESCENT == 2 |
| 6170 |
if (const auto c = obj.ctype.powerup_info.creation_time - GameTime64; c < F1_0*(-18000)) |
| 6171 |
obj_rw->ctype.powerup_info.creation_time = INTEL_INT(F1_0*(-18000)); |
| 6172 |
else |
| 6173 |
obj_rw->ctype.powerup_info.creation_time = INTEL_INT(static_cast<int>(c)); |
| 6174 |
obj_rw->ctype.powerup_info.flags = INTEL_INT(obj.ctype.powerup_info.flags); |
| 6175 |
#endif |
| 6176 |
break; |
| 6177 |
case object::control_type::None: |
| 6178 |
case object::control_type::flying: |
| 6179 |
case object::control_type::slew: |
| 6180 |
case object::control_type::flythrough: |
| 6181 |
case object::control_type::repaircen: |
| 6182 |
case object::control_type::morph: |
| 6183 |
case object::control_type::debris: |
| 6184 |
case object::control_type::remote: |
| 6185 |
default: |
| 6186 |
break; |
| 6187 |
} |
| 6188 |
|
| 6189 |
switch (rtype) |
| 6190 |
{ |
| 6191 |
case render_type::RT_NONE: |
| 6192 |
if (obj.type != OBJ_GHOST) // HACK: when a player is dead or not connected yet, clients still expect to get polyobj data - even if render_type == RT_NONE at this time. |
| 6193 |
break; |
| 6194 |
[[fallthrough]]; |
| 6195 |
case render_type::RT_MORPH: |
| 6196 |
case render_type::RT_POLYOBJ: |
| 6197 |
{ |
| 6198 |
int i; |
| 6199 |
obj_rw->rtype.pobj_info.model_num = INTEL_INT(underlying_value(obj.rtype.pobj_info.model_num)); |
| 6200 |
for (i=0;i<MAX_SUBMODELS;i++) |
| 6201 |
obj_rw->rtype.pobj_info.anim_angles[i] = build_little_endian_angvec_from_native_endian(obj.rtype.pobj_info.anim_angles[i]); |
| 6202 |
obj_rw->rtype.pobj_info.subobj_flags = INTEL_INT(obj.rtype.pobj_info.subobj_flags); |
| 6203 |
obj_rw->rtype.pobj_info.tmap_override = INTEL_INT(obj.rtype.pobj_info.tmap_override); |
| 6204 |
obj_rw->rtype.pobj_info.alt_textures = INTEL_INT(obj.rtype.pobj_info.alt_textures); |
| 6205 |
break; |
| 6206 |
} |
| 6207 |
|
| 6208 |
case render_type::RT_WEAPON_VCLIP: |
| 6209 |
case render_type::RT_HOSTAGE: |
| 6210 |
case render_type::RT_POWERUP: |
| 6211 |
case render_type::RT_FIREBALL: |
| 6212 |
obj_rw->rtype.vclip_info.vclip_num = INTEL_INT(underlying_value(obj.rtype.vclip_info.vclip_num)); |
| 6213 |
obj_rw->rtype.vclip_info.frametime = INTEL_INT(obj.rtype.vclip_info.frametime); |
| 6214 |
obj_rw->rtype.vclip_info.framenum = obj.rtype.vclip_info.framenum; |
| 6215 |
break; |
| 6216 |
|
| 6217 |
case render_type::RT_LASER: |
| 6218 |
break; |
| 6219 |
|
| 6220 |
} |
| 6221 |
} |
| 6222 |
|
| 6223 |
// turn object_rw to object after receiving |
| 6224 |
void multi_object_rw_to_object(const object_rw *const obj_rw, object &obj) |
| 6225 |
{ |
| 6226 |
obj = {}; |
| 6227 |
DXX_POISON_VAR(obj, 0xfd); |
| 6228 |
set_object_type(obj, obj_rw->type); |
| 6229 |
if (obj.type == OBJ_NONE) |
| 6230 |
return; |
| 6231 |
obj.signature = object_signature_t{static_cast<uint16_t>(INTEL_INT(obj_rw->signature))}; |
| 6232 |
obj.id = obj_rw->id; |
| 6233 |
/* obj->next,obj->prev handled by caller based on segment */ |
| 6234 |
obj.control_source = typename object::control_type{obj_rw->control_source}; |
| 6235 |
obj.movement_source = typename object::movement_type{obj_rw->movement_source}; |
| 6236 |
if (const auto rtype = obj_rw->render_type; valid_render_type(rtype)) |
| 6237 |
obj.render_type = render_type{rtype}; |
| 6238 |
else |
| 6239 |
{ |
| 6240 |
con_printf(CON_URGENT, "peer sent bogus render type %#x for object %p; using none instead", rtype, &obj); |
| 6241 |
obj.render_type = render_type::RT_NONE; |
| 6242 |
} |
| 6243 |
obj.flags = obj_rw->flags; |
| 6244 |
obj.segnum = vmsegidx_t::check_nothrow_index(INTEL_SHORT(obj_rw->segnum)).value_or(segment_none); |
| 6245 |
obj.attached_obj = object_none; |
| 6246 |
obj.pos = build_native_endian_vector_from_little_endian(obj_rw->pos); |
| 6247 |
obj.orient = build_native_endian_matrix_from_little_endian(obj_rw->orient); |
| 6248 |
obj.size = INTEL_INT(obj_rw->size); |
| 6249 |
obj.shields = INTEL_INT(obj_rw->shields); |
| 6250 |
obj.contains = build_contained_object_parameters_from_untrusted(obj_rw->contains_type, obj_rw->contains_id, obj_rw->contains_count); |
| 6251 |
obj.matcen_creator= obj_rw->matcen_creator; |
| 6252 |
obj.lifeleft = INTEL_INT(obj_rw->lifeleft); |
| 6253 |
|
| 6254 |
switch (obj.movement_source) |
| 6255 |
{ |
| 6256 |
case object::movement_type::None: |
| 6257 |
break; |
| 6258 |
case object::movement_type::physics: |
| 6259 |
obj.mtype.phys_info.velocity = build_native_endian_vector_from_little_endian(obj_rw->mtype.phys_info.velocity); |
| 6260 |
obj.mtype.phys_info.thrust = build_native_endian_vector_from_little_endian(obj_rw->mtype.phys_info.thrust); |
| 6261 |
obj.mtype.phys_info.mass = INTEL_INT(obj_rw->mtype.phys_info.mass); |
| 6262 |
obj.mtype.phys_info.drag = INTEL_INT(obj_rw->mtype.phys_info.drag); |
| 6263 |
obj.mtype.phys_info.rotvel = build_native_endian_vector_from_little_endian(obj_rw->mtype.phys_info.rotvel); |
| 6264 |
obj.mtype.phys_info.rotthrust = build_native_endian_vector_from_little_endian(obj_rw->mtype.phys_info.rotthrust); |
| 6265 |
obj.mtype.phys_info.turnroll = INTEL_INT(obj_rw->mtype.phys_info.turnroll); |
| 6266 |
obj.mtype.phys_info.flags = INTEL_INT(obj_rw->mtype.phys_info.flags); |
| 6267 |
break; |
| 6268 |
|
| 6269 |
case object::movement_type::spinning: |
| 6270 |
obj.mtype.spin_rate = build_native_endian_vector_from_little_endian(obj_rw->mtype.spin_rate); |
| 6271 |
break; |
| 6272 |
} |
| 6273 |
|
| 6274 |
switch (obj.control_source) |
| 6275 |
{ |
| 6276 |
case object::control_type::weapon: |
| 6277 |
obj.ctype.laser_info.parent_type = INTEL_SHORT(obj_rw->ctype.laser_info.parent_type); |
| 6278 |
obj.ctype.laser_info.parent_num = INTEL_SHORT(obj_rw->ctype.laser_info.parent_num); |
| 6279 |
obj.ctype.laser_info.parent_signature = object_signature_t{static_cast<uint16_t>(INTEL_INT(obj_rw->ctype.laser_info.parent_signature))}; |
| 6280 |
obj.ctype.laser_info.creation_time = INTEL_INT(obj_rw->ctype.laser_info.creation_time); |
| 6281 |
/* `last_hitobj` is untrusted network data, so it must be checked before use. */ |
| 6282 |
if (const auto last_hitobj{vcobjidx_t::check_nothrow_index(INTEL_SHORT(obj_rw->ctype.laser_info.last_hitobj))}) |
| 6283 |
obj.ctype.laser_info.reset_hitobj(*last_hitobj); |
| 6284 |
else |
| 6285 |
obj.ctype.laser_info.clear_hitobj(); |
| 6286 |
obj.ctype.laser_info.track_goal = INTEL_SHORT(obj_rw->ctype.laser_info.track_goal); |
| 6287 |
obj.ctype.laser_info.multiplier = INTEL_INT(obj_rw->ctype.laser_info.multiplier); |
| 6288 |
#if DXX_BUILD_DESCENT == 2 |
| 6289 |
obj.ctype.laser_info.last_afterburner_time = 0; |
| 6290 |
#endif |
| 6291 |
break; |
| 6292 |
|
| 6293 |
case object::control_type::explosion: |
| 6294 |
obj.ctype.expl_info.spawn_time = INTEL_INT(obj_rw->ctype.expl_info.spawn_time); |
| 6295 |
obj.ctype.expl_info.delete_time = INTEL_INT(obj_rw->ctype.expl_info.delete_time); |
| 6296 |
obj.ctype.expl_info.delete_objnum = INTEL_SHORT(obj_rw->ctype.expl_info.delete_objnum); |
| 6297 |
obj.ctype.expl_info.attach_parent = INTEL_SHORT(obj_rw->ctype.expl_info.attach_parent); |
| 6298 |
obj.ctype.expl_info.prev_attach = INTEL_SHORT(obj_rw->ctype.expl_info.prev_attach); |
| 6299 |
obj.ctype.expl_info.next_attach = INTEL_SHORT(obj_rw->ctype.expl_info.next_attach); |
| 6300 |
break; |
| 6301 |
|
| 6302 |
case object::control_type::ai: |
| 6303 |
{ |
| 6304 |
obj.ctype.ai_info.behavior = static_cast<ai_behavior>(obj_rw->ctype.ai_info.behavior); |
| 6305 |
{ |
| 6306 |
const uint8_t gun_num = obj_rw->ctype.ai_info.flags[0]; |
| 6307 |
obj.ctype.ai_info.CURRENT_GUN = (gun_num < MAX_GUNS) ? robot_gun_number{gun_num} : robot_gun_number{}; |
| 6308 |
} |
| 6309 |
obj.ctype.ai_info.CURRENT_STATE = build_ai_state_from_untrusted(obj_rw->ctype.ai_info.flags[1]).value(); |
| 6310 |
obj.ctype.ai_info.GOAL_STATE = build_ai_state_from_untrusted(obj_rw->ctype.ai_info.flags[2]).value(); |
| 6311 |
obj.ctype.ai_info.PATH_DIR = obj_rw->ctype.ai_info.flags[3]; |
| 6312 |
#if DXX_BUILD_DESCENT == 1 |
| 6313 |
obj.ctype.ai_info.SUBMODE = obj_rw->ctype.ai_info.flags[4]; |
| 6314 |
#elif DXX_BUILD_DESCENT == 2 |
| 6315 |
obj.ctype.ai_info.SUB_FLAGS = obj_rw->ctype.ai_info.flags[4]; |
| 6316 |
#endif |
| 6317 |
obj.ctype.ai_info.GOALSIDE = build_sidenum_from_untrusted(obj_rw->ctype.ai_info.flags[5]).value(); |
| 6318 |
obj.ctype.ai_info.CLOAKED = obj_rw->ctype.ai_info.flags[6]; |
| 6319 |
obj.ctype.ai_info.SKIP_AI_COUNT = obj_rw->ctype.ai_info.flags[7]; |
| 6320 |
obj.ctype.ai_info.REMOTE_OWNER = obj_rw->ctype.ai_info.flags[8]; |
| 6321 |
obj.ctype.ai_info.REMOTE_SLOT_NUM = obj_rw->ctype.ai_info.flags[9]; |
| 6322 |
obj.ctype.ai_info.hide_segment = vmsegidx_t::check_nothrow_index(INTEL_SHORT(obj_rw->ctype.ai_info.hide_segment)).value_or(segment_none); |
| 6323 |
obj.ctype.ai_info.hide_index = INTEL_SHORT(obj_rw->ctype.ai_info.hide_index); |
| 6324 |
obj.ctype.ai_info.path_length = INTEL_SHORT(obj_rw->ctype.ai_info.path_length); |
| 6325 |
obj.ctype.ai_info.cur_path_index = |
| 6326 |
#if DXX_BUILD_DESCENT == 1 |
| 6327 |
INTEL_SHORT(obj_rw->ctype.ai_info.cur_path_index); |
| 6328 |
#elif DXX_BUILD_DESCENT == 2 |
| 6329 |
obj_rw->ctype.ai_info.cur_path_index; |
| 6330 |
#endif |
| 6331 |
obj.ctype.ai_info.danger_laser_num = INTEL_SHORT(obj_rw->ctype.ai_info.danger_laser_num); |
| 6332 |
if (obj.ctype.ai_info.danger_laser_num != object_none) |
| 6333 |
obj.ctype.ai_info.danger_laser_signature = object_signature_t{static_cast<uint16_t>(INTEL_INT(obj_rw->ctype.ai_info.danger_laser_signature))}; |
| 6334 |
#if DXX_BUILD_DESCENT == 1 |
| 6335 |
#elif DXX_BUILD_DESCENT == 2 |
| 6336 |
obj.ctype.ai_info.dying_sound_playing = obj_rw->ctype.ai_info.dying_sound_playing; |
| 6337 |
obj.ctype.ai_info.dying_start_time = INTEL_INT(obj_rw->ctype.ai_info.dying_start_time); |
| 6338 |
#endif |
| 6339 |
break; |
| 6340 |
} |
| 6341 |
|
| 6342 |
case object::control_type::light: |
| 6343 |
obj.ctype.light_info.intensity = INTEL_INT(obj_rw->ctype.light_info.intensity); |
| 6344 |
break; |
| 6345 |
|
| 6346 |
case object::control_type::powerup: |
| 6347 |
obj.ctype.powerup_info.count = INTEL_INT(obj_rw->ctype.powerup_info.count); |
| 6348 |
#if DXX_BUILD_DESCENT == 1 |
| 6349 |
obj.ctype.powerup_info.creation_time = 0; |
| 6350 |
obj.ctype.powerup_info.flags = 0; |
| 6351 |
#elif DXX_BUILD_DESCENT == 2 |
| 6352 |
obj.ctype.powerup_info.creation_time = INTEL_INT(obj_rw->ctype.powerup_info.creation_time); |
| 6353 |
obj.ctype.powerup_info.flags = INTEL_INT(obj_rw->ctype.powerup_info.flags); |
| 6354 |
#endif |
| 6355 |
break; |
| 6356 |
case object::control_type::cntrlcen: |
| 6357 |
{ |
| 6358 |
// gun points of reactor now part of the object but of course not saved in object_rw. Let's just recompute them. |
| 6359 |
calc_controlcen_gun_point(obj); |
| 6360 |
break; |
| 6361 |
} |
| 6362 |
case object::control_type::None: |
| 6363 |
case object::control_type::flying: |
| 6364 |
case object::control_type::slew: |
| 6365 |
case object::control_type::flythrough: |
| 6366 |
case object::control_type::repaircen: |
| 6367 |
case object::control_type::morph: |
| 6368 |
case object::control_type::debris: |
| 6369 |
case object::control_type::remote: |
| 6370 |
default: |
| 6371 |
break; |
| 6372 |
} |
| 6373 |
|
| 6374 |
switch (obj.render_type) |
| 6375 |
{ |
| 6376 |
case render_type::RT_NONE: |
| 6377 |
if (obj.type != OBJ_GHOST) // HACK: when a player is dead or not connected yet, clients still expect to get polyobj data - even if render_type == RT_NONE at this time. |
| 6378 |
break; |
| 6379 |
[[fallthrough]]; |
| 6380 |
case render_type::RT_MORPH: |
| 6381 |
case render_type::RT_POLYOBJ: |
| 6382 |
{ |
| 6383 |
int i; |
| 6384 |
obj.rtype.pobj_info.model_num = build_polygon_model_index_from_untrusted(INTEL_INT(obj_rw->rtype.pobj_info.model_num)); |
| 6385 |
for (i=0;i<MAX_SUBMODELS;i++) |
| 6386 |
{ |
| 6387 |
obj.rtype.pobj_info.anim_angles[i] = build_native_endian_angvec_from_little_endian(obj_rw->rtype.pobj_info.anim_angles[i]); |
| 6388 |
} |
| 6389 |
obj.rtype.pobj_info.subobj_flags = INTEL_INT(obj_rw->rtype.pobj_info.subobj_flags); |
| 6390 |
obj.rtype.pobj_info.tmap_override = INTEL_INT(obj_rw->rtype.pobj_info.tmap_override); |
| 6391 |
obj.rtype.pobj_info.alt_textures = INTEL_INT(obj_rw->rtype.pobj_info.alt_textures); |
| 6392 |
break; |
| 6393 |
} |
| 6394 |
|
| 6395 |
case render_type::RT_WEAPON_VCLIP: |
| 6396 |
case render_type::RT_HOSTAGE: |
| 6397 |
case render_type::RT_POWERUP: |
| 6398 |
case render_type::RT_FIREBALL: |
| 6399 |
obj.rtype.vclip_info.vclip_num = build_vclip_index_from_untrusted(INTEL_INT(obj_rw->rtype.vclip_info.vclip_num)); |
| 6400 |
obj.rtype.vclip_info.frametime = INTEL_INT(obj_rw->rtype.vclip_info.frametime); |
| 6401 |
obj.rtype.vclip_info.framenum = obj_rw->rtype.vclip_info.framenum; |
| 6402 |
break; |
| 6403 |
|
| 6404 |
case render_type::RT_LASER: |
| 6405 |
break; |
| 6406 |
|
| 6407 |
} |
| 6408 |
} |
| 6409 |
|
| 6410 |
void show_netgame_info(const netgame_info &netgame) |
| 6411 |
{ |
| 6412 |
struct netgame_info_menu_items |
| 6413 |
{ |
| 6414 |
enum netgame_menu_info_index |
| 6415 |
{ |
| 6416 |
game_name, |
| 6417 |
mission_name, |
| 6418 |
level_number, |
| 6419 |
game_mode, |
| 6420 |
player_counts, |
| 6421 |
blank_1, |
| 6422 |
game_options_header, |
| 6423 |
difficulty, |
| 6424 |
reactor_life, |
| 6425 |
max_time, |
| 6426 |
kill_goal, |
| 6427 |
blank_2, |
| 6428 |
duplicate_powerups_header, |
| 6429 |
duplicate_primaries, |
| 6430 |
duplicate_secondaries, |
| 6431 |
#if DXX_BUILD_DESCENT == 2 |
| 6432 |
duplicate_accessories, |
| 6433 |
#endif |
| 6434 |
blank_3, |
| 6435 |
spawn_site_header, |
| 6436 |
spawn_count, |
| 6437 |
spawn_invulnerable_time, |
| 6438 |
blank_4, |
| 6439 |
objects_allowed_header, |
| 6440 |
allow_laser_upgrade, |
| 6441 |
allow_quad_laser, |
| 6442 |
allow_vulcan_cannon, |
| 6443 |
allow_spreadfire_cannon, |
| 6444 |
allow_plasma_cannon, |
| 6445 |
allow_fusion_cannon, |
| 6446 |
/* concussion missiles are always allowed, so there is no line |
| 6447 |
* item for them */ |
| 6448 |
allow_homing_missiles, |
| 6449 |
allow_proximity_bombs, |
| 6450 |
allow_smart_missiles, |
| 6451 |
allow_mega_missiles, |
| 6452 |
#if DXX_BUILD_DESCENT == 2 |
| 6453 |
allow_super_laser_upgrade, |
| 6454 |
allow_gauss_cannon, |
| 6455 |
allow_helix_cannon, |
| 6456 |
allow_phoenix_cannon, |
| 6457 |
allow_omega_cannon, |
| 6458 |
allow_flash_missiles, |
| 6459 |
allow_guided_missiles, |
| 6460 |
allow_smart_mines, |
| 6461 |
allow_mercury_missiles, |
| 6462 |
allow_earthshaker_missiles, |
| 6463 |
#endif |
| 6464 |
allow_cloaking, |
| 6465 |
allow_invulnerability, |
| 6466 |
#if DXX_BUILD_DESCENT == 2 |
| 6467 |
allow_afterburner, |
| 6468 |
allow_ammo_rack, |
| 6469 |
allow_energy_converter, |
| 6470 |
allow_headlight, |
| 6471 |
#endif |
| 6472 |
blank_5, |
| 6473 |
objects_granted_header, |
| 6474 |
grant_laser_level, |
| 6475 |
grant_quad_laser, |
| 6476 |
grant_vulcan_cannon, |
| 6477 |
grant_spreadfire_cannon, |
| 6478 |
grant_plasma_cannon, |
| 6479 |
grant_fusion_cannon, |
| 6480 |
#if DXX_BUILD_DESCENT == 2 |
| 6481 |
grant_gauss_cannon, |
| 6482 |
grant_helix_cannon, |
| 6483 |
grant_phoenix_cannon, |
| 6484 |
grant_omega_cannon, |
| 6485 |
grant_afterburner, |
| 6486 |
grant_ammo_rack, |
| 6487 |
grant_energy_converter, |
| 6488 |
grant_headlight, |
| 6489 |
#endif |
| 6490 |
blank_6, |
| 6491 |
misc_options_header, |
| 6492 |
show_all_players_on_automap, |
| 6493 |
#if DXX_BUILD_DESCENT == 2 |
| 6494 |
allow_marker_camera, |
| 6495 |
indestructible_lights, |
| 6496 |
thief_permitted, |
| 6497 |
thief_steals_energy, |
| 6498 |
guidebot_enabled, |
| 6499 |
#endif |
| 6500 |
bright_player_ships, |
| 6501 |
enemy_names_on_hud, |
| 6502 |
friendly_fire, |
| 6503 |
blank_7, |
| 6504 |
network_options_header, |
| 6505 |
packets_per_second, |
| 6506 |
}; |
| 6507 |
enum |
| 6508 |
{ |
| 6509 |
count_array_elements = static_cast<unsigned>(packets_per_second) + 1 |
| 6510 |
}; |
| 6511 |
enumerated_array<std::array<char, 50>, count_array_elements, netgame_menu_info_index> lines; |
| 6512 |
enumerated_array<newmenu_item, count_array_elements, netgame_menu_info_index> menu_items; |
| 6513 |
netgame_info_menu_items(const netgame_info &netgame) |
| 6514 |
{ |
| 6515 |
for (auto &&[m, l] : zip(menu_items, lines)) |
| 6516 |
nm_set_item_text(m, l.data()); |
| 6517 |
|
| 6518 |
menu_items[blank_1].text = |
| 6519 |
menu_items[blank_2].text = |
| 6520 |
menu_items[blank_3].text = |
| 6521 |
menu_items[blank_4].text = |
| 6522 |
menu_items[blank_5].text = |
| 6523 |
menu_items[blank_6].text = |
| 6524 |
menu_items[blank_7].text = |
| 6525 |
const_cast<char *>(" "); |
| 6526 |
|
| 6527 |
menu_items[game_options_header].text = const_cast<char *>("Game Options:"); |
| 6528 |
menu_items[duplicate_powerups_header].text = const_cast<char *>("Duplicate Powerups:"); |
| 6529 |
menu_items[spawn_site_header].text = const_cast<char *>("Spawn Options:"); |
| 6530 |
menu_items[objects_allowed_header].text = const_cast<char *>("Objects Allowed:"); |
| 6531 |
menu_items[objects_granted_header].text = const_cast<char *>("Objects Granted At Spawn:"); |
| 6532 |
menu_items[misc_options_header].text = const_cast<char *>("Misc. Options:"); |
| 6533 |
menu_items[network_options_header].text = const_cast<char *>("Network Options:"); |
| 6534 |
|
| 6535 |
array_snprintf(lines[game_name], "Game Name\t %s", netgame.game_name.data()); |
| 6536 |
array_snprintf(lines[mission_name], "Mission Name\t %s", netgame.mission_title.data()); |
| 6537 |
array_snprintf(lines[level_number], "Level\t %s%i", (netgame.levelnum < 0) ? "S" : " ", abs(netgame.levelnum)); |
| 6538 |
const auto gamemode = underlying_value(netgame.gamemode); |
| 6539 |
array_snprintf(lines[game_mode], "Game Mode\t %s", gamemode < GMNames.size() ? GMNames[gamemode] : "INVALID"); |
| 6540 |
array_snprintf(lines[player_counts], "Players\t %i/%i", netgame.numplayers, netgame.max_numplayers); |
| 6541 |
array_snprintf(lines[difficulty], "Difficulty\t %s", MENU_DIFFICULTY_TEXT(netgame.difficulty)); |
| 6542 |
array_snprintf(lines[reactor_life], "Reactor Life\t %i %s", netgame.control_invul_time / F1_0 / 60, TXT_MINUTES_ABBREV); |
| 6543 |
array_snprintf(lines[max_time], "Max Time\t %i %s", netgame.PlayTimeAllowed.count() / (F1_0 * 60), TXT_MINUTES_ABBREV); |
| 6544 |
array_snprintf(lines[kill_goal], "Kill Goal\t %i", netgame.KillGoal * 5); |
| 6545 |
array_snprintf(lines[duplicate_primaries], "Primaries\t %i", static_cast<int>(netgame.DuplicatePowerups.get_primary_count())); |
| 6546 |
array_snprintf(lines[duplicate_secondaries], "Secondaries\t %i", static_cast<int>(netgame.DuplicatePowerups.get_secondary_count())); |
| 6547 |
#if DXX_BUILD_DESCENT == 2 |
| 6548 |
array_snprintf(lines[duplicate_accessories], "Accessories\t %i", static_cast<int>(netgame.DuplicatePowerups.get_accessory_count())); |
| 6549 |
#endif |
| 6550 |
array_snprintf(lines[spawn_count], "Use * Furthest Spawn Sites\t %i", netgame.SecludedSpawns+1); |
| 6551 |
array_snprintf(lines[spawn_invulnerable_time], "Invulnerable Time\t %1.1f sec", static_cast<float>(netgame.InvulAppear) / 2); |
| 6552 |
array_snprintf(lines[allow_laser_upgrade], "Laser Upgrade\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOLASER) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6553 |
array_snprintf(lines[allow_quad_laser], "Quad Lasers\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOQUAD) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6554 |
array_snprintf(lines[allow_vulcan_cannon], "Vulcan Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOVULCAN) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6555 |
array_snprintf(lines[allow_spreadfire_cannon], "Spreadfire Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOSPREAD) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6556 |
array_snprintf(lines[allow_plasma_cannon], "Plasma Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOPLASMA) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6557 |
array_snprintf(lines[allow_fusion_cannon], "Fusion Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOFUSION) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6558 |
array_snprintf(lines[allow_homing_missiles], "Homing Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOHOMING) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6559 |
array_snprintf(lines[allow_proximity_bombs], "Proximity Bombs\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOPROXIM) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6560 |
array_snprintf(lines[allow_smart_missiles], "Smart Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOSMART) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6561 |
array_snprintf(lines[allow_mega_missiles], "Mega Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOMEGA) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6562 |
#if DXX_BUILD_DESCENT == 2 |
| 6563 |
array_snprintf(lines[allow_super_laser_upgrade], "Super Lasers\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOSUPERLASER) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6564 |
array_snprintf(lines[allow_gauss_cannon], "Gauss Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOGAUSS) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6565 |
array_snprintf(lines[allow_helix_cannon], "Helix Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOHELIX) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6566 |
array_snprintf(lines[allow_phoenix_cannon], "Phoenix Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOPHOENIX) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6567 |
array_snprintf(lines[allow_omega_cannon], "Omega Cannon\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOOMEGA) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6568 |
array_snprintf(lines[allow_flash_missiles], "Flash Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOFLASH) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6569 |
array_snprintf(lines[allow_guided_missiles], "Guided Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOGUIDED) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6570 |
array_snprintf(lines[allow_smart_mines], "Smart Mines\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOSMARTMINE) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6571 |
array_snprintf(lines[allow_mercury_missiles], "Mercury Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOMERCURY) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6572 |
array_snprintf(lines[allow_earthshaker_missiles], "Earthshaker Missiles\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOSHAKER) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6573 |
#endif |
| 6574 |
array_snprintf(lines[allow_cloaking], "Cloaking\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOCLOAK) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6575 |
array_snprintf(lines[allow_invulnerability], "Invulnerability\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOINVUL) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6576 |
#if DXX_BUILD_DESCENT == 2 |
| 6577 |
array_snprintf(lines[allow_afterburner], "Afterburners\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOAFTERBURNER) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6578 |
array_snprintf(lines[allow_ammo_rack], "Ammo Rack\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOAMMORACK) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6579 |
array_snprintf(lines[allow_energy_converter], "Energy Converter\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOCONVERTER) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6580 |
array_snprintf(lines[allow_headlight], "Headlight\t %s", (netgame.AllowedItems & netflag_flag::NETFLAG_DOHEADLIGHT) != netflag_flag::None ? TXT_YES : TXT_NO); |
| 6581 |
#endif |
| 6582 |
array_snprintf(lines[grant_laser_level], "Laser Level\t %u", static_cast<unsigned>(map_granted_flags_to_laser_level(netgame.SpawnGrantedItems)) + 1); |
| 6583 |
array_snprintf(lines[grant_quad_laser], "Quad Lasers\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_QUAD) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6584 |
array_snprintf(lines[grant_vulcan_cannon], "Vulcan Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_VULCAN) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6585 |
array_snprintf(lines[grant_spreadfire_cannon], "Spreadfire Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_SPREAD) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6586 |
array_snprintf(lines[grant_plasma_cannon], "Plasma Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_PLASMA) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6587 |
array_snprintf(lines[grant_fusion_cannon], "Fusion Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_FUSION) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6588 |
#if DXX_BUILD_DESCENT == 2 |
| 6589 |
array_snprintf(lines[grant_gauss_cannon], "Gauss Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_GAUSS) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6590 |
array_snprintf(lines[grant_helix_cannon], "Helix Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_HELIX) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6591 |
array_snprintf(lines[grant_phoenix_cannon], "Phoenix Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_PHOENIX) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6592 |
array_snprintf(lines[grant_omega_cannon], "Omega Cannon\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_OMEGA) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6593 |
array_snprintf(lines[grant_afterburner], "Afterburner\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_AFTERBURNER) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6594 |
array_snprintf(lines[grant_ammo_rack], "Ammo Rack\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_AMMORACK) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6595 |
array_snprintf(lines[grant_energy_converter], "Energy Converter\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_CONVERTER) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6596 |
array_snprintf(lines[grant_headlight], "Headlight\t %s", menu_bit_wrapper(netgame.SpawnGrantedItems.mask, netgrant_flag::NETGRANT_HEADLIGHT) != netgrant_flag::None ? TXT_YES : TXT_NO); |
| 6597 |
#endif |
| 6598 |
array_snprintf(lines[show_all_players_on_automap], "Show All Players On Automap\t %s", ((netgame.game_flag & netgame_rule_flags::show_all_players_on_automap) != netgame_rule_flags::None) ? TXT_YES : TXT_NO); |
| 6599 |
#if DXX_BUILD_DESCENT == 2 |
| 6600 |
array_snprintf(lines[allow_marker_camera], "Allow Marker Camera Views\t %s", netgame.Allow_marker_view?TXT_YES:TXT_NO); |
| 6601 |
array_snprintf(lines[indestructible_lights], "Indestructible Lights\t %s", netgame.AlwaysLighting?TXT_YES:TXT_NO); |
| 6602 |
array_snprintf(lines[thief_permitted], "Thief permitted\t %s", (netgame.ThiefModifierFlags & ThiefModifier::Absent) ? TXT_NO : TXT_YES); |
| 6603 |
array_snprintf(lines[thief_steals_energy], "Thief steals energy weapons\t %s", (netgame.ThiefModifierFlags & ThiefModifier::NoEnergyWeapons) ? TXT_NO : TXT_YES); |
| 6604 |
array_snprintf(lines[guidebot_enabled], "Guidebot enabled (experimental)\t %s", Netgame.AllowGuidebot ? TXT_YES : TXT_NO); |
| 6605 |
#endif |
| 6606 |
array_snprintf(lines[bright_player_ships], "Bright Player Ships\t %s", netgame.BrightPlayers?TXT_YES:TXT_NO); |
| 6607 |
array_snprintf(lines[enemy_names_on_hud], "Enemy Names On Hud\t %s", netgame.ShowEnemyNames?TXT_YES:TXT_NO); |
| 6608 |
array_snprintf(lines[friendly_fire], "Friendly Fire (Team, Coop)\t %s", netgame.NoFriendlyFire?TXT_NO:TXT_YES); |
| 6609 |
array_snprintf(lines[packets_per_second], "Packets Per Second\t %i", netgame.PacketsPerSec); |
| 6610 |
} |
| 6611 |
}; |
| 6612 |
struct netgame_info_menu : netgame_info_menu_items, passive_newmenu |
| 6613 |
{ |
| 6614 |
netgame_info_menu(const netgame_info &netgame, grs_canvas &src) : |
| 6615 |
netgame_info_menu_items(netgame), |
| 6616 |
passive_newmenu(menu_title{nullptr}, menu_subtitle{"Netgame Info & Rules"}, menu_filename{nullptr}, tiny_mode_flag::tiny, tab_processing_flag::ignore, adjusted_citem::create(menu_items, 0), src) |
| 6617 |
{ |
| 6618 |
} |
| 6619 |
}; |
| 6620 |
auto menu = window_create<netgame_info_menu>(netgame, grd_curscreen->sc_canvas); |
| 6621 |
(void)menu; |
| 6622 |
} |
| 6623 |
} |