File: inform.c

package info (click to toggle)
netrek-client-cow 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 5,028 kB
  • sloc: ansic: 42,893; sh: 2,959; python: 380; makefile: 87
file content (260 lines) | stat: -rw-r--r-- 8,829 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
#include "config.h"
#include "copyright.h"

#include <stdio.h>
#include <math.h>
#include <signal.h>
#include "Wlib.h"
#include "defs.h"
#include "struct.h"
#include "data.h"
#include "string_util.h"

#include "inform.h"

/*

Display information about the nearest object to mouse.

When the player asks for info, this routine finds the object nearest
the mouse, either player or planet, and pop up a window with the
desired information in it. We intentionally provide less information
than is actually available. Keeps the fog of war up.

There is a different sized window for each type player/planet and we
take care to keep it from extending beyond the main window boundaries.

*/

static char *my_classes[NUM_TYPES] =
{
  "SC", "DD", "CA", "BB", "AS", "SB", "GA", "??"
};

void inform(W_Window ww, int x, int y, char key)
{
  char    buf[BUFSIZ];
  char    ftoabuf[8];
  int     line = 0;
  register struct player *j;
  register struct planet *k;
  int     mx, my;
  struct obtype *gettarget(W_Window ww, int x, int y, int targtype), *target;
  int     windowWidth, windowHeight;
  float   KillsPerHour, LossesPerHour;		 /* SB info window changed to

						  * 
						  * * * use these instead of
						  * * * Offense and Defense.
						  * * * 12/27/93 ATH */

  mx = x;
  my = y;
  infomapped = 1;
  if (key == 'i')
    {
      target = gettarget(ww, x, y, TARG_PLAYER | TARG_PLANET);
    }
  else
    {
      target = gettarget(ww, x, y, TARG_PLAYER | TARG_SELF);
    }

  /* This is pretty lame.  We make a graphics window for the info
     window so we can accurately space the thing to barely fit into
     the galactic map or whatever. */

  windowWidth = W_WindowWidth(ww);
  windowHeight = W_WindowHeight(ww);
  if (target->o_type == PLAYERTYPE)
    {
      if (key == 'i')
	{
	  /* Too close to the edge? */
	  if (mx + 23 * W_Textwidth + 2 > windowWidth)
	    mx = windowWidth - 23 * W_Textwidth - 2;
	  if (my + 5 * W_Textheight + 2 > windowHeight)
	    my = windowHeight - 5 * W_Textheight - 2;

	  infow = W_MakeWindow("info", mx, my, 23 * W_Textwidth, 6 * W_Textheight,
			       ww, 2, foreColor);
	  W_MapWindow(infow);
	  j = &players[target->o_num];
	  (void) sprintf(buf, "%s (%c%c)", j->p_name, teamlet[j->p_team], shipnos[j->p_no]);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf), shipFont(j));
	  (void) sprintf(buf, "Speed:   %-d", j->p_speed);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);

	  (void) sprintf(buf, "kills:   %-4.2f", j->p_kills);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  (void) sprintf(buf, "Ship Type: %-s", my_classes[j->p_ship.s_type]);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);

	  if (j->p_swar & me->p_team)
	    W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), "WAR", 3,
			W_RegularFont);
	  else if (j->p_hostile & me->p_team)
	    W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), "HOSTILE", 7,
			W_RegularFont);
	  else
	    W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), "PEACEFUL", 8,
			W_RegularFont);
	  (void) sprintf(buf, "%s@%s", j->p_login, j->p_monitor);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j),
		      buf, strlen(buf), W_RegularFont);
	}
      else
	{					 /* New information window! */
	  if (mx + 24 * W_Textwidth + 2 > windowWidth)
	    mx = windowWidth - 24 * W_Textwidth - 2;
	  if (my + 10 * W_Textheight + 2 > windowHeight)
	    my = windowHeight - 10 * W_Textheight - 2;

	  infow = W_MakeWindow("info", mx, my, 24 * W_Textwidth, 10 * W_Textheight,
			       ww, 2, foreColor);
	  W_MapWindow(infow);
	  j = &players[target->o_num];
	  (void) sprintf(buf, "%s (%c%c):", j->p_name, teamlet[j->p_team], shipnos[j->p_no]);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf), shipFont(j));
	  (void) sprintf(buf, "Login   %-s", j->p_login);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  (void) sprintf(buf, "Display %-s", j->p_monitor);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  STRNCPY(buf, "        Rating    Total", 25);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  ftoa(bombingRating(j), ftoabuf, 0, 2, 2);
	  sprintf(buf, "Bombing: %s  %5d",
		  ftoabuf,
		  j->p_stats.st_armsbomb + j->p_stats.st_tarmsbomb);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  ftoa(planetRating(j), ftoabuf, 0, 2, 2);
	  sprintf(buf, "Planets: %s  %5d",
		  ftoabuf,
		  j->p_stats.st_planets + j->p_stats.st_tplanets);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  if ((j->p_ship.s_type == STARBASE) && (SBhours))
	    {
	      KillsPerHour = (float) (j->p_stats.st_sbticks == 0) ?
		  0.0 :
		  (float) j->p_stats.st_sbkills * 36000.0 /
		  (float) j->p_stats.st_sbticks;
	      sprintf(buf, "KPH:     %5.2f  %5d",
		      KillsPerHour,
		      j->p_stats.st_sbkills);
	    }
	  else
	    {
	      ftoa(offenseRating(j), ftoabuf, 0, 2, 2);
	      sprintf(buf, "Offense: %s  %5d",
		      ftoabuf,
		      j->p_stats.st_kills + j->p_stats.st_tkills);
	    }
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  if ((j->p_ship.s_type == STARBASE) && (SBhours))
	    {
	      LossesPerHour = (float) (j->p_stats.st_sbticks == 0) ?
		  0.0 :
		  (float) j->p_stats.st_sblosses * 36000.0 /
		  (float) j->p_stats.st_sbticks;
	      sprintf(buf, "DPH:     %5.2f  %5d",
		      LossesPerHour,
		      j->p_stats.st_sblosses);
	    }
	  else
	    {
	      ftoa(defenseRating(j), ftoabuf, 0, 2, 2);
	      sprintf(buf, "Defense: %s  %5d",
		      ftoabuf,
		      j->p_stats.st_losses + j->p_stats.st_tlosses);
	    }
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  if (j->p_ship.s_type == STARBASE)
	    {
	      sprintf(buf, "  Maxkills: %6.2f", j->p_stats.st_sbmaxkills);
	    }
	  else
	    {
	      sprintf(buf, "  Maxkills: %6.2f", j->p_stats.st_maxkills);
	    }
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	  if ((j->p_ship.s_type == STARBASE) && (SBhours))
	    {
	      sprintf(buf, "  Hours:    %6.2f",
		      (float) j->p_stats.st_sbticks / 36000.0);
	    }
	  else
	    {
	      sprintf(buf, "  Hours:    %6.2f",
		      (float) j->p_stats.st_tticks / 36000.0);
	    }
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, playerColor(j), buf, strlen(buf),
		      W_RegularFont);
	}
    }
  else
    {						 /* Planet */
      /* Too close to the edge? */
      if (mx + 23 * W_Textwidth + 2 > windowWidth)
	mx = windowWidth - 28 * W_Textwidth - 2;
      if (my + 3 * W_Textheight + 2 > windowHeight)
	my = windowHeight - 3 * W_Textheight - 2;

      infow = W_MakeWindow("info", mx, my, W_Textwidth * 28, W_Textheight * 3, ww,
			   2, foreColor);
      W_MapWindow(infow);
      k = &planets[target->o_num];
      if ((k->pl_info & me->p_team)

#ifdef RECORDGAME
	  || playback
#endif

	  )
	{
	  (void) sprintf(buf, "%s (%c)", k->pl_name, teamlet[k->pl_owner]);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, planetColor(k), buf, strlen(buf),
		      planetFont(k));
	  (void) sprintf(buf, "Armies %d", k->pl_armies);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, planetColor(k), buf, strlen(buf),
		      W_RegularFont);
	  (void) sprintf(buf, "%s %s %s %s %c%c%c%c",
			 (k->pl_flags & PLREPAIR ? "REPAIR" : "      "),
			 (k->pl_flags & PLFUEL ? "FUEL" : "    "),
			 (k->pl_flags & PLAGRI ? "AGRI" : "    "),
			 (k->pl_flags & PLCORE ? "CORE" : "    "),
			 (k->pl_info & FED ? 'F' : ' '),
			 (k->pl_info & ROM ? 'R' : ' '),
			 (k->pl_info & KLI ? 'K' : ' '),
			 (k->pl_info & ORI ? 'O' : ' '));
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, planetColor(k), buf, strlen(buf),
		      W_RegularFont);
	}
      else
	{
	  (void) sprintf(buf, "%s", k->pl_name);
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, planetColor(k), buf, strlen(buf),
		      W_RegularFont);
	  (void) sprintf(buf, "No other info");
	  W_WriteText(infow, W_Textwidth, W_Textheight * line++, planetColor(k), buf, strlen(buf),
		      W_RegularFont);
	}
    }
}

void destroyInfo(void)
{
  W_DestroyWindow(infow);
  infow = 0;
  infomapped = 0;
}