simplicate and add lightness

This commit is contained in:
Enno Rehling 2020-01-14 21:00:54 +01:00
parent 6626cfe297
commit 27aac671a4
1 changed files with 10 additions and 9 deletions

View File

@ -1061,9 +1061,9 @@ static const attrib_type at_trades = {
NO_READ NO_READ
}; };
static int trade_add(unit *u, int n) { static int trade_add(unit *u, int wants, int skill) {
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */ /* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
int k = u->number * 10 * effskill(u, SK_TRADE, NULL); int k = u->number * 10 * skill;
attrib *a = a_find(u->attribs, &at_trades); attrib *a = a_find(u->attribs, &at_trades);
/* hat der Haendler bereits gehandelt, muss die Menge der bereits /* hat der Haendler bereits gehandelt, muss die Menge der bereits
@ -1075,11 +1075,11 @@ static int trade_add(unit *u, int n) {
k -= a->data.i; k -= a->data.i;
} }
if (n > k) n = k; if (wants > k) wants = k;
/* die Menge der verkauften Gueter merken */ /* die Menge der verkauften Gueter merken */
a->data.i += n; a->data.i += wants;
return n; return wants;
} }
static void expandbuying(region * r, econ_request * buyorders) static void expandbuying(region * r, econ_request * buyorders)
@ -1220,7 +1220,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
{ {
char token[128]; char token[128];
region *r = u->region; region *r = u->region;
int n; int n, skill = effskill(u, SK_TRADE, NULL);
econ_request *o; econ_request *o;
const item_type *itype = NULL; const item_type *itype = NULL;
const luxury_type *ltype = NULL; const luxury_type *ltype = NULL;
@ -1260,7 +1260,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
} }
} }
n = trade_add(u, n); n = trade_add(u, n, skill);
if (n <= 0) { if (n <= 0) {
cmistake(u, ord, 102, MSG_COMMERCE); cmistake(u, ord, 102, MSG_COMMERCE);
return; return;
@ -1386,10 +1386,11 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
const luxury_type *search = NULL; const luxury_type *search = NULL;
const luxury_type *ltype = g_requests[j]->data.trade.ltype; const luxury_type *ltype = g_requests[j]->data.trade.ltype;
int multi = r_demand(r, ltype); int multi = r_demand(r, ltype);
int i, price; int i, price, skill;
int use = 0; int use = 0;
u = g_requests[j]->unit; u = g_requests[j]->unit;
skill = effskill(u, SK_TRADE, NULL);
for (i = 0, search = luxurytypes; search != ltype; search = search->next) { for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
/* TODO: this is slow and lame! */ /* TODO: this is slow and lame! */
++i; ++i;
@ -1401,7 +1402,7 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
price = ltype->price * multi; price = ltype->price * multi;
if (money >= price) { if (money >= price) {
if (trade_add(u, 1) != 1) { if (trade_add(u, 1, skill) != 1) {
break; break;
} }
else { else {