]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/produce.c
config: Make product work independently configurable
[empserver] / src / lib / update / produce.c
index 817be09523836322cc59ed2db516c897ca8bc123..4cc6dc03f3617fae2fce4a5f4ffe91cc6cd8a583 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -27,7 +27,7 @@
  *  produce.c: Produce goodies
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2021
  */
 
 #include <config.h>
@@ -41,7 +41,9 @@
 #include "prototypes.h"
 #include "update.h"
 
+static double prod_materials_cost(struct pchrstr *, short[]);
 static void materials_charge(struct pchrstr *, short *, double);
+static double prod_resource_limit(struct pchrstr *, unsigned char *);
 
 static char *levelnames[] = {
     "Technology", "Research", "Education", "Happiness"
@@ -68,11 +70,13 @@ produce(struct natstr *np, struct sctstr *sp)
     cost = product->p_cost * output / prodeff;
     if (opt_TECH_POP) {
        if (product->p_level == NAT_TLEV) {
-           if (tpops[sp->sct_own] > 50000)
-               cost *= tpops[sp->sct_own] / 50000.0;
+           if (budget->oldowned_civs > 50000)
+               cost *= budget->oldowned_civs / 50000.0;
        }
     }
 
+    if (product->p_level >= 0)
+       budget->level[product->p_level] += output;
     budget->prod[sp->sct_type].count += ldround(output, 1);
     budget->prod[sp->sct_type].money -= cost;
     budget->money -= cost;
@@ -95,17 +99,14 @@ prod_output(struct sctstr *sp, double prodeff)
     else
        resource = NULL;
 
-    material_limit = prod_materials_cost(product, sp->sct_item,
-                                        &unit_work);
+    material_limit = prod_materials_cost(product, sp->sct_item);
+    unit_work = product->p_bwork;
 
     /* sector p.e. */
     p_e = sp->sct_effic / 100.0;
     if (resource) {
-       unit_work++;
        p_e *= *resource / 100.0;
     }
-    if (unit_work == 0)
-       unit_work = 1;
 
     worker_limit = sp->sct_avail * p_e / unit_work;
     res_limit = prod_resource_limit(product, resource);
@@ -134,7 +135,6 @@ prod_output(struct sctstr *sp, double prodeff)
     output = material_consume * prodeff;
     if (item == I_NONE) {
        if (!player->simulation) {
-           levels[sp->sct_own][product->p_level] += output;
            wu(0, sp->sct_own, "%s (%.2f) produced in %s\n",
               product->p_name, output, ownxy(sp));
        }
@@ -181,16 +181,14 @@ prod_output(struct sctstr *sp, double prodeff)
 
 /*
  * Return how much of product @pp can be made from materials @vec[].
- * Store amount of work per unit in *@costp.
  */
-double
-prod_materials_cost(struct pchrstr *pp, short vec[], int *costp)
+static double
+prod_materials_cost(struct pchrstr *pp, short vec[])
 {
     double count, n;
-    int cost, i;
+    int i;
 
     count = ITEM_MAX;
-    cost = 0;
     for (i = 0; i < MAXPRCON; ++i) {
        if (!pp->p_camt[i])
            continue;
@@ -199,9 +197,7 @@ prod_materials_cost(struct pchrstr *pp, short vec[], int *costp)
        n = (double)vec[pp->p_ctype[i]] / pp->p_camt[i];
        if (n < count)
            count = n;
-       cost += pp->p_camt[i];
     }
-    *costp = cost;
     return count;
 }
 
@@ -229,7 +225,7 @@ materials_charge(struct pchrstr *pp, short *vec, double count)
  * Return how much of product @pp can be made from its resource.
  * If @pp depletes a resource, @resource must point to its value.
  */
-double
+static double
 prod_resource_limit(struct pchrstr *pp, unsigned char *resource)
 {
     if (CANT_HAPPEN(pp->p_nrndx && !resource))