pull economy requests into header, rename the struct.

This commit is contained in:
Enno Rehling 2017-12-04 19:20:48 +01:00
parent c124702ffe
commit 05425b5101
9 changed files with 121 additions and 119 deletions

View File

@ -45,28 +45,35 @@ int tolua_shiplist_next(lua_State * L)
static int tolua_ship_get_id(lua_State * L) static int tolua_ship_get_id(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->no); lua_pushinteger(L, self->no);
return 1; return 1;
} }
static int tolua_ship_get_name(lua_State * L) static int tolua_ship_get_name(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, ship_getname(self)); tolua_pushstring(L, ship_getname(self));
return 1; return 1;
} }
static int tolua_ship_get_size(lua_State * L)
{
ship *self = (ship *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->size);
return 1;
}
static int tolua_ship_get_display(lua_State * L) static int tolua_ship_get_display(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, self->display); tolua_pushstring(L, self->display);
return 1; return 1;
} }
static int tolua_ship_get_region(lua_State * L) static int tolua_ship_get_region(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
if (self) { if (self) {
tolua_pushusertype(L, self->region, TOLUA_CAST "region"); tolua_pushusertype(L, self->region, TOLUA_CAST "region");
return 1; return 1;
@ -76,8 +83,8 @@ static int tolua_ship_get_region(lua_State * L)
static int tolua_ship_set_region(lua_State * L) static int tolua_ship_set_region(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
region *r = (region *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 2, NULL);
if (self) { if (self) {
move_ship(self, self->region, r, NULL); move_ship(self, self->region, r, NULL);
} }
@ -86,22 +93,29 @@ static int tolua_ship_set_region(lua_State * L)
static int tolua_ship_set_name(lua_State * L) static int tolua_ship_set_name(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
ship_setname(self, tolua_tostring(L, 2, 0)); ship_setname(self, tolua_tostring(L, 2, NULL));
return 0;
}
static int tolua_ship_set_size(lua_State * L)
{
ship *self = (ship *)tolua_tousertype(L, 1, NULL);
self->size = lua_tointeger(L, 2);
return 0; return 0;
} }
static int tolua_ship_set_display(lua_State * L) static int tolua_ship_set_display(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
free(self->display); free(self->display);
self->display = strdup(tolua_tostring(L, 2, 0)); self->display = strdup(tolua_tostring(L, 2, NULL));
return 0; return 0;
} }
static int tolua_ship_get_units(lua_State * L) static int tolua_ship_get_units(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *)); unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
unit *u = self->region->units; unit *u = self->region->units;
@ -118,8 +132,8 @@ static int tolua_ship_get_units(lua_State * L)
static int tolua_ship_create(lua_State * L) static int tolua_ship_create(lua_State * L)
{ {
region *r = (region *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 1, NULL);
const char *sname = tolua_tostring(L, 2, 0); const char *sname = tolua_tostring(L, 2, NULL);
if (sname) { if (sname) {
const ship_type *stype = st_find(sname); const ship_type *stype = st_find(sname);
if (stype) { if (stype) {
@ -138,40 +152,40 @@ static int tolua_ship_create(lua_State * L)
static int static int
tolua_ship_tostring(lua_State * L) tolua_ship_tostring(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
lua_pushstring(L, shipname(self)); lua_pushstring(L, shipname(self));
return 1; return 1;
} }
static int tolua_ship_get_flags(lua_State * L) static int tolua_ship_get_flags(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->flags); lua_pushinteger(L, self->flags);
return 1; return 1;
} }
static int tolua_ship_set_flags(lua_State * L) static int tolua_ship_set_flags(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
self->flags = (int)tolua_tonumber(L, 2, 0); self->flags = (int)lua_tointeger(L, 2);
return 0; return 0;
} }
static int tolua_ship_set_coast(lua_State * L) static int tolua_ship_set_coast(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
if (lua_isnil(L, 2)) { if (lua_isnil(L, 2)) {
self->coast = NODIRECTION; self->coast = NODIRECTION;
} }
else if (lua_isnumber(L, 2)) { else if (lua_isnumber(L, 2)) {
self->coast = (direction_t)tolua_tonumber(L, 2, 0); self->coast = (direction_t)lua_tointeger(L, 2);
} }
return 0; return 0;
} }
static int tolua_ship_get_coast(lua_State * L) static int tolua_ship_get_coast(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
if (self->coast) { if (self->coast) {
lua_pushinteger(L, self->coast); lua_pushinteger(L, self->coast);
return 1; return 1;
@ -181,28 +195,28 @@ static int tolua_ship_get_coast(lua_State * L)
static int tolua_ship_get_type(lua_State * L) static int tolua_ship_get_type(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, self->type->_name); tolua_pushstring(L, self->type->_name);
return 1; return 1;
} }
static int tolua_ship_get_damage(lua_State * L) static int tolua_ship_get_damage(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->damage); lua_pushinteger(L, self->damage);
return 1; return 1;
} }
static int tolua_ship_set_damage(lua_State * L) static int tolua_ship_set_damage(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
self->damage = (int)tolua_tonumber(L, 2, 0); self->damage = (int)lua_tointeger(L, 2);
return 0; return 0;
} }
static int tolua_ship_get_curse(lua_State *L) { static int tolua_ship_get_curse(lua_State *L) {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, 0); const char *name = tolua_tostring(L, 2, NULL);
if (self->attribs) { if (self->attribs) {
curse * c = get_curse(self->attribs, ct_find(name)); curse * c = get_curse(self->attribs, ct_find(name));
if (c) { if (c) {
@ -214,8 +228,8 @@ static int tolua_ship_get_curse(lua_State *L) {
} }
static int tolua_ship_has_attrib(lua_State *L) { static int tolua_ship_has_attrib(lua_State *L) {
ship *self = (ship *)tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, 0); const char *name = tolua_tostring(L, 2, NULL);
attrib * a = a_find(self->attribs, at_find(name)); attrib * a = a_find(self->attribs, at_find(name));
lua_pushboolean(L, a != NULL); lua_pushboolean(L, a != NULL);
return 1; return 1;
@ -236,6 +250,8 @@ void tolua_ship_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL); tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL);
tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name, tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name,
tolua_ship_set_name); tolua_ship_set_name);
tolua_variable(L, TOLUA_CAST "size", tolua_ship_get_size,
tolua_ship_set_size);
tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display, tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display,
tolua_ship_set_display); tolua_ship_set_display);
tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL); tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL);

View File

@ -1388,7 +1388,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
else { else {
fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION); fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION);
} }
if (production(r)) { if (max_production(r)) {
int p_wage = wage(r, NULL, NULL, turn + 1); int p_wage = wage(r, NULL, NULL, turn + 1);
fprintf(F, "%d;Lohn\n", p_wage); fprintf(F, "%d;Lohn\n", p_wage);
if (is_mourning(r, turn + 1)) { if (is_mourning(r, turn + 1)) {

View File

@ -81,26 +81,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
typedef struct request {
struct request *next;
struct unit *unit;
struct order *ord;
int qty;
int no;
union {
bool goblin; /* stealing */
const struct luxury_type *ltype; /* trading */
} type;
} request;
static int working; static int working;
static request entertainers[1024]; static production entertainers[1024];
static request *nextentertainer; static production *nextentertainer;
static int entertaining; static int entertaining;
static unsigned int norders; static unsigned int norders;
static request *g_requests; static production *g_requests;
#define RECRUIT_MERGE 1 #define RECRUIT_MERGE 1
static int rules_recruit = -1; static int rules_recruit = -1;
@ -153,12 +141,12 @@ static void scramble(void *data, unsigned int n, size_t width)
} }
} }
static void expandorders(region * r, request * requests) static void expandorders(region * r, production * requests)
{ {
unit *u; unit *u;
request *o; production *o;
/* Alle Units ohne request haben ein -1, alle units mit orders haben ein /* Alle Units ohne production haben ein -1, alle units mit orders haben ein
* 0 hier stehen */ * 0 hier stehen */
for (u = r->units; u; u = u->next) for (u = r->units; u; u = u->next)
@ -174,7 +162,7 @@ static void expandorders(region * r, request * requests)
if (norders > 0) { if (norders > 0) {
int i = 0; int i = 0;
g_requests = (request *)calloc(norders, sizeof(request)); g_requests = (production *)calloc(norders, sizeof(production));
for (o = requests; o; o = o->next) { for (o = requests; o; o = o->next) {
if (o->qty > 0) { if (o->qty > 0) {
unsigned int j; unsigned int j;
@ -185,13 +173,13 @@ static void expandorders(region * r, request * requests)
} }
} }
} }
scramble(g_requests, norders, sizeof(request)); scramble(g_requests, norders, sizeof(production));
} }
else { else {
g_requests = NULL; g_requests = NULL;
} }
while (requests) { while (requests) {
request *o = requests->next; production *o = requests->next;
free_order(requests->ord); free_order(requests->ord);
free(requests); free(requests);
requests = o; requests = o;
@ -203,21 +191,21 @@ static void expandorders(region * r, request * requests)
typedef struct recruitment { typedef struct recruitment {
struct recruitment *next; struct recruitment *next;
faction *f; faction *f;
request *requests; production *requests;
int total, assigned; int total, assigned;
} recruitment; } recruitment;
/** Creates a list of recruitment structs, one for each faction. Adds every quantifyable request /** Creates a list of recruitment structs, one for each faction. Adds every quantifyable production
* to the faction's struct and to total. * to the faction's struct and to total.
*/ */
static recruitment *select_recruitment(request ** rop, static recruitment *select_recruitment(production ** rop,
int(*quantify) (const struct race *, int), int *total) int(*quantify) (const struct race *, int), int *total)
{ {
recruitment *recruits = NULL; recruitment *recruits = NULL;
while (*rop) { while (*rop) {
recruitment *rec = recruits; recruitment *rec = recruits;
request *ro = *rop; production *ro = *rop;
unit *u = ro->unit; unit *u = ro->unit;
const race *rc = u_race(u); const race *rc = u_race(u);
int qty = quantify(rc, ro->qty); int qty = quantify(rc, ro->qty);
@ -294,7 +282,7 @@ static int do_recruiting(recruitment * recruits, int available)
int n = 0; int n = 0;
int rest, mintotal = INT_MAX; int rest, mintotal = INT_MAX;
/* find smallest request */ /* find smallest production */
for (rec = recruits; rec != NULL; rec = rec->next) { for (rec = recruits; rec != NULL; rec = rec->next) {
int want = rec->total - rec->assigned; int want = rec->total - rec->assigned;
if (want > 0) { if (want > 0) {
@ -310,7 +298,7 @@ static int do_recruiting(recruitment * recruits, int available)
} }
rest = available - mintotal * n; rest = available - mintotal * n;
/* assign size of smallest request for everyone if possible; in the end roll dice to assign /* assign size of smallest production for everyone if possible; in the end roll dice to assign
* small rest */ * small rest */
for (rec = recruits; rec != NULL; rec = rec->next) { for (rec = recruits; rec != NULL; rec = rec->next) {
int want = rec->total - rec->assigned; int want = rec->total - rec->assigned;
@ -330,7 +318,7 @@ static int do_recruiting(recruitment * recruits, int available)
/* do actual recruiting */ /* do actual recruiting */
for (rec = recruits; rec != NULL; rec = rec->next) { for (rec = recruits; rec != NULL; rec = rec->next) {
request *req; production *req;
int get = rec->assigned; int get = rec->assigned;
for (req = rec->requests; req; req = req->next) { for (req = rec->requests; req; req = req->next) {
@ -379,7 +367,7 @@ void free_recruitments(recruitment * recruits)
recruitment *rec = recruits; recruitment *rec = recruits;
recruits = rec->next; recruits = rec->next;
while (rec->requests) { while (rec->requests) {
request *req = rec->requests; production *req = rec->requests;
rec->requests = req->next; rec->requests = req->next;
free_order(req->ord); free_order(req->ord);
free(req); free(req);
@ -389,7 +377,7 @@ void free_recruitments(recruitment * recruits)
} }
/* Rekrutierung */ /* Rekrutierung */
static void expandrecruit(region * r, request * recruitorders) static void expandrecruit(region * r, production * recruitorders)
{ {
recruitment *recruits = NULL; recruitment *recruits = NULL;
@ -430,11 +418,11 @@ static int recruit_cost(const faction * f, const race * rc)
return -1; return -1;
} }
static void recruit(unit * u, struct order *ord, request ** recruitorders) static void recruit(unit * u, struct order *ord, production ** recruitorders)
{ {
region *r = u->region; region *r = u->region;
plane *pl; plane *pl;
request *o; production *o;
int recruitcost = -1; int recruitcost = -1;
const faction *f = u->faction; const faction *f = u->faction;
const struct race *rc = u_race(u); const struct race *rc = u_race(u);
@ -555,7 +543,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
return; return;
} }
o = (request *)calloc(1, sizeof(request)); o = (production *)calloc(1, sizeof(production));
o->qty = n; o->qty = n;
o->unit = u; o->unit = u;
o->ord = copy_order(ord); o->ord = copy_order(ord);
@ -751,7 +739,7 @@ void maintain_buildings(region * r)
void economics(region * r) void economics(region * r)
{ {
unit *u; unit *u;
request *recruitorders = NULL; production *recruitorders = NULL;
/* Geben vor Selbstmord (doquit)! Hier alle unmittelbaren Befehle. /* Geben vor Selbstmord (doquit)! Hier alle unmittelbaren Befehle.
* Rekrutieren vor allen Einnahmequellen. Bewachen JA vor Steuern * Rekrutieren vor allen Einnahmequellen. Bewachen JA vor Steuern
@ -1441,7 +1429,7 @@ const attrib_type at_luxuries = {
"luxuries", NULL, free_luxuries, NULL, NULL, NULL "luxuries", NULL, free_luxuries, NULL, NULL, NULL
}; };
static void expandbuying(region * r, request * buyorders) static void expandbuying(region * r, production * buyorders)
{ {
const resource_type *rsilver = get_resourcetype(R_SILVER); const resource_type *rsilver = get_resourcetype(R_SILVER);
int max_products; int max_products;
@ -1554,12 +1542,12 @@ attrib_type at_trades = {
NO_READ NO_READ
}; };
static void buy(unit * u, request ** buyorders, struct order *ord) static void buy(unit * u, production ** buyorders, struct order *ord)
{ {
char token[128]; char token[128];
region *r = u->region; region *r = u->region;
int n, k; int n, k;
request *o; production *o;
attrib *a; attrib *a;
const item_type *itype = NULL; const item_type *itype = NULL;
const luxury_type *ltype = NULL; const luxury_type *ltype = NULL;
@ -1650,7 +1638,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "luxury_notsold", "")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "luxury_notsold", ""));
return; return;
} }
o = (request *)calloc(1, sizeof(request)); o = (production *)calloc(1, sizeof(production));
o->type.ltype = ltype; /* sollte immer gleich sein */ o->type.ltype = ltype; /* sollte immer gleich sein */
o->unit = u; o->unit = u;
@ -1670,7 +1658,7 @@ static void add_income(unit * u, int type, int want, int qty)
/* Steuers<72>tze in % bei Burggr<67><72>e */ /* Steuers<72>tze in % bei Burggr<67><72>e */
static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 }; static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 };
static void expandselling(region * r, request * sellorders, int limit) static void expandselling(region * r, production * sellorders, int limit)
{ {
int money, price, max_products; int money, price, max_products;
unsigned int j; unsigned int j;
@ -1859,7 +1847,7 @@ static void expandselling(region * r, request * sellorders, int limit)
} }
} }
static bool sell(unit * u, request ** sellorders, struct order *ord) static bool sell(unit * u, production ** sellorders, struct order *ord)
{ {
char token[128]; char token[128];
bool unlimited = true; bool unlimited = true;
@ -1952,7 +1940,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
} }
else { else {
attrib *a; attrib *a;
request *o; production *o;
int k, available; int k, available;
if (!r_demand(r, ltype)) { if (!r_demand(r, ltype)) {
@ -1977,7 +1965,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
cmistake(u, ord, 264, MSG_COMMERCE); cmistake(u, ord, 264, MSG_COMMERCE);
return false; return false;
} }
/* Hier wird request->type verwendet, weil die obere limit durch /* Hier wird production->type verwendet, weil die obere limit durch
* das silber gegeben wird (region->money), welches f<EFBFBD>r alle * das silber gegeben wird (region->money), welches f<EFBFBD>r alle
* (!) produkte als summe gilt, als nicht wie bei der * (!) produkte als summe gilt, als nicht wie bei der
* produktion, wo f<EFBFBD>r jedes produkt einzeln eine obere limite * produktion, wo f<EFBFBD>r jedes produkt einzeln eine obere limite
@ -2000,7 +1988,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
assert(n >= 0); assert(n >= 0);
/* die Menge der verkauften G<>ter merken */ /* die Menge der verkauften G<>ter merken */
a->data.i += n; a->data.i += n;
o = (request *)calloc(1, sizeof(request)); o = (production *)calloc(1, sizeof(production));
o->unit = u; o->unit = u;
o->qty = n; o->qty = n;
o->type.ltype = ltype; o->type.ltype = ltype;
@ -2012,7 +2000,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static void expandstealing(region * r, request * stealorders) static void expandstealing(region * r, production * stealorders)
{ {
const resource_type *rsilver = get_resourcetype(R_SILVER); const resource_type *rsilver = get_resourcetype(R_SILVER);
unsigned int j; unsigned int j;
@ -2406,12 +2394,12 @@ message * check_steal(const unit * u, struct order *ord) {
return 0; return 0;
} }
static void steal_cmd(unit * u, struct order *ord, request ** stealorders) static void steal_cmd(unit * u, struct order *ord, production ** stealorders)
{ {
const resource_type *rring = get_resourcetype(R_RING_OF_NIMBLEFINGER); const resource_type *rring = get_resourcetype(R_RING_OF_NIMBLEFINGER);
int n, i, id, effsk; int n, i, id, effsk;
bool goblin = false; bool goblin = false;
request *o; production *o;
unit *u2 = NULL; unit *u2 = NULL;
region *r = u->region; region *r = u->region;
faction *f = NULL; faction *f = NULL;
@ -2508,7 +2496,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
/* wer dank unsichtbarkeitsringen klauen kann, muss nicht unbedingt ein /* wer dank unsichtbarkeitsringen klauen kann, muss nicht unbedingt ein
* guter dieb sein, schliesslich macht man immer noch sehr viel laerm */ * guter dieb sein, schliesslich macht man immer noch sehr viel laerm */
o = (request *)calloc(1, sizeof(request)); o = (production *)calloc(1, sizeof(production));
o->unit = u; o->unit = u;
o->qty = 1; /* Betrag steht in u->wants */ o->qty = 1; /* Betrag steht in u->wants */
o->no = u2->no; o->no = u2->no;
@ -2526,7 +2514,7 @@ static void expandentertainment(region * r)
{ {
unit *u; unit *u;
int m = entertainmoney(r); int m = entertainmoney(r);
request *o; production *o;
for (o = &entertainers[0]; o != nextentertainer; ++o) { for (o = &entertainers[0]; o != nextentertainer; ++o) {
double part = m / (double)entertaining; double part = m / (double)entertaining;
@ -2551,7 +2539,7 @@ void entertain_cmd(unit * u, struct order *ord)
{ {
region *r = u->region; region *r = u->region;
int max_e; int max_e;
request *o; production *o;
static int entertainbase = 0; static int entertainbase = 0;
static int entertainperlevel = 0; static int entertainperlevel = 0;
keyword_t kwd; keyword_t kwd;
@ -2604,7 +2592,7 @@ void entertain_cmd(unit * u, struct order *ord)
* \return number of working spaces taken by players * \return number of working spaces taken by players
*/ */
static void static void
expandwork(region * r, request * work_begin, request * work_end, int maxwork) expandwork(region * r, production * work_begin, production * work_end, int maxwork)
{ {
int earnings; int earnings;
/* n: verbleibende Einnahmen */ /* n: verbleibende Einnahmen */
@ -2612,7 +2600,7 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork)
int jobs = maxwork; int jobs = maxwork;
int p_wage = wage(r, NULL, NULL, turn); int p_wage = wage(r, NULL, NULL, turn);
int money = rmoney(r); int money = rmoney(r);
request *o; production *o;
for (o = work_begin; o != work_end; ++o) { for (o = work_begin; o != work_end; ++o) {
unit *u = o->unit; unit *u = o->unit;
@ -2655,7 +2643,7 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork)
rsetmoney(r, money + earnings); rsetmoney(r, money + earnings);
} }
static int do_work(unit * u, order * ord, request * o) static int do_work(unit * u, order * ord, production * o)
{ {
if (playerrace(u_race(u))) { if (playerrace(u_race(u))) {
region *r = u->region; region *r = u->region;
@ -2690,7 +2678,7 @@ static int do_work(unit * u, order * ord, request * o)
return -1; return -1;
} }
static void expandloot(region * r, request * lootorders) static void expandloot(region * r, production * lootorders)
{ {
unit *u; unit *u;
unsigned int i; unsigned int i;
@ -2727,7 +2715,7 @@ static void expandloot(region * r, request * lootorders)
} }
} }
void expandtax(region * r, request * taxorders) void expandtax(region * r, production * taxorders)
{ {
unit *u; unit *u;
unsigned int i; unsigned int i;
@ -2751,13 +2739,13 @@ void expandtax(region * r, request * taxorders)
} }
} }
void tax_cmd(unit * u, struct order *ord, request ** taxorders) void tax_cmd(unit * u, struct order *ord, production ** taxorders)
{ {
/* Steuern werden noch vor der Forschung eingetrieben */ /* Steuern werden noch vor der Forschung eingetrieben */
region *r = u->region; region *r = u->region;
unit *u2; unit *u2;
int n; int n;
request *o; production *o;
int max; int max;
keyword_t kwd; keyword_t kwd;
static int taxperlevel = 0; static int taxperlevel = 0;
@ -2819,20 +2807,20 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
* fraktionen werden dann bei eintreiben unter allen eintreibenden * fraktionen werden dann bei eintreiben unter allen eintreibenden
* einheiten aufgeteilt. */ * einheiten aufgeteilt. */
o = (request *)calloc(1, sizeof(request)); o = (production *)calloc(1, sizeof(production));
o->qty = u->wants / TAXFRACTION; o->qty = u->wants / TAXFRACTION;
o->unit = u; o->unit = u;
addlist(taxorders, o); addlist(taxorders, o);
return; return;
} }
void loot_cmd(unit * u, struct order *ord, request ** lootorders) void loot_cmd(unit * u, struct order *ord, production ** lootorders)
{ {
region *r = u->region; region *r = u->region;
unit *u2; unit *u2;
int n; int n;
int max; int max;
request *o; production *o;
keyword_t kwd; keyword_t kwd;
kwd = init_order_depr(ord); kwd = init_order_depr(ord);
@ -2884,7 +2872,7 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders)
u->wants = MIN(n * skbonus * 10, max); u->wants = MIN(n * skbonus * 10, max);
} }
o = (request *)calloc(1, sizeof(request)); o = (production *)calloc(1, sizeof(production));
o->qty = u->wants / TAXFRACTION; o->qty = u->wants / TAXFRACTION;
o->unit = u; o->unit = u;
addlist(lootorders, o); addlist(lootorders, o);
@ -2895,8 +2883,8 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders)
#define MAX_WORKERS 2048 #define MAX_WORKERS 2048
void auto_work(region * r) void auto_work(region * r)
{ {
request workers[MAX_WORKERS]; production workers[MAX_WORKERS];
request *nextworker = workers; production *nextworker = workers;
unit *u; unit *u;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
@ -2964,11 +2952,11 @@ static bool rule_autowork(void) {
void produce(struct region *r) void produce(struct region *r)
{ {
request workers[MAX_WORKERS]; production workers[MAX_WORKERS];
request *taxorders, *lootorders, *sellorders, *stealorders, *buyorders; production *taxorders, *lootorders, *sellorders, *stealorders, *buyorders;
unit *u; unit *u;
bool limited = true; bool limited = true;
request *nextworker = workers; production *nextworker = workers;
static int bt_cache; static int bt_cache;
static const struct building_type *caravan_bt; static const struct building_type *caravan_bt;
static int rc_cache; static int rc_cache;

View File

@ -45,7 +45,18 @@ extern "C" {
struct faction; struct faction;
struct order; struct order;
struct message; struct message;
struct request;
typedef struct production {
struct production *next;
struct unit *unit;
struct order *ord;
int qty;
int no;
union {
bool goblin; /* stealing */
const struct luxury_type *ltype; /* trading */
} type;
} production;
int income(const struct unit *u); int income(const struct unit *u);
int entertainmoney(const struct region *r); int entertainmoney(const struct region *r);
@ -61,8 +72,8 @@ extern "C" {
void split_allocations(struct region *r); void split_allocations(struct region *r);
int give_control_cmd(struct unit *u, struct order *ord); int give_control_cmd(struct unit *u, struct order *ord);
void give_control(struct unit * u, struct unit * u2); void give_control(struct unit * u, struct unit * u2);
void tax_cmd(struct unit * u, struct order *ord, struct request ** taxorders); void tax_cmd(struct unit * u, struct order *ord, struct production ** taxorders);
void expandtax(struct region * r, struct request * taxorders); void expandtax(struct region * r, struct production * taxorders);
void add_recruits(struct unit * u, int number, int wanted); void add_recruits(struct unit * u, int number, int wanted);
struct message * check_steal(const struct unit * u, struct order *ord); struct message * check_steal(const struct unit * u, struct order *ord);

View File

@ -300,26 +300,13 @@ static void test_buy_cmd(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
typedef struct request {
struct request *next;
struct unit *unit;
struct order *ord;
int qty;
int no;
union {
bool goblin; /* stealing */
const struct luxury_type *ltype; /* trading */
} type;
} request;
static void test_tax_cmd(CuTest *tc) { static void test_tax_cmd(CuTest *tc) {
order *ord; order *ord;
faction *f; faction *f;
region *r; region *r;
unit *u; unit *u;
item_type *sword, *silver; item_type *sword, *silver;
request *taxorders = 0; production *taxorders = 0;
test_setup(); test_setup();
init_resources(); init_resources();

View File

@ -139,7 +139,7 @@ const char *regionname(const region * r, const faction * f)
int region_maxworkers(const region *r) int region_maxworkers(const region *r)
{ {
int size = production(r); int size = max_production(r);
int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE; int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE;
return MAX(size - treespace, MIN(size / 10, 200)); return MAX(size - treespace, MIN(size / 10, 200));
} }
@ -1244,7 +1244,7 @@ void terraform_region(region * r, const terrain_type * terrain)
* egal ob durch den spell oder anderes angelegt. * egal ob durch den spell oder anderes angelegt.
**/ **/
#include "curse.h" #include "curse.h"
int production(const region * r) int max_production(const region * r)
{ {
/* muß rterrain(r) sein, nicht rterrain() wegen rekursion */ /* muß rterrain(r) sein, nicht rterrain() wegen rekursion */
int p = r->terrain->size; int p = r->terrain->size;

View File

@ -240,7 +240,7 @@ extern "C" {
extern const int delta_x[MAXDIRECTIONS]; extern const int delta_x[MAXDIRECTIONS];
extern const int delta_y[MAXDIRECTIONS]; extern const int delta_y[MAXDIRECTIONS];
direction_t dir_invert(direction_t dir); direction_t dir_invert(direction_t dir);
int production(const struct region *r); int max_production(const struct region *r);
void region_set_owner(struct region *r, struct faction *owner, int turn); void region_set_owner(struct region *r, struct faction *owner, int turn);
struct faction *region_get_owner(const struct region *r); struct faction *region_get_owner(const struct region *r);

View File

@ -314,7 +314,7 @@ static void peasants(region * r, int rule)
{ {
int peasants = rpeasants(r); int peasants = rpeasants(r);
int money = rmoney(r); int money = rmoney(r);
int maxp = production(r); int maxp = max_production(r);
int n, satiated; int n, satiated;
int dead = 0; int dead = 0;
@ -588,12 +588,12 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
return; return;
} }
if (production(r) <= 0) if (max_production(r) <= 0)
return; return;
/* Grundchance 1.0% */ /* Grundchance 1.0% */
/* Jeder Elf in der Region erhöht die Chance marginal */ /* Jeder Elf in der Region erhöht die Chance marginal */
elves = MIN(elves, production(r) / 8); elves = MIN(elves, max_production(r) / 8);
if (elves) { if (elves) {
seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY); seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY);
} }

View File

@ -974,7 +974,7 @@ void report_region(struct stream *out, const region * r, faction * f)
/* Trees */ /* Trees */
trees = rtrees(r, 2); trees = rtrees(r, 2);
saplings = rtrees(r, 1); saplings = rtrees(r, 1);
if (production(r)) { if (max_production(r)) {
if (trees > 0 || saplings > 0) { if (trees > 0 || saplings > 0) {
bytes = snprintf(bufp, size, ", %d/%d ", trees, saplings); bytes = snprintf(bufp, size, ", %d/%d ", trees, saplings);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
@ -1311,7 +1311,7 @@ static void statistics(struct stream *out, const region * r, const faction * f)
paragraph(out, buf, 2, 2, 0); paragraph(out, buf, 2, 2, 0);
msg_release(m); msg_release(m);
} }
if (production(r) && (!fval(r->terrain, SEA_REGION) if (max_production(r) && (!fval(r->terrain, SEA_REGION)
|| f->race == get_race(RC_AQUARIAN))) { || f->race == get_race(RC_AQUARIAN))) {
if (markets_module()) { /* hack */ if (markets_module()) { /* hack */
m = m =