File: nPlayBMenu.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 (188 lines) | stat: -rw-r--r-- 3,749 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
/* 
 * playback menu node
 *
 * $Id: nPlayBMenu.c,v 1.6 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 "conqcom.h"
#include "datatypes.h"
#include "color.h"
#include "conf.h"
#include "record.h"
#include "playback.h"
#include "gldisplay.h"
#include "node.h"
#include "client.h"
#include "prm.h"
#include "glmisc.h"
#include "ui.h"

#include "nPlayB.h"
#include "nPlayBMenu.h"
#include "nShipl.h"
#include "nPlanetl.h"
#include "nUserl.h"
#include "nHistl.h"
#include "nPlay.h"
#include "nTeaml.h"
#include "cqkeys.h"

extern void processPacket(Unsgn8 *buf);

#define S_NONE          0
#define S_WATCH         1       /* prompt for a ship */
static int state;

prm_t prm;
static int prompting;

static char cbuf[BUFFER_SIZE];

static int nPlayBMenuDisplay(dspConfig_t *);
static int nPlayBMenuInput(int ch);

static char *nss = NULL;        /* no such ship */

static scrNode_t nPlayBMenuNode = {
  nPlayBMenuDisplay,               /* display */
  NULL,                         /* idle */
  nPlayBMenuInput,                  /* input */
  NULL                          /* next */
};

void nPlayBMenuInit(void)
{
  state = S_NONE;
  prompting = FALSE;

  /* if framedelay wasn't overridden, setup based on samplerate */
  if (framedelay == -1.0)
    framedelay = 1.0 / (real)fhdr.samplerate;

  setNode(&nPlayBMenuNode);

  return;
}


static int nPlayBMenuDisplay(dspConfig_t *dsp)
{
  dspReplayMenu();

  if (prompting)
    cprintf(MSG_LIN1, 1, ALIGN_NONE, "#%d#%s #%d#%s",
            CyanColor, prm.pbuf, NoColor, prm.buf);

  if (nss)
    cprintf(MSG_LIN2, 1, ALIGN_NONE, nss);

  return NODE_OK;
}  


static int nPlayBMenuInput(int ch)
{
  int irv;

  ch = CQ_CHAR(ch);

  if (prompting)
    {
      int tmpsnum;
      irv = prmProcInput(&prm, ch);

      if (irv > 0)
        {
          if (ch == TERM_ABORT)
            {
              state = S_NONE;
              prompting = False;

              return NODE_OK;
            }

          delblanks( prm.buf );
          if ( strlen( prm.buf ) == 0 )
            {              /* watch doomsday machine */
              tmpsnum = DISPLAY_DOOMSDAY;
            }
          else
            {
              if ( alldig( prm.buf ) != TRUE )
                {
                  state = S_NONE;
                  prompting = False;

                  nss = "No such ship.";
                  return NODE_OK; 
                }
              safectoi( &tmpsnum, prm.buf, 0 );     /* ignore return status */
            }

          if ( (tmpsnum < 1 || tmpsnum > MAXSHIPS) && 
               tmpsnum != DISPLAY_DOOMSDAY )
            {
              state = S_NONE;
              prompting = False;

              nss = "No such ship.";
              return NODE_OK;
            }

          Context.snum = tmpsnum;
          nPlayBInit();         /* start playing */
        }
      return NODE_OK;
    }

  nss = NULL;
  switch (ch)
    {
    case '/':
      nShiplInit(DSP_NODE_PLAYBMENU, TRUE);
      break;

    case 'q':
      return NODE_EXIT;         /* time to leave */
      break;

    case 'r':
      pbFileSeek(startTime);
      break;

    case 'w':
      state = S_WATCH;
      if (fhdr.snum == 0)
        {
          cbuf[0] = EOS;
          prm.preinit = False;

        }
      else
        {
          sprintf(cbuf, "%d", fhdr.snum);
          prm.preinit = True;
        }

      prm.buf = cbuf;
      prm.buflen = MSGMAXLINE;
      prm.pbuf = "Watch which ship (<cr> for doomsday)?";
      prm.terms = TERMS;
      prm.index = 20;
      prompting = TRUE;

      break;

    default:
      return NODE_OK;
    }


  return NODE_OK;
}