aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/include/g_main_cl.h
blob: 5731048625f9a78086583e50dcfeeb809ae92d6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#ifndef _G_MAIN_CL_H_
#define _G_MAIN_CL_H_

// ----------------------------------------------------------------------------
//
class G_Extracted
{
protected:
	
	// remember time last kill was achieved, needed for medals 
	refframe_t last_kill_time;
	
protected:
	
	// check kill announcements and medals ----------------------------------------
	//
	void _CheckKillAnnouncements( int nKiller )
	{
		if ( !AUX_DISABLE_KILLS_LEFT_ANNOUNCEMENT ) {
			
			// check if somebody is approaching the kill limit
			int leaderkills = 0;
			
			for ( int pid = 0; pid < MAX_NET_PROTO_PLAYERS; pid++ ) {
				if ( Player_Status[ pid ] == PLAYER_INACTIVE )
					continue;
				if ( Player_KillStat[ pid ] > leaderkills )
					leaderkills = Player_KillStat[ pid ];
			}
			
			if ( AUX_KILL_LIMIT_FOR_GAME_END > 0 ) {
				if ( AUX_KILL_LIMIT_FOR_GAME_END >= leaderkills ) {
					int killsleft = AUX_KILL_LIMIT_FOR_GAME_END - leaderkills;
					AUD_KillsLeft( killsleft );
				}
			}
		}
		
		// check if we downed that ship ourselves
		if ( nKiller == LocalPlayerId ) {
			
			refframe_t timesincekill = SYSs_GetRefFrameCount() - last_kill_time;
			
			if ( timesincekill < AUXDATA_SKILL_AMAZING_TIME ) {
				
				AUD_SkillAmazing();
				
			} else if ( timesincekill < AUXDATA_SKILL_BRILLIANT_TIME ) {
				
				AUD_SkillBrilliant();
				
			} else {
				
				AUD_JimCommenting( JIM_COMMENT_EATTHIS );
			}
			
			last_kill_time = SYSs_GetRefFrameCount();
		}
	}
	
public:

	G_Extracted()
	{
		last_kill_time = 0;
	}

	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	// UI Code
	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	
	
	// UI feedback for player has joined --------------------------------------
	//
	bool_t UI_PlayerJoinedFeedback( RE_PlayerStatus* playerstatus )
	{
		ASSERT( playerstatus != NULL );
		
		// nothing todo for local client
		if ( playerstatus->senderid == LocalPlayerId ) {
			return false;
		}

		// show join message
		if ( !EntryMode ) {
			CopyRemoteName( paste_str, Player_Name[ playerstatus->senderid ] );
			strcat( paste_str, " has joined" );
			ShowMessage( paste_str );
			
			// play sound "player has joined"
			AUD_NewPlayerJoined();
		}
		
		return true;
	}
	
	// UI feedback when player has unjoined -----------------------------------
	//
	bool_t UI_PlayerUnjoinedFeedback( RE_PlayerStatus* playerstatus )
	{
		ASSERT( playerstatus != NULL );

		// nothing todo for local client
		if ( playerstatus->senderid == LocalPlayerId ) {
			return false;
		}

		// show appropriate message
		if ( !EntryMode ) {
			CopyRemoteName( paste_str, Player_Name[ playerstatus->senderid ] );
			if ( playerstatus->params[ 0 ] == USER_EXIT ) {
				
				strcat( paste_str, " has left" );
				
			} else if ( playerstatus->params[ 0 ] == SHIP_DOWNED ) {
				
				strcat( paste_str, " was killed by " );
				strcat( paste_str, Player_Name[ playerstatus->params[ 2 ] - KILLERID_BIAS ] );
			}
			ShowMessage( paste_str );
		}
		
		return true;
	}

	// UI feedback when player connects ---------------------------------------
	//
	bool_t UI_PlayerConnectedFeedback( int playerid )
	{
		return true;
	}

	// UI feedback when player disconnects ------------------------------------
	//
	bool_t UI_PlayerDisconnectedFeedback( int playerid )
	{
		return true;
	}

	// UI feedback when player is removed ( timeout ) -------------------------
	//
	bool_t UI_PlayerWasRemovedFeedback( int playerid )
	{
		// show appropriate message
		if ( !EntryMode ) {
			CopyRemoteName( paste_str, Player_Name[ playerid ] );
			strcat( paste_str, " has been removed" );
			ShowMessage( paste_str );
		}

		return true;
	}


	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	// GAMECODE
	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////

	// the local player is killed -------------------------------------------------
	//
	void GC_LocalPlayerKill( int nClientID_Killer, int weapon )
	{
		// remember the last killer
		CurKiller = nClientID_Killer;
		
		ShipDowned = TRUE;
		// this causes the correct case to be taken in G_MAIN::Gm_CancelGameLoop()
		ExitGameLoop = 2;

		KillDurationWeapons( MyShip );
		OBJ_CreateShipExtras( MyShip );

		//FIXME: different texts for different ways the local player can get killed
		switch ( weapon ) {
			case 0:
			default:
				strcpy( paste_str, "killed by " );
				strcat( paste_str, NET_FetchPlayerName( nClientID_Killer ) );
				break;
		}
		ShowMessage( paste_str );

		// play sample
		AUD_PlayerKilled();
	}

	
	// GameCode called when player unjoins due to ship downed -----------------
	//
	bool_t GC_UnjoinPlayer_ShipDowned( int nClientID_Downed, int nClientID_Killer, int nWeapon )
	{
		ASSERT( ( nClientID_Downed >= 0 ) && ( nClientID_Downed < MAX_NET_PROTO_PLAYERS ) );
		ASSERT( ( nClientID_Killer >= 0 ) && ( nClientID_Killer < MAX_NET_PROTO_PLAYERS ) );
		ASSERT( nClientID_Downed != LocalPlayerId );

		// local player downing MUST be handled differently
		ASSERT( nClientID_Downed != LocalPlayerId );

		ShipObject *shippo = (ShipObject *) Player_Ship[ nClientID_Downed ];
		ASSERT( shippo != NULL );

		if ( shippo != NULL ) {
		
			//NOTE:
			// the ship will be deleted automatically by the
			// explosion (in a certain animation frame).
			
			// start explosion by setting count greater than zero
			if ( shippo->ExplosionCount == 0 ) {
				shippo->ExplosionCount = MAX_EXPLOSION_COUNT;
				
				AUD_ShipDestroyed( shippo );
			}
		}
		
		_CheckKillAnnouncements( nClientID_Killer  );
		
		return true;
	}
	
	// GameCode called when player unjoins due to user exit -------------------
	//
	bool_t GC_UnjoinPlayer_UserExit( RE_PlayerStatus* playerstatus )
	{
		ASSERT( playerstatus != NULL );
		ASSERT( playerstatus->params[ 0 ] == USER_EXIT );
		
		ShipObject *shippo = (ShipObject *) Player_Ship[ playerstatus->senderid ];
		ASSERT( shippo != NULL );
		
		// open stargate
		SFX_CreateStargate( shippo );
		
		//FIXME: [1/27/2002] shouldn't we move this to the engine core
		// kill ship object
		KillSpecificObject( Player_ShipId[ playerstatus->senderid ], PShipObjects );
		
		return true;
	}

};

// UI/GameCode ----------------------------------------------------------------
//
extern G_Extracted TheGameExtraction;
#define GAMECODE( x )	( TheGameExtraction.x )

#endif // _G_MAIN_CL_H_