2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * xdump.c: Extended dump
29 * Known contributors to this file:
30 * Markus Armbruster, 2004-2014
42 * Is object P of type TYPE visible to the player?
43 * TODO: Fold this into interators.
46 xdvisible(int type, void *p)
48 struct empobj *gp = p;
49 struct lonstr *lp = p;
53 if (!empobj_in_use(type, p))
64 return gp->own == player->cnum || player->god;
66 return gp->own == player->cnum;
68 return !opt_HIDDEN || player->god; /* FIXME */
70 if (lp->l_status == LS_SIGNED)
72 return lp->l_loner == player->cnum || lp->l_lonee == player->cnum
75 tlev = ((struct mchrstr *)p)->m_tech;
78 tlev = ((struct plchrstr *)p)->pl_tech;
81 tlev = ((struct lchrstr *)p)->l_tech;
83 natp = getnatp(player->cnum);
84 return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
86 tlev = ((struct nchrstr *)p)->n_tech;
87 if (drnuke_const > MIN_DRNUKE_CONST) {
88 natp = getnatp(player->cnum);
89 if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV])
95 return ((struct empfile *)p)->cadef != NULL;
102 * Dump meta-data for items of type TYPE to XD.
103 * Return RET_SYN when TYPE doesn't have meta-data, else RET_OK.
106 xdmeta(struct xdstr *xd, int type)
108 struct castr *ca = ef_cadef(type);
115 xdhdr(xd, ef_nameof(type), 1);
118 for (i = 0; ca[i].ca_name; i++) {
119 if (ca[i].ca_flags & NSC_DEITY && !xd->divine)
121 if (ca[i].ca_flags & NSC_EXTRA)
123 xdflds(xd, mdchr_ca, &ca[i]);
134 * Dump items of type TYPE selected by ARG to XD.
135 * Return RET_OK on success, RET_SYN on error.
138 xditem(struct xdstr *xd, int type, char *arg)
143 unsigned char buf[EF_WITH_CADEF_MAX_ENTRY_SIZE];
149 if (!snxtitem(&ni, type, arg, NULL))
152 xdhdr(xd, ef_nameof(type), 0);
155 while (nxtitem(&ni, buf)) {
156 if (!xdvisible(type, buf))
168 /* Extended dump command */
179 p = getstarg(player->argp[1], "Table name, or meta? ", buf);
180 if (p && strcmp(p, "meta") == 0) {
182 p = getstarg(player->argp[2], "Table name? ", buf);
187 xdinit(&xd, player->cnum, 0, 0, pr);
188 natp = getnatp(player->cnum);
189 type = isdigit(p[0]) ? atoi(p) : ef_byname(p);
190 if (type < 0 || type >= EF_MAX)
193 return xdmeta(&xd, type);
194 if ((EF_IS_GAME_STATE(type) || EF_IS_VIEW(type))
195 && !(natp->nat_stat == STAT_ACTIVE || player->god)) {
196 pr("Access to table %s denied\n", ef_nameof(type));
199 return xditem(&xd, type, player->argp[2]);