]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/buil.c
Move declarations for chance.c to new chance.h
[empserver] / src / lib / commands / buil.c
index 97dd42ddcc2bf57f5bd2bde16181dff83620d2ad..58bafa322278e79cdcd2a2da5ff2f2c5206834b3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  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 *);
 
 /*
@@ -63,21 +64,15 @@ 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);
@@ -135,19 +130,13 @@ buil(void)
        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);
@@ -172,49 +161,50 @@ buil(void)
        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, &sect)) {
-           gotsect++;
            if (!player->owner)
                continue;
-           if (build_it(&sect, type, sect.sct_item, tlev))
+           gotsect = 1;
+           if (build_it(&sect, type, tlev))
                putsect(&sect);
        }
        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;
@@ -301,8 +291,9 @@ build_ship(struct sctstr *sp, int type, short *vec, int tlev)
 }
 
 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;
@@ -415,8 +406,9 @@ build_land(struct sctstr *sp, int type, short *vec, int tlev)
 }
 
 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;
@@ -493,8 +485,9 @@ build_nuke(struct sctstr *sp, int type, short *vec, int tlev)
 }
 
 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;
@@ -591,7 +584,7 @@ build_bridge(char what)
 {
     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;
 
@@ -624,21 +617,21 @@ build_bridge(char what)
        return RET_SYN;
     gotsect = 0;
     while (nxtsct(&nstr, &sect)) {
-       gotsect++;
        if (!player->owner)
            continue;
-       if (build_it(&sect, sect.sct_item))
+       gotsect = 1;
+       if (build_it(&sect))
            putsect(&sect);
     }
-    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;
@@ -745,8 +738,9 @@ build_bspan(struct sctstr *sp, short *vec)
 }
 
 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;