MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PlayerSwitchToObserver

Function PlayerSwitchToObserver

Descent3/Player.cpp:3500–3549  ·  view source on GitHub ↗

Switches a player object to observer mode

Source from the content-addressed store, hash-verified

3498
3499// Switches a player object to observer mode
3500void PlayerSwitchToObserver(int slot, int observer_mode, int piggy_objnum) {
3501 object *obj = &Objects[Players[slot].objnum];
3502
3503 // call the event to the multiplayer DLL's so they can do what they need
3504 if (Game_mode & GM_MULTI) {
3505 DLLInfo.me_handle = obj->handle;
3506
3507 if (observer_mode == OBSERVER_MODE_PIGGYBACK) {
3508 DLLInfo.it_handle = Objects[piggy_objnum].handle;
3509 } else {
3510 DLLInfo.it_handle = OBJECT_HANDLE_NONE;
3511 }
3512
3513 CallGameDLL(EVT_CLIENT_GAMEPLAYERENTERSOBSERVER, &DLLInfo);
3514 }
3515
3516 // Stop sounds for this player
3517 PlayerStopSounds(slot);
3518
3519 if (slot == Player_num) {
3520 AddHUDMessage(TXT_ENTEROBS);
3521 SetHUDMode(HUD_OBSERVER);
3522 Players[slot].movement_scalar = 2.0;
3523 } else
3524 AddHUDMessage(TXT_PLYRENTEROBS, Players[slot].callsign);
3525
3526 CreateRandomSparks(30, &obj->pos, obj->roomnum, HOT_SPARK_INDEX, (ps_rand() % 3) + 2);
3527
3528 if (Demo_flags != DF_PLAYBACK) {
3529 PlayerSpewInventory(obj, false);
3530 }
3531
3532 obj->type = OBJ_OBSERVER;
3533 obj->render_type = RT_NONE;
3534
3535 if (Demo_flags == DF_RECORDING) {
3536 DemoWritePlayerTypeChange(slot, false, observer_mode, piggy_objnum);
3537 }
3538
3539 if (observer_mode == OBSERVER_MODE_ROAM) {
3540 SetObjectControlType(obj, CT_FLYING);
3541 Players[slot].piggy_objnum = -1;
3542 obj->movement_type = MT_PHYSICS;
3543 } else if (observer_mode == OBSERVER_MODE_PIGGYBACK) {
3544 SetObjectControlType(obj, CT_NONE);
3545 Players[slot].piggy_objnum = piggy_objnum;
3546 Players[slot].piggy_sig = Objects[piggy_objnum].handle & HANDLE_COUNT_MASK;
3547 mprintf(0, "Object %d is observing object %d!\n", obj - Objects, piggy_objnum);
3548 }
3549}
3550
3551// Stops a player from observing
3552void PlayerStopObserving(int slot) {

Callers 4

ProcessTestKeysFunction · 0.85
MultiDoObserverChangeFunction · 0.85
MultiDoServerFrameFunction · 0.85
DemoReadPlayerTypeChangeFunction · 0.85

Calls 9

CallGameDLLFunction · 0.85
PlayerStopSoundsFunction · 0.85
AddHUDMessageFunction · 0.85
SetHUDModeFunction · 0.85
CreateRandomSparksFunction · 0.85
ps_randFunction · 0.85
PlayerSpewInventoryFunction · 0.85
SetObjectControlTypeFunction · 0.85

Tested by

no test coverage detected