Debian Codegraph @

netgames/dmfc/dmfchudmessages.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/Dmfc/dmfchudmessages.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:20 $
23 * $Author: kevinb $
24 *
25 * HUD Message (Death Message's etc) functions
26 *
27 * $Log: dmfchudmessages.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:20 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 20 7/09/99 2:53p Jeff
33 * handle gametime better (pause it when needed) if the server is 'waiting
34 * for players'
35 *
36 * 19 6/11/99 5:37p Jeff
37 * removed ai_info #ifdefs (better way of doing it)
38 *
39 * 18 6/10/99 12:41p Jeff
40 * no ai_info in non-Outrage builds
41 *
42 * 17 4/19/99 3:54a Jeff
43 * added needed includes for Linux
44 *
45 * 16 3/17/99 12:24p Jeff
46 * converted DMFC to be COM interface
47 *
48 * 15 2/11/99 12:50a Jeff
49 * changed names of exported variables
50 *
51 * 14 2/02/99 8:43a Chris
52 * I made buildings with AI work correctly (ie really big robots should be
53 * buildings)
54 * anim to and from states are now shorts instead of bytes
55 *
56 * 13 1/31/99 7:26p Matt
57 * Renamed a bunch of functions to have HUD capitalized
58 *
59 * 12 1/19/99 3:55a Jeff
60 * all strings localized out
61 *
62 * 10 10/30/98 12:47p Jeff
63 * cut down a couple bytes on memory usage
64 *
65 * 9 10/20/98 2:10p Jeff
66 * fixed bug where if death messages were turned off, you wouldn't get any
67 * statistical messages
68 *
69 * 8 10/20/98 12:16p Jeff
70 * added death message filter, hud callsign filter
71 *
72 * 7 10/13/98 2:15a Jeff
73 * created new event for when a player leaves a multiplayer game. Fixed
74 * some 'english' bugs in the network games.
75 *
76 * 6 10/05/98 2:49p Jeff
77 *
78 * 5 10/01/98 2:47p Jeff
79 * added revenge message
80 *
81 * 4 9/28/98 5:05p Jeff
82 * made the statisitical death messages an option in the menu
83 *
84 * 3 9/28/98 10:49a Jeff
85 * fixed 2 of the statistical messages so they don't print if the time is
86 * 0 (last kill/death time)
87 *
88 * 2 9/25/98 4:50p Jeff
89 *
90 * $NoKeywords: $
91 */
92
93 #include "gamedll_header.h"
94 #include "DMFC.h"
95 #include "dmfcinternal.h"
96 #include <stdlib.h>
97
98 /*
99
100 // DMFCBase::DoRandomDeathMessage
101 //
102 // DMFC will display a death message (or suicide message if killer and victim are the same) when
103 // this function is called, based on the strings added with AddDeathMessage or AddSuicideMessage.
104 // killernum = object number of the killer
105 // victimnum = object number of the victim
106 // hash = hash index of the weapon killer, -1 if none
107 void DMFCBase::DoRandomDeathMessage(int killernum,int victimnum,uint32_t hash)
108 {
109 object *it,*me;
110
111 if(killernum!=-1)
112 it = &DLLObjects[killernum];
113 else
114 it = NULL;
115
116 if(victimnum!=-1)
117 me = &DLLObjects[victimnum];
118 else
119 me = NULL;
120
121 char buffer[400];
122 char temp[150],temp2[150];
123
124 //@@strcpy(buffer,"Hi"); <---ummm why did I put this here?
125
126 int weapon_index = -1;
127
128 if(me){
129 if(it)
130 mprintf(0,"[Killer: T=%d I=%d] [Victim: T=%d I=%d]\n",it->type,it->id,me->type,me->id);
131 else
132 mprintf(0,"[Killer: NOT KNOWN] [Victim: T=%d I=%d]\n",me->type,me->id);
133 }else{
134 if(it)
135 mprintf(0,"[Killer: T=%d I=%d] [Victim: NOT KNOWN]\n",it->type,it->id);
136 else
137 mprintf(0,"[Killer: NOT KNOWN] [Victim: NOT KNOWN]\n");
138 }
139
140 if(me){
141 if((hash!=0xFFFFFFFF)&&(me->type==OBJ_PLAYER)&& ( (me->id==GetPlayerNum()) || ((rand()%3)==1) ) ){
142 weapon_index = DLLMultiMatchWeapon(hash);
143 if(weapon_index==-1){
144 mprintf(0,"Server Weapon Doesn't Match!\n");
145 }
146 }
147 }
148
149 if((it)&&(me)){
150 //first check to see if the killer was of type OBJ_PLAYER or OBJ_GHOST
151 if( (it->type==OBJ_PLAYER)||(it->type==OBJ_GHOST)||(it->type==OBJ_OBSERVER) ){
152
153 if(killernum==victimnum){
154 //Display a suicide message
155 int msg = (int)( ((float)m_iSuicideMsgCount) * (((float)rand())/((float)RAND_MAX)) );
156
157 if(!SuicideMsgs[msg].inuse){
158 //we shouldn't have gotten here, but display the first message since there is
159 one guaranteed msg = 0;
160 }
161 sprintf(temp,"\1\100\255\100%s\1\1\255\1",DLLPlayers[me->id].callsign);
162 sprintf(buffer,SuicideMsgs[msg].message,temp);
163 }
164 else{
165 //victim = temp, killer = temp2
166 sprintf(temp,"\1\100\255\100%s\1\1\255\1",DLLPlayers[me->id].callsign);
167 sprintf(temp2,"\1\100\255\100%s\1\1\255\1",DLLPlayers[it->id].callsign);
168
169 bool v_first;
170 char *msg = GetWeaponDeathMessage(weapon_index,&v_first);
171 if(msg){
172 //do a weapon death message
173 if(v_first)
174 sprintf(buffer,msg,temp,temp2);
175 else
176 sprintf(buffer,msg,temp2,temp);
177 }else{
178 //Display a death message
179 int msg = (int)( ((float)m_iDeathMsgCount) * (((float)rand())/((float)RAND_MAX))
180 );
181
182 if(!DeathMsgs[msg].inuse){
183 //we shouldn't have gotten here, but display the first message since
184 there is one guaranteed msg = 0;
185 }
186
187 #ifndef PCGAMER_DEMO
188
189 if((*DLLPlayers[me->id].callsign==95) &&
190 (strlen(DLLPlayers[me->id].callsign)==6) && (!stricmp((char *)(&DLLPlayers[me->id].callsign)+1,(char *)seeds2))){ char
191 seedbuf[200]; memcpy(seedbuf,seeds1,31); DecryptData((uint8_t *)seedbuf,30); sprintf(buffer,(char
192 *)seedbuf,temp2); memset(seedbuf,0,31); }else{ #endif if(DeathMsgs[msg].victim_first)
193 sprintf(buffer,DeathMsgs[msg].message,temp,temp2);
194 else
195 sprintf(buffer,DeathMsgs[msg].message,temp2,temp);
196 #ifndef PCGAMER_DEMO
197 }
198 #endif
199 }
200 }
201 }
202 else if(it->type==OBJ_ROBOT || (it->type == OBJ_BUILDING && it->ai_info)){
203 //we have a kill by a robot
204
205 //see if it was a counter measure
206 int cpnum = GetCounterMeasureOwner(it);
207 if(!CheckPlayerNum(cpnum)){
208 //it was a real robot
209 sprintf(temp,"\1\100\255\100%s\1\1\255\1",DLLPlayers[me->id].callsign);
210 sprintf(buffer,DTXT_ROBOTKILL,temp);
211 }else{
212 //nope we have a player's counter measure
213 DoRandomDeathMessage(DLLPlayers[cpnum].objnum,DLLPlayers[me->id].objnum);
214 return;
215 }
216 }else{
217 //we have a non-player killer
218 sprintf(temp,"\1\100\255\100%s\1\1\255\1",DLLPlayers[me->id].callsign);
219 sprintf(buffer,DTXT_STRAYFIREFORM,temp);
220 }
221 }else{
222 //either me or it doesn't exist
223 mprintf(0,"**********************************************************************\n");
224 mprintf(0,"Either me or it doesn't exist for death message\n");
225
226 if(me){
227 //only the killer doesn't exist
228 sprintf(temp,"\1\100\255\100%s\1\1\255\1",DLLPlayers[me->id].callsign);
229 sprintf(buffer,"%s was killed",temp);
230 }
231 }
232
233
234 static int sound_id = -1;
235
236 if(sound_id==-1){
237 sound_id = DLLFindSoundName("Hostage pickup");
238 }
239
240 DLLAddColoredHudMessage(GR_RGB(1,255,1),buffer);
241 if(sound_id!=-1)
242 DLLPlay3dSound(sound_id,&DLLObjects[DLLPlayers[GetPlayerNum()].objnum]);
243 }
244 */
245 // DMFCBase::DoRandomDeathMessage
246 //
247 // DMFC will display a death message (or suicide message if killer and victim are the same) when
248 // this function is called, based on the strings added with AddDeathMessage or AddSuicideMessage.
249 // killernum = object number of the killer
250 // victimnum = object number of the victim
251 // hash = hash index of the weapon killer, -1 if none
252 void DMFCBase::DoRandomDeathMessage(int killernum, int victimnum, uint32_t hash) {
253 object *it, *me;
254
255 if (killernum != -1)
256 it = &Objects[killernum];
257 else
258 it = NULL;
259
260 if (victimnum != -1)
261 me = &Objects[victimnum];
262 else
263 me = NULL;
264
265 char buffer[400];
266 char temp[150];
267 bool do_statistical = false;
268
269 int weapon_index = -1;
270
271 if (me) {
272 if ((hash != 0xFFFFFFFF) && (me->type == OBJ_PLAYER) && ((me->id == GetPlayerNum()) || ((rand() % 3) == 1))) {
273 weapon_index = DLLMultiMatchWeapon(hash);
274 if (weapon_index == -1) {
275 mprintf(0, "Server Weapon Doesn't Match!\n");
276 }
277 }
278 }
279
280 if ((it) && (me)) {
281 // first check to see if the killer was of type OBJ_PLAYER or OBJ_GHOST
282 if ((it->type == OBJ_PLAYER) || (it->type == OBJ_GHOST) || (it->type == OBJ_OBSERVER)) {
283
284 if (killernum == victimnum) {
285
286 char temp[150];
287 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
288
289 if (m_iDeathMessageFilter == DM_FILTER_SIMPLE) {
290 // do the simple message
291 snprintf(buffer, sizeof(buffer), DTXT_SUICIDE1, temp);
292 } else {
293 // do the detailed message
294 int msg = (int)(((float)m_iSuicideMsgCount) * (((float)rand()) / ((float)RAND_MAX)));
295 if (!SuicideMsgs[msg].inuse) {
296 // we shouldn't have gotten here, but display the first message since there is one guaranteed
297 msg = 0;
298 }
299 snprintf(buffer, sizeof(buffer), SuicideMsgs[msg].message, temp);
300 }
301 } else {
302
303 if (m_iDeathMessageFilter == DM_FILTER_SIMPLE) {
304 // do the simple message
305 char temp[150], temp2[150];
306 // victim = temp, killer = temp2
307 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
308 snprintf(temp2, sizeof(temp2), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[it->id].callsign);
309 snprintf(buffer, sizeof(buffer), DTXT_KILLED1, temp, temp2);
310 } else {
311 // do the detailed message
312 bool vfirst;
313 char *wm = GetWeaponDeathMessage(weapon_index, &vfirst);
314
315 if (wm) {
316 // victim = temp, killer = temp2
317 char temp[150], temp2[150];
318 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
319 snprintf(temp2, sizeof(temp2), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[it->id].callsign);
320
321 if (vfirst)
322 snprintf(buffer, sizeof(buffer), wm, temp, temp2);
323 else
324 snprintf(buffer, sizeof(buffer), wm, temp2, temp);
325
326 } else {
327 int msg = (int)(((float)m_iDeathMsgCount) * (((float)rand()) / ((float)RAND_MAX)));
328 if (!DeathMsgs[msg].inuse) {
329 // we shouldn't have gotten here, but display the first message since there is one guaranteed
330 msg = 0;
331 }
332
333 // victim = temp, killer = temp2
334 char temp[150], temp2[150];
335 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
336 snprintf(temp2, sizeof(temp2), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[it->id].callsign);
337
338 // So when we get here we should have the format string in use_msg, although it still needs the callsigns
339 // if use_vfirst is true, then the victim's callsign comes first
340 if (DeathMsgs[msg].victim_first)
341 snprintf(buffer, sizeof(buffer), DeathMsgs[msg].message, temp, temp2);
342 else
343 snprintf(buffer, sizeof(buffer), DeathMsgs[msg].message, temp2, temp);
344 }
345 }
346 do_statistical = true;
347 }
348
349 } else if (it->type == OBJ_ROBOT || (it->type == OBJ_BUILDING && it->ai_info)) {
350 // we have a kill by a robot
351
352 // see if it was a counter measure
353 int cpnum = GetCounterMeasureOwner(it);
354 if (!CheckPlayerNum(cpnum)) {
355 // it was a real robot
356 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
357 snprintf(buffer, sizeof(buffer), DTXT_ROBOTKILL, temp);
358 } else {
359 // nope we have a player's counter measure
360 DoRandomDeathMessage(Players[cpnum].objnum, Players[me->id].objnum);
361 return;
362 }
363 } else {
364 // we have a non-player killer
365 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
366 snprintf(buffer, sizeof(buffer), DTXT_STRAYFIREFORM, temp);
367 }
368 } else {
369 // either me or it doesn't exist
370 mprintf(0, "**********************************************************************\n");
371 mprintf(0, "Either me or it doesn't exist for death message\n");
372
373 if (me) {
374 // only the killer doesn't exist
375 snprintf(temp, sizeof(temp), "\x01\x64\xFF\x64%s\x01\x01\xFF\x01", Players[me->id].callsign);
376 snprintf(buffer, sizeof(buffer), DTXT_NOKILLERDEATHMSG, temp);
377 }
378 }
379
380 static int sound_id = -1;
381
382 if (m_iDeathMessageFilter != DM_FILTER_NONE) {
383
384 if (sound_id == -1) {
385 sound_id = DLLFindSoundName("Hostage pickup");
386 }
387
388 DLLAddColoredHUDMessage(GR_RGB(1, 255, 1), buffer);
389
390 if (sound_id != -1)
391 DLLPlay3dSound(sound_id, &Objects[Players[GetPlayerNum()].objnum], MAX_GAME_VOLUME, 0);
392 }
393
394 if (do_statistical && (m_iProtectedFlags & DMFC_PRF_DISPSTATHUDMSGS)) {
395 GetStatisticalDeathMessage(it->id, me->id);
396 }
397 }
398
399 // DMFCBase::GetStatisticalSuicideMessage
400 //
401 // Generates a statistical suicide message about the suicide
402 char *DMFCBase::GetStatisticalSuicideMessage(int pnum) {
403 static char buffer[150];
404 strcpy(buffer, DTXT_SIMPLESUICIDEMSG);
405 return buffer;
406 }
407
408 // DMFCBase::GetStatisticalDeathMessage
409 //
410 // Generates a statistical death message about the deaths
411 void DMFCBase::GetStatisticalDeathMessage(int knum, int vnum) {
412 char buffer[150];
413
414 PInfo *vpi, *kpi;
415 tPExtraInfo *vei, *kei;
416
417 vpi = FindPInfo(vnum);
418 kpi = FindPInfo(knum);
419
420 player_record *kpr = GetPlayerRecordByPnum(knum);
421 player_record *vpr = GetPlayerRecordByPnum(vnum);
422
423 if (!vpi || !kpi || !kpr || !vpr)
424 return;
425
426 vei = vpi->GetExtraInfo();
427 kei = kpi->GetExtraInfo();
428
429 int message_type = 0;
430 int retries = 0;
431
432 death_retry:
433 retries++;
434 message_type = (int)(rand() % 10);
435
436 if (retries > 3)
437 return;
438
439 switch (message_type) {
440 case 0: // Kills in a row
441 {
442 if (kei->kills_in_a_row <= 2)
443 goto death_retry;
444 snprintf(buffer, sizeof(buffer), DTXT_HM_KILLSINAROW, kei->kills_in_a_row, kpr->callsign);
445 } break;
446 case 1: // Deaths in a row
447 {
448 if (vei->deaths_in_a_row <= 2)
449 goto death_retry;
450 snprintf(buffer, sizeof(buffer), DTXT_HM_DEATHSINAROW, vei->deaths_in_a_row, vpr->callsign);
451 } break;
452 case 2: // Time since last kill
453 {
454 if (kei->last_kill_time == 0)
455 goto death_retry;
456
457 float a = ((RealGametime) - (kei->last_kill_time));
458 if (a < 60.0f)
459 goto death_retry;
460 snprintf(buffer, sizeof(buffer), DTXT_HM_TIMESINCELASTKILL, kpr->callsign, GetTimeString(a));
461 } break;
462 case 3: // Time since last death
463 {
464 if (vei->last_death_time == 0)
465 goto death_retry;
466
467 float a = ((RealGametime) - (vei->last_death_time));
468 if (a < 60.0f)
469 goto death_retry;
470 snprintf(buffer, sizeof(buffer), DTXT_HM_TIMESINCELASTDEATH, vpr->callsign, GetTimeString(a));
471 } break;
472 case 4: // Efficiency
473 {
474 float kills = ((float)kpr->dstats.kills[DSTAT_LEVEL]);
475 float deaths = ((float)kpr->dstats.deaths[DSTAT_LEVEL]);
476 float suicides = ((float)kpr->dstats.suicides[DSTAT_LEVEL]);
477 float a = kills / (kills + deaths + suicides) * 100.0f;
478
479 if (a < 55.0f)
480 goto death_retry;
481 if (kills < 5)
482 goto death_retry;
483
484 if (a > 75.0f)
485 snprintf(buffer, sizeof(buffer), DTXT_HM_HIGHEFFICENCY, kpr->callsign, a);
486 else
487 snprintf(buffer, sizeof(buffer), DTXT_HM_GOODEFFICENCY, kpr->callsign, a);
488 } break;
489 case 5: // Ranking
490 {
491 goto death_retry;
492 } break;
493 case 7: // How many times you killed the victim
494 {
495 int slot = PRec_GetPlayerSlot(vnum);
496 tPKillerInfo *ki = kpi->GetKillerInfo(slot);
497
498 if (ki->kills < 3)
499 goto death_retry;
500 snprintf(buffer, sizeof(buffer), DTXT_HM_TIMESKILLED, kpr->callsign, vpr->callsign, ki->kills);
501 } break;
502 case 8: { // revenge death
503 int kslot = PRec_GetPlayerSlot(knum);
504 int vslot = PRec_GetPlayerSlot(vnum);
505 if (kslot == -1 || vslot == -1)
506 goto death_retry;
507
508 if (vei->last_kill_num == kslot && kei->last_death_num == vslot && !kei->got_revenge) {
509 // there has been revenge
510 snprintf(buffer, sizeof(buffer), DTXT_HM_REVENGE, kpr->callsign, vpr->callsign);
511 kei->got_revenge = 1;
512 } else
513 goto death_retry;
514 } break;
515 case 9: {
516 goto death_retry;
517 } break;
518 default:
519 goto death_retry;
520 }
521
522 DLLAddHUDMessage(buffer);
523 }