forked from github/server
parent
27aac671a4
commit
3b09b401f7
189
src/economy.c
189
src/economy.c
|
@ -1052,36 +1052,6 @@ const attrib_type at_luxuries = {
|
|||
"luxuries", NULL, free_luxuries, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const attrib_type at_trades = {
|
||||
"trades",
|
||||
DEFAULT_INIT,
|
||||
DEFAULT_FINALIZE,
|
||||
DEFAULT_AGE,
|
||||
NO_WRITE,
|
||||
NO_READ
|
||||
};
|
||||
|
||||
static int trade_add(unit *u, int wants, int skill) {
|
||||
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
||||
int k = u->number * 10 * skill;
|
||||
|
||||
attrib *a = a_find(u->attribs, &at_trades);
|
||||
/* hat der Haendler bereits gehandelt, muss die Menge der bereits
|
||||
* verkauften/gekauften Gueter abgezogen werden */
|
||||
if (!a) {
|
||||
a = a_add(&u->attribs, a_new(&at_trades));
|
||||
}
|
||||
else {
|
||||
k -= a->data.i;
|
||||
}
|
||||
|
||||
if (wants > k) wants = k;
|
||||
|
||||
/* die Menge der verkauften Gueter merken */
|
||||
a->data.i += wants;
|
||||
return wants;
|
||||
}
|
||||
|
||||
static void expandbuying(region * r, econ_request * buyorders)
|
||||
{
|
||||
const resource_type *rsilver = get_resourcetype(R_SILVER);
|
||||
|
@ -1150,16 +1120,15 @@ static void expandbuying(region * r, econ_request * buyorders)
|
|||
a->data.v = items;
|
||||
i_change(&g_requests[j]->unit->items, ltype->itype, 1);
|
||||
use_pooled(u, rsilver, GET_DEFAULT, price);
|
||||
if (u->n < 0) {
|
||||
if (u->n < 0)
|
||||
u->n = 0;
|
||||
}
|
||||
u->n += price;
|
||||
|
||||
rsetmoney(r, rmoney(r) + price);
|
||||
|
||||
/* Falls mehr als max_products Bauern ein Produkt verkauft haben, steigt
|
||||
* der Preis Multiplikator fuer das Produkt um den Faktor 1. Der Zaehler
|
||||
* wird wieder auf 0 gesetzt. */
|
||||
* der Preis Multiplikator fuer das Produkt um den Faktor 1. Der Zaehler
|
||||
* wird wieder auf 0 gesetzt. */
|
||||
if (++trade->number == max_products) {
|
||||
trade->number = 0;
|
||||
++trade->multi;
|
||||
|
@ -1189,6 +1158,15 @@ static void expandbuying(region * r, econ_request * buyorders)
|
|||
}
|
||||
}
|
||||
|
||||
attrib_type at_trades = {
|
||||
"trades",
|
||||
DEFAULT_INIT,
|
||||
DEFAULT_FINALIZE,
|
||||
DEFAULT_AGE,
|
||||
NO_WRITE,
|
||||
NO_READ
|
||||
};
|
||||
|
||||
bool trade_needs_castle(const terrain_type *terrain, const race *rc)
|
||||
{
|
||||
static int rc_change, terrain_change;
|
||||
|
@ -1220,8 +1198,9 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
|
|||
{
|
||||
char token[128];
|
||||
region *r = u->region;
|
||||
int n, skill = effskill(u, SK_TRADE, NULL);
|
||||
int n, k;
|
||||
econ_request *o;
|
||||
attrib *a;
|
||||
const item_type *itype = NULL;
|
||||
const luxury_type *ltype = NULL;
|
||||
keyword_t kwd;
|
||||
|
@ -1260,12 +1239,30 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
|
|||
}
|
||||
}
|
||||
|
||||
n = trade_add(u, n, skill);
|
||||
if (n <= 0) {
|
||||
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
||||
k = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
||||
|
||||
/* hat der Haendler bereits gehandelt, muss die Menge der bereits
|
||||
* verkauften/gekauften Gueter abgezogen werden */
|
||||
a = a_find(u->attribs, &at_trades);
|
||||
if (!a) {
|
||||
a = a_add(&u->attribs, a_new(&at_trades));
|
||||
}
|
||||
else {
|
||||
k -= a->data.i;
|
||||
}
|
||||
|
||||
if (n > k) n = k;
|
||||
|
||||
if (!n) {
|
||||
cmistake(u, ord, 102, MSG_COMMERCE);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(n >= 0);
|
||||
/* die Menge der verkauften Gueter merken */
|
||||
a->data.i += n;
|
||||
|
||||
s = gettoken(token, sizeof(token));
|
||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||
if (itype != NULL) {
|
||||
|
@ -1312,7 +1309,8 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
|
|||
unit *maxowner = (unit *)NULL;
|
||||
building *maxb = (building *)NULL;
|
||||
building *b;
|
||||
unit *hafenowner, *u;
|
||||
unit *u;
|
||||
unit *hafenowner;
|
||||
static int counter[MAXLUXURIES];
|
||||
static int ncounter = 0;
|
||||
static int bt_cache;
|
||||
|
@ -1386,11 +1384,8 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
|
|||
const luxury_type *search = NULL;
|
||||
const luxury_type *ltype = g_requests[j]->data.trade.ltype;
|
||||
int multi = r_demand(r, ltype);
|
||||
int i, price, skill;
|
||||
int i, price;
|
||||
int use = 0;
|
||||
|
||||
u = g_requests[j]->unit;
|
||||
skill = effskill(u, SK_TRADE, NULL);
|
||||
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
|
||||
/* TODO: this is slow and lame! */
|
||||
++i;
|
||||
|
@ -1402,62 +1397,58 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
|
|||
price = ltype->price * multi;
|
||||
|
||||
if (money >= price) {
|
||||
if (trade_add(u, 1, skill) != 1) {
|
||||
break;
|
||||
item *itm;
|
||||
attrib *a;
|
||||
u = g_requests[j]->unit;
|
||||
a = a_find(u->attribs, &at_luxuries);
|
||||
if (!a) {
|
||||
a = a_add(&u->attribs, a_new(&at_luxuries));
|
||||
}
|
||||
itm = (item *)a->data.v;
|
||||
i_change(&itm, ltype->itype, 1);
|
||||
a->data.v = itm;
|
||||
++use;
|
||||
if (u->n < 0) {
|
||||
u->n = 0;
|
||||
}
|
||||
else {
|
||||
item *itm;
|
||||
attrib *a;
|
||||
a = a_find(u->attribs, &at_luxuries);
|
||||
if (!a) {
|
||||
a = a_add(&u->attribs, a_new(&at_luxuries));
|
||||
}
|
||||
itm = (item *)a->data.v;
|
||||
i_change(&itm, ltype->itype, 1);
|
||||
a->data.v = itm;
|
||||
++use;
|
||||
if (u->n < 0) {
|
||||
u->n = 0;
|
||||
}
|
||||
|
||||
if (hafenowner) {
|
||||
if (hafenowner->faction != u->faction) {
|
||||
int abgezogenhafen = price / 10;
|
||||
hafencollected += abgezogenhafen;
|
||||
price -= abgezogenhafen;
|
||||
money -= abgezogenhafen;
|
||||
}
|
||||
if (hafenowner) {
|
||||
if (hafenowner->faction != u->faction) {
|
||||
int abgezogenhafen = price / 10;
|
||||
hafencollected += abgezogenhafen;
|
||||
price -= abgezogenhafen;
|
||||
money -= abgezogenhafen;
|
||||
}
|
||||
if (maxb) {
|
||||
if (maxowner->faction != u->faction) {
|
||||
int abgezogensteuer = price * tax_per_size[maxeffsize] / 100;
|
||||
taxcollected += abgezogensteuer;
|
||||
price -= abgezogensteuer;
|
||||
money -= abgezogensteuer;
|
||||
}
|
||||
}
|
||||
if (maxb) {
|
||||
if (maxowner->faction != u->faction) {
|
||||
int abgezogensteuer = price * tax_per_size[maxeffsize] / 100;
|
||||
taxcollected += abgezogensteuer;
|
||||
price -= abgezogensteuer;
|
||||
money -= abgezogensteuer;
|
||||
}
|
||||
u->n += price;
|
||||
change_money(u, price);
|
||||
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
||||
}
|
||||
u->n += price;
|
||||
change_money(u, price);
|
||||
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
||||
|
||||
/* r->money -= price; --- dies wird eben nicht ausgefuehrt, denn die
|
||||
* Produkte koennen auch als Steuern eingetrieben werden. In der Region
|
||||
* wurden Silberstuecke gegen Luxusgueter des selben Wertes eingetauscht!
|
||||
* Falls mehr als max_products Kunden ein Produkt gekauft haben, sinkt
|
||||
* die Nachfrage fuer das Produkt um 1. Der Zaehler wird wieder auf 0
|
||||
* gesetzt. */
|
||||
/* r->money -= price; --- dies wird eben nicht ausgefuehrt, denn die
|
||||
* Produkte koennen auch als Steuern eingetrieben werden. In der Region
|
||||
* wurden Silberstuecke gegen Luxusgueter des selben Wertes eingetauscht!
|
||||
* Falls mehr als max_products Kunden ein Produkt gekauft haben, sinkt
|
||||
* die Nachfrage fuer das Produkt um 1. Der Zaehler wird wieder auf 0
|
||||
* gesetzt. */
|
||||
|
||||
if (++counter[i] > max_products) {
|
||||
int d = r_demand(r, ltype);
|
||||
if (d > 1) {
|
||||
r_setdemand(r, ltype, d - 1);
|
||||
}
|
||||
counter[i] = 0;
|
||||
if (++counter[i] > max_products) {
|
||||
int d = r_demand(r, ltype);
|
||||
if (d > 1) {
|
||||
r_setdemand(r, ltype, d - 1);
|
||||
}
|
||||
counter[i] = 0;
|
||||
}
|
||||
}
|
||||
if (use > 0) {
|
||||
use_pooled(u, ltype->itype->rtype, GET_DEFAULT, use);
|
||||
use_pooled(g_requests[j]->unit, ltype->itype->rtype, GET_DEFAULT, use);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1504,7 +1495,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
|
|||
bool unlimited = true;
|
||||
const item_type *itype;
|
||||
const luxury_type *ltype;
|
||||
int n, i;
|
||||
int n, k;
|
||||
region *r = u->region;
|
||||
const char *s;
|
||||
keyword_t kwd;
|
||||
|
@ -1555,8 +1546,9 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
|
|||
}
|
||||
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt verkaufen. */
|
||||
|
||||
i = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
||||
if (n > i) n = i;
|
||||
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
||||
k = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
||||
if (n > k) n = k;
|
||||
|
||||
if (!n) {
|
||||
cmistake(u, ord, 54, MSG_COMMERCE);
|
||||
|
@ -1570,8 +1562,9 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
|
|||
return false;
|
||||
}
|
||||
else {
|
||||
attrib *a;
|
||||
econ_request *o;
|
||||
int k, available;
|
||||
int available;
|
||||
|
||||
if (!r->land || !r_demand(r, ltype)) {
|
||||
cmistake(u, ord, 263, MSG_COMMERCE);
|
||||
|
@ -1602,12 +1595,20 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
|
|||
* produktion, wo fuer jedes produkt einzeln eine obere limite
|
||||
* existiert, so dass man arrays von orders machen kann. */
|
||||
|
||||
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
||||
k = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
||||
/* hat der Haendler bereits gehandelt, muss die Menge der bereits
|
||||
* verkauften/gekauften Gueter abgezogen werden */
|
||||
a = a_find(u->attribs, &at_trades);
|
||||
if (!a) {
|
||||
a = a_add(&u->attribs, a_new(&at_trades));
|
||||
}
|
||||
else {
|
||||
k -= a->data.i;
|
||||
}
|
||||
|
||||
if (n > k) n = k;
|
||||
assert(n >= 0);
|
||||
/* die Menge der verkauften Gueter merken */
|
||||
a->data.i += n;
|
||||
o = (econ_request *)calloc(1, sizeof(econ_request));
|
||||
if (!o) abort();
|
||||
o->unit = u;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
/* attributes includes */
|
||||
#include <attributes/racename.h>
|
||||
#include <attributes/movement.h>
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/attrib.h>
|
||||
|
@ -319,7 +318,7 @@ static void transfer_units(ship *s1, ship *s2)
|
|||
}
|
||||
|
||||
static bool ship_cursed(const ship *sh) {
|
||||
return a_find(sh->attribs, &at_curse) != NULL || a_find(sh->attribs, &at_speedup) != NULL;
|
||||
return a_find(sh->attribs, &at_curse) != NULL;
|
||||
}
|
||||
|
||||
message * give_ship(unit *u1, unit *u2, int n, order *ord)
|
||||
|
|
|
@ -31,7 +31,7 @@ struct order *ord)
|
|||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
|
||||
}
|
||||
else {
|
||||
if (u->ship && u->ship->number == 1) {
|
||||
if (u->ship) {
|
||||
attrib *a = a_find(u->ship->attribs, &at_speedup);
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->ship->attribs, a_new(&at_speedup));
|
||||
|
|
Loading…
Reference in New Issue