]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/produce.c
Fix trailing whitespace
[empserver] / src / lib / update / produce.c
index 939fc0ca77383476ae0cd811b3488b0a392dc967..4c4c8dcace3384e1d720e6e2416c21af3cf7773c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  produce.c: Produce goodies
- * 
+ *
  *  Known contributors to this file:
- *    
+ *
  */
 
 #include <config.h>
 
-#include "misc.h"
-#include "sect.h"
-#include "product.h"
-#include "nat.h"
-#include "xy.h"
+#include "budg.h"
 #include "player.h"
+#include "product.h"
 #include "update.h"
-#include "gen.h"
-#include "subs.h"
-#include "common.h"
-#include "optlist.h"
-#include "budg.h"
 
 static void materials_charge(struct pchrstr *, short *, int);
 static int materials_cost(struct pchrstr *, short *, int *);
@@ -70,9 +62,9 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
     int material_consume;
     int val;
 
-    product = &pchr[dchr[desig].d_prd];
-    if (product == &pchr[0])
+    if (dchr[desig].d_prd < 0)
        return 0;
+    product = &pchr[dchr[desig].d_prd];
     item = product->p_type;
     *amount = 0;
     *cost = 0;
@@ -100,7 +92,7 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
        material_consume = worker_limit;
     if (material_consume == 0)
        return 0;
-    prodeff = prod_eff(product, np->nat_level[product->p_nlndx]);
+    prodeff = prod_eff(desig, np->nat_level[product->p_nlndx]);
     if (prodeff <= 0.0 && !player->simulation) {
        wu(0, sp->sct_own,
           "%s level too low to produce in %s (need %d)\n",
@@ -111,16 +103,17 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
      * Adjust produced amount by commodity production ratio
      */
     output = material_consume * prodeff;
-    actual = roundavg(output);
-    if (actual <= 0)
-       return 0;
     if (item == I_NONE) {
+       actual = ldround(output, 1);
        if (!player->simulation) {
            levels[sp->sct_own][product->p_level] += output;
            wu((natid)0, sp->sct_own, "%s (%.2f) produced in %s\n",
               product->p_name, output, ownxy(sp));
        }
     } else {
+       actual = roundavg(output);
+       if (actual <= 0)
+           return 0;
        if (product->p_nrdep != 0) {
            if (*resource * 100 < product->p_nrdep * actual)
                actual = *resource * 100 / product->p_nrdep;
@@ -134,13 +127,13 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
                                        * material_consume / actual);
            if (material_consume < 0)
                material_consume = 0;
-           vec[item] = ITEM_MAX;
+           actual = ITEM_MAX - vec[item];
            if (sp->sct_own && !player->simulation)
                wu(0, sp->sct_own,
                   "%s production backlog in %s\n",
                   product->p_name, ownxy(sp));
-       } else
-           vec[item] += actual;
+       }
+       vec[item] += actual;
     }
     /*
      * Reset produced amount by commodity production ratio
@@ -219,14 +212,19 @@ materials_charge(struct pchrstr *pp, short *vec, int count)
 }
 
 /*
- * Return level p.e. for product PP.
+ * Return level p.e. for sector type TYPE.
  * Zero means level is too low for production.
  * LEVEL is the affecting production of PP; it must match PP->p_nlndx.
  */
 double
-prod_eff(struct pchrstr *pp, float level)
+prod_eff(int type, float level)
 {
     double level_p_e;
+    struct dchrstr *dp = &dchr[type];
+    struct pchrstr *pp = &pchr[dp->d_prd];
+
+    if (CANT_HAPPEN(dp->d_prd < 0))
+       return 0.0;
 
     if (pp->p_nlndx < 0)
        level_p_e = 1.0;
@@ -240,5 +238,5 @@ prod_eff(struct pchrstr *pp, float level)
        level_p_e = delta / (delta + pp->p_nllag);
     }
 
-    return level_p_e * pp->p_effic * 0.01;
+    return level_p_e * dp->d_peffic * 0.01;
 }