1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: sv_mobj.cpp 1832 2010-09-01 23:59:33Z mike $
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 // Copyright (C) 2006-2014 by The Odamex Team.
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // DESCRIPTION:
20 // Moving object handling. Spawn functions.
21 //
22 //-----------------------------------------------------------------------------
23
24 #include "m_alloc.h"
25 #include "i_system.h"
26 #include "z_zone.h"
27 #include "m_random.h"
28 #include "doomdef.h"
29 #include "p_local.h"
30 #include "p_lnspec.h"
31 #include "s_sound.h"
32 #include "doomstat.h"
33 #include "doomtype.h"
34 #include "v_video.h"
35 #include "c_cvars.h"
36 #include "m_vectors.h"
37 #include "p_mobj.h"
38 #include "sv_main.h"
39 #include "p_ctf.h"
40 #include "g_game.h"
41 #include "p_acs.h"
42
43 EXTERN_CVAR(sv_nomonsters)
44 EXTERN_CVAR(sv_maxplayers)
45
46 void G_PlayerReborn(player_t &player);
47 void CTF_RememberFlagPos(mapthing2_t *mthing);
48
P_SetSpectatorFlags(player_t & player)49 void P_SetSpectatorFlags(player_t &player)
50 {
51 player.spectator = true;
52
53 if (player.mo)
54 {
55 player.mo->flags |= MF_SPECTATOR;
56 player.mo->flags &= ~MF_SOLID;
57 player.mo->flags2 |= MF2_FLY;
58 }
59 }
60
61 //
62 // P_SpawnPlayer
63 // Called when a player is spawned on the level.
64 // Most of the player structure stays unchanged
65 // between levels.
66 //
P_SpawnPlayer(player_t & player,mapthing2_t * mthing)67 void P_SpawnPlayer (player_t &player, mapthing2_t *mthing)
68 {
69 // denis - clients should not control spawning
70 if(!serverside)
71 return;
72
73 // [RH] Things 4001-? are also multiplayer starts. Just like 1-4.
74 // To make things simpler, figure out which player is being
75 // spawned here.
76 player_t *p = &player;
77
78 // not playing?
79 if(!p->ingame())
80 return;
81
82 if (p->playerstate == PST_REBORN || p->playerstate == PST_ENTER)
83 G_PlayerReborn (*p);
84
85 AActor *mobj = new AActor (mthing->x << FRACBITS, mthing->y << FRACBITS, ONFLOORZ, MT_PLAYER);
86
87 // set color translations for player sprites
88 // [RH] Different now: MF_TRANSLATION is not used.
89 // mobj->translation = translationtables + 256*playernum;
90
91 mobj->angle = ANG45 * (mthing->angle/45);
92 mobj->pitch = 0;
93 mobj->player = p;
94 mobj->health = p->health;
95
96 p->fov = 90.0f;
97 p->mo = p->camera = mobj->ptr();
98 p->playerstate = PST_LIVE;
99 p->refire = 0;
100 p->damagecount = 0;
101 p->bonuscount = 0;
102 p->extralight = 0;
103 p->fixedcolormap = 0;
104 p->viewheight = VIEWHEIGHT;
105 p->xviewshift = 0;
106 p->attacker = AActor::AActorPtr();
107
108 // Set up some special spectator stuff
109 if (p->spectator)
110 P_SetSpectatorFlags(player);
111
112 // [RH] Allow chasecam for demo watching
113 //if ((demoplayback || demonew) && chasedemo)
114 // p->cheats = CF_CHASECAM;
115
116 // setup gun psprite
117 P_SetupPsprites (p);
118
119 // give all cards in death match mode
120 if (sv_gametype != GM_COOP)
121 {
122 for (int i = 0; i < NUMCARDS; i++)
123 p->cards[i] = true;
124 }
125
126 if(serverside)
127 {
128 // [RH] If someone is in the way, kill them
129 P_TeleportMove (mobj, mobj->x, mobj->y, mobj->z, true);
130
131 // [BC] Do script stuff
132 if (level.behavior != NULL)
133 {
134 if (p->playerstate == PST_ENTER)
135 {
136 level.behavior->StartTypedScripts (SCRIPT_Enter, p->mo);
137 }
138 else if (p->playerstate == PST_REBORN)
139 {
140 level.behavior->StartTypedScripts (SCRIPT_Respawn, p->mo);
141 }
142 }
143
144 // send new objects
145 SV_SpawnMobj(mobj);
146 }
147 }
148
149 /**
150 * Stub
151 */
P_ShowSpawns(mapthing2_t * mthing)152 void P_ShowSpawns(mapthing2_t* mthing) { }
153
154 VERSION_CONTROL (sv_mobj_cpp, "$Id: sv_mobj.cpp 1832 2010-09-01 23:59:33Z mike $")
155
156