]> git.pond.sub.org Git - empserver/blob - src/lib/commands/show.c
0f04c864ae5dede2f8396d0f57716b815c52a173
[empserver] / src / lib / commands / show.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  show.c: Give info on empire objects, planes, boats, nukes, etc.
29  * 
30  *  Known contributors to this file:
31  *     Julian Onions, 1988
32  *     Steve McClure, 1997
33  */
34
35 #include <config.h>
36
37 #include "commands.h"
38 #include "nuke.h"
39 #include "optlist.h"
40
41 int
42 show(void)
43 {
44     char *p;
45     void (*cfunc)(int);
46     void (*sfunc)(int);
47     void (*bfunc)(int);
48     struct natstr *natp;
49     int tlev;
50     char buf[1024];
51     int rlev;
52
53     if (!(p = getstarg(player->argp[1],
54                        "Describe what (plane, nuke, bridge, ship, sect, land unit, tower, item)? ",
55                        buf))
56         || !*p)
57         return RET_SYN;
58
59     natp = getnatp(player->cnum);
60     rlev = (int)(1.25 * natp->nat_level[NAT_RLEV]);
61
62     if (!player->argp[3]) {
63         tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]);
64         if (player->god)
65             tlev = 1000;
66     } else {
67         tlev = (int)atoi(player->argp[3]);
68         if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god)
69             tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]);
70     }
71     if (player->god)
72         rlev = 1000;
73     pr("Printing for tech level '%d'\n", tlev);
74     switch (*p) {
75     case 'b':
76         show_bridge(99999);
77         return RET_OK;
78     case 't':
79         show_tower(99999);
80         return RET_OK;
81     case 'i':
82         show_item(99999);
83         return RET_OK;
84     case 'n':
85         if (*(p + 1) == 'e') {
86             show_news(99999);
87             return RET_OK;
88         }
89         if (drnuke_const > MIN_DRNUKE_CONST)
90             tlev = ((rlev / drnuke_const) > tlev ? tlev :
91                     (rlev / drnuke_const));
92         bfunc = show_nuke_build;
93         cfunc = show_nuke_capab;
94         sfunc = show_nuke_stats;
95         break;
96     case 'l':
97         bfunc = show_land_build;
98         sfunc = show_land_stats;
99         cfunc = show_land_capab;
100         break;
101     case 'p':
102         bfunc = show_plane_build;
103         sfunc = show_plane_stats;
104         cfunc = show_plane_capab;
105         break;
106     case 's':
107         if (*(p + 1) == 'e') {
108             bfunc = show_sect_build;
109             sfunc = show_sect_stats;
110             cfunc = show_sect_capab;
111         } else {
112             bfunc = show_ship_build;
113             sfunc = show_ship_stats;
114             cfunc = show_ship_capab;
115         }
116         break;
117     default:
118         return RET_SYN;
119     }
120     if (!(p = getstarg(player->argp[2],
121                        "Build, stats, or capability data (b,s,c)? ", buf))
122         || !*p)
123         return RET_SYN;
124     if (*p == 'B' || *p == 'b')
125         bfunc(tlev);
126     else if (*p == 'C' || *p == 'c')
127         cfunc(tlev);
128     else if (*p == 'S' || *p == 's')
129         sfunc(tlev);
130     else
131         return RET_SYN;
132     return RET_OK;
133 }