/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
*
* Known contributors to this file:
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2011
+ * Markus Armbruster, 2004-2012
*/
#include <config.h>
#include <limits.h>
+#include "chance.h"
#include "commands.h"
#include "game.h"
#include "land.h"
#include "treaty.h"
#include "unit.h"
-static int build_ship(struct sctstr *sp, int type, short *vec, int tlev);
-static int build_land(struct sctstr *sp, int type, short *vec, int tlev);
-static int build_nuke(struct sctstr *sp, int type, short *vec, int tlev);
-static int build_plane(struct sctstr *sp, int type, short *vec, int tlev);
+static int build_ship(struct sctstr *sp, int type, int tlev);
+static int build_land(struct sctstr *sp, int type, int tlev);
+static int build_nuke(struct sctstr *sp, int type, int tlev);
+static int build_plane(struct sctstr *sp, int type, int tlev);
static int build_bridge(char);
-static int build_bspan(struct sctstr *sp, short *vec);
-static int build_btower(struct sctstr *sp, short *vec);
+static int build_bspan(struct sctstr *sp);
+static int build_btower(struct sctstr *sp);
static int build_can_afford(double, char *);
/*
int
buil(void)
{
+ struct natstr *natp = getnatp(player->cnum);
+ int tlev = (int)natp->nat_level[NAT_TLEV];
struct sctstr sect;
struct nstr_sect nstr;
- struct natstr *natp;
- int rqtech;
- int tlev;
- int type;
+ int rqtech, type, number, val, gotsect;
char *p, *what, *prompt;
- int gotsect = 0;
- int (*build_it)(struct sctstr *, int, short[], int);
- int number;
+ int (*build_it)(struct sctstr *, int, int);
char buf[1024];
- natp = getnatp(player->cnum);
- tlev = (int)natp->nat_level[NAT_TLEV];
-
p = getstarg(player->argp[1],
"Build (ship, nuke, bridge, plane, land unit, tower)? ",
buf);
break;
case 's':
type = ef_elt_byname(EF_SHIP_CHR, p);
- if (type >= 0) {
+ if (type >= 0)
rqtech = mchr[type].m_tech;
- if ((mchr[type].m_flags & M_TRADE) && !opt_TRADESHIPS)
- type = -1;
- }
break;
case 'l':
type = ef_elt_byname(EF_LAND_CHR, p);
- if (type >= 0) {
+ if (type >= 0)
rqtech = lchr[type].l_tech;
- if ((lchr[type].l_flags & L_SPY) && !opt_LANDSPIES)
- type = -1;
- }
break;
case 'n':
type = ef_elt_byname(EF_NUKE_CHR, p);
if (number > 20) {
char bstr[80];
sprintf(bstr,
- "Are you sure that you want to build %s of them? ",
- player->argp[4]);
+ "Are you sure that you want to build %d of them? ",
+ number);
p = getstarg(player->argp[6], bstr, buf);
if (!p || *p != 'y')
return RET_SYN;
}
}
- if (*what != 'n') {
- if (player->argp[5]) {
- tlev = atoi(player->argp[5]);
- if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
- pr("Your tech level is only %d.\n",
- (int)natp->nat_level[NAT_TLEV]);
- return RET_FAIL;
- }
- if (rqtech > tlev) {
- pr("Required tech is %d.\n", rqtech);
- return RET_FAIL;
- }
- pr("building with tech level %d.\n", tlev);
+ if (player->argp[5]) {
+ val = atoi(player->argp[5]);
+ if (val > tlev && !player->god) {
+ pr("Your%s tech level is only %d.\n",
+ *what == 'n' && drnuke_const > MIN_DRNUKE_CONST
+ ? " effective" : "", tlev);
+ return RET_FAIL;
+ }
+ if (rqtech > val) {
+ pr("Required tech is %d.\n", rqtech);
+ return RET_FAIL;
}
+ tlev = val;
+ pr("Building with tech level %d.\n", tlev);
}
+ gotsect = 0;
while (number-- > 0) {
while (nxtsct(&nstr, §)) {
- gotsect++;
if (!player->owner)
continue;
- if (build_it(§, type, sect.sct_item, tlev))
+ gotsect = 1;
+ if (build_it(§, type, tlev))
putsect(§);
}
snxtsct_rewind(&nstr);
}
- if (!gotsect) {
- pr("Bad sector specification.\n");
- }
+ if (!gotsect)
+ pr("No sectors.\n");
return RET_OK;
}
static int
-build_ship(struct sctstr *sp, int type, short *vec, int tlev)
+build_ship(struct sctstr *sp, int type, int tlev)
{
+ short *vec = sp->sct_item;
struct mchrstr *mp = &mchr[type];
struct shpstr ship;
struct nstr_item nstr;
}
static int
-build_land(struct sctstr *sp, int type, short *vec, int tlev)
+build_land(struct sctstr *sp, int type, int tlev)
{
+ short *vec = sp->sct_item;
struct lchrstr *lp = &lchr[type];
struct lndstr land;
struct nstr_item nstr;
}
static int
-build_nuke(struct sctstr *sp, int type, short *vec, int tlev)
+build_nuke(struct sctstr *sp, int type, int tlev)
{
+ short *vec = sp->sct_item;
struct nchrstr *np = &nchr[type];
struct nukstr nuke;
struct nstr_item nstr;
}
static int
-build_plane(struct sctstr *sp, int type, short *vec, int tlev)
+build_plane(struct sctstr *sp, int type, int tlev)
{
+ short *vec = sp->sct_item;
struct plchrstr *pp = &plchr[type];
struct plnstr plane;
struct nstr_item nstr;
{
struct natstr *natp = getnatp(player->cnum);
struct nstr_sect nstr;
- int (*build_it)(struct sctstr *, short[]);
+ int (*build_it)(struct sctstr *);
int gotsect;
struct sctstr sect;
return RET_SYN;
gotsect = 0;
while (nxtsct(&nstr, §)) {
- gotsect++;
if (!player->owner)
continue;
- if (build_it(§, sect.sct_item))
+ gotsect = 1;
+ if (build_it(§))
putsect(§);
}
- if (!gotsect) {
- pr("Bad sector specification.\n");
- }
+ if (!gotsect)
+ pr("No sectors.\n");
return RET_OK;
}
static int
-build_bspan(struct sctstr *sp, short *vec)
+build_bspan(struct sctstr *sp)
{
+ short *vec = sp->sct_item;
struct sctstr sect;
int val;
int newx, newy;
}
static int
-build_btower(struct sctstr *sp, short *vec)
+build_btower(struct sctstr *sp)
{
+ short *vec = sp->sct_item;
struct sctstr sect;
int val;
int newx, newy;