File: nDead.c

package info (click to toggle)
conquest 8.1-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,984 kB
  • ctags: 3,086
  • sloc: ansic: 39,393; sh: 8,540; yacc: 446; makefile: 296; lex: 146
file content (312 lines) | stat: -rw-r--r-- 7,775 bytes parent folder | download
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* 
 * node
 *
 * $Id: nDead.c,v 1.5 2004/09/12 20:01:06 jon Exp $
 *
 * Copyright 1999-2004 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
 */

#include "c_defs.h"
#include "context.h"
#include "global.h"
#include "datatypes.h"
#include "color.h"
#include "conf.h"
#include "gldisplay.h"
#include "client.h"
#include "node.h"
#include "ship.h"
#include "prm.h"
#include "conqcom.h"
#include "conqlb.h"
#include "nDead.h"
#include "nMenu.h"
#include "cqkeys.h"

extern Unsgn8 clientFlags;      /* conquestgl.c */

static int snum;
static int kb;                  /* killed by... */
string ywkb="You were killed by ";
static char buf[128], junk[128], cbuf[MID_BUFFER_SIZE];
static char lastwords[MAXLASTWORDS];
static Ship_t eShip = {}; /* copy of killers ship, if killed by ship */

#define S_PRESSANY  0           /* press any key... */
#define S_LASTWORDS 1           /* you won, get conquer msg */
#define S_LASTWCONF 2           /* confirm last words */
static int state;

static prm_t prm;

static int nDeadDisplay(dspConfig_t *);
static int nDeadIdle(void);
static int nDeadInput(int ch);

static scrNode_t nDeadNode = {
  nDeadDisplay,               /* display */
  nDeadIdle,                  /* idle */
  nDeadInput,                  /* input */
  NULL
};


void nDeadInit(void)
{
  state = S_PRESSANY;
  snum = Context.snum;

  /* If something is wrong, don't do anything. */
  if ( snum < 1 || snum > MAXSHIPS )
    {
      clog("nDead: nDeadInit: snum < 1 || snum > MAXSHIPS (%d)", snum);
      nMenuInit();
    }
  
  kb = Ships[snum].killedby;

  if (kb >= 1 && kb <= MAXSHIPS)
    eShip = Ships[kb];        /* get copy of killers ship */

  if (clientFlags & SPCLNTSTAT_FLAG_CONQUER)
    {
      state = S_LASTWORDS;

      prm.preinit = False;
      prm.buf = lastwords;
      prm.buflen = MAXLASTWORDS - 1;
      prm.terms = TERMS;
      prm.buf[0] = EOS;
    }


  setNode(&nDeadNode);

  return;
}


static int nDeadDisplay(dspConfig_t *dsp)
{
  int i;

  /* Figure out why we died. */
  switch ( kb )
    {
    case KB_SELF:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You scuttled yourself.");
      
      break;
    case KB_NEGENB:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You were destroyed by the negative energy barrier.");
      
      break;
    case KB_CONQUER:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "Y O U   C O N Q U E R E D   T H E   U N I V E R S E ! ! !");
      break;
    case KB_NEWGAME:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "N E W   G A M E !");
      break;
    case KB_EVICT:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "Closed for repairs.");
      break;
    case KB_SHIT:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You are no longer allowed to play.");
      break;
    case KB_GOD:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You were killed by an act of GOD.");
      
      break;
    case KB_DOOMSDAY:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You were eaten by the doomsday machine.");
      
      break;
    case KB_GOTDOOMSDAY:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You destroyed the doomsday machine!");
      break;
    case KB_DEATHSTAR:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You were vaporized by the Death Star.");
      
      break;
    case KB_LIGHTNING:
      cprintf(8,0,ALIGN_CENTER,"#%d#%s", RedLevelColor, 
              "You were destroyed by a lightning bolt.");
      
      break;
    default:
      cbuf[0] = EOS;
      buf[0] = EOS;
      junk[0] = EOS;
      if ( kb > 0 && kb <= MAXSHIPS )
	{
	  appship( kb, cbuf );
	  if ( eShip.status != SS_LIVE )
	    appstr( ", who also died.", buf );
	  else
	    appchr( '.', buf );
	  cprintf( 8,0,ALIGN_CENTER, 
		   "#%d#You were kill number #%d#%.1f #%d#for #%d#%s #%d#(#%d#%s#%d#)%s",
		   InfoColor, CQC_A_BOLD, eShip.kills, 
		   InfoColor, CQC_A_BOLD, eShip.alias, 
		   InfoColor, CQC_A_BOLD, cbuf, 
		   InfoColor, buf );
	}
      else if ( -kb > 0 && -kb <= NUMPLANETS )
	{
	  if ( Planets[-kb].type == PLANET_SUN )
            strcpy(cbuf, "solar radiation.");
	  else
            strcpy(cbuf, "planetary defenses.");

	  cprintf(8,0,ALIGN_CENTER,"#%d#%s#%d#%s%s#%d#%s", 
                  InfoColor, ywkb, CQC_A_BOLD, Planets[-kb].name, "'s ",
                  InfoColor, cbuf);
	}
      else
	{
	  /* We were unable to determine the cause of death. */
	  buf[0] = EOS;
	  appship( snum, buf );
	  sprintf(cbuf, "dead: %s was killed by %d.", buf, kb);
	  cerror( cbuf );
	  clog(cbuf);
	  
	  cprintf(8,0,ALIGN_CENTER,"#%d#%s%s", 
                  RedLevelColor, ywkb, "nothing in particular.  (How strange...)");
	}
    }
  
  if ( kb == KB_NEWGAME )
    {
      cprintf( 10,0,ALIGN_CENTER,
		"#%d#Universe conquered by #%d#%s #%d#for the #%d#%s #%d#team.",
		 InfoColor, CQC_A_BOLD, ConqInfo->conqueror, 
		 InfoColor, CQC_A_BOLD, ConqInfo->conqteam, LabelColor );
    }
  else if ( kb == KB_SELF )
    {
      i = Ships[snum].armies;
      if ( i > 0 )
	{
	  junk[0] = EOS; 
	  if ( i == 1 )
	    strcpy( cbuf, "army" );
	  else
	    {
	      if ( i < 100 )
			appnum( i, junk );
	      else
			appint( i, junk );
	      strcpy( cbuf, "armies" );
	    }
	  if ( i == 1 )
	    strcpy( buf, "was" );
	  else
	    strcpy( buf, "were");
	  if ( i == 1 )
		cprintf(10,0,ALIGN_CENTER,
		"#%d#The #%d#%s #%d#you were carrying %s not amused.",
			LabelColor, CQC_A_BOLD, cbuf, LabelColor, buf);
	  else
		cprintf(10,0,ALIGN_CENTER,
		"#%d#The #%d#%s %s #%d#you were carrying %s not amused.",
			LabelColor, CQC_A_BOLD, junk, cbuf, LabelColor, buf);
	}
    }
  else if ( kb >= 0 )
    {
      if ( eShip.status == SS_LIVE )
	{
	  cprintf( 10,0,ALIGN_CENTER,
		"#%d#He had #%d#%d%% #%d#shields and #%d#%d%% #%d#damage.",
		InfoColor, CQC_A_BOLD, round(eShip.shields), 
		InfoColor, CQC_A_BOLD, round(eShip.damage),InfoColor );
	}
    }

  cprintf(12,0,ALIGN_CENTER,
	"#%d#You got #%d#%.1f #%d#this time.", 
	InfoColor, CQC_A_BOLD, oneplace(Ships[snum].kills), InfoColor );

  if (state == S_PRESSANY)
    cprintf(MSG_LIN1, 0, ALIGN_CENTER, MTXT_DONE);
  else
    {
      if (state == S_LASTWORDS)
        {
          cprintf(14, 0, ALIGN_LEFT, "#%d#Any last words? #%d#%s",
                  CyanColor, NoColor, prm.buf);
        }
      if (state == S_LASTWCONF)
        {
          if (prm.buf[0] != EOS)
            {
              cprintf( 13,0,ALIGN_CENTER, "#%d#%s",
                       InfoColor, "Your last words are entered as:");
              cprintf( 14,0,ALIGN_CENTER, "#%d#%c%s%c",
                       YellowLevelColor, '"', prm.buf, '"' );
            }
          else
            cprintf( 14,0,ALIGN_CENTER,"#%d#%s", InfoColor,
                     "You have chosen to NOT leave any last words:" );

          cprintf( 16,0,ALIGN_CENTER, "Press [TAB] to confirm");
        }
    }

  return NODE_OK;
}  
  
static int nDeadIdle(void)
{
  return NODE_OK;
}

static int nDeadInput(int ch)
{
  int irv;

  ch = CQ_CHAR(ch);

  switch (state)
    {
    case S_PRESSANY:
      nMenuInit();                /* go to menu */

      break;

    case S_LASTWORDS:
      irv = prmProcInput(&prm, ch); 
      if (irv > 0)
        state = S_LASTWCONF;

      break;

    case S_LASTWCONF:
      if (ch == TERM_EXTRA)
        {                       /* we are done */
          sendMessage(MSG_GOD, lastwords);
          nMenuInit();
        }
      else
        {                       /* back to the drawing board */
          state = S_LASTWORDS;
          prm.buf[0] = EOS;
        }

      break;
    }

  return NODE_OK;
}