forked from github/server
parent
27aac671a4
commit
3b09b401f7
105
src/economy.c
105
src/economy.c
|
@ -1052,36 +1052,6 @@ const attrib_type at_luxuries = {
|
||||||
"luxuries", NULL, free_luxuries, NULL, NULL, NULL
|
"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)
|
static void expandbuying(region * r, econ_request * buyorders)
|
||||||
{
|
{
|
||||||
const resource_type *rsilver = get_resourcetype(R_SILVER);
|
const resource_type *rsilver = get_resourcetype(R_SILVER);
|
||||||
|
@ -1150,9 +1120,8 @@ static void expandbuying(region * r, econ_request * buyorders)
|
||||||
a->data.v = items;
|
a->data.v = items;
|
||||||
i_change(&g_requests[j]->unit->items, ltype->itype, 1);
|
i_change(&g_requests[j]->unit->items, ltype->itype, 1);
|
||||||
use_pooled(u, rsilver, GET_DEFAULT, price);
|
use_pooled(u, rsilver, GET_DEFAULT, price);
|
||||||
if (u->n < 0) {
|
if (u->n < 0)
|
||||||
u->n = 0;
|
u->n = 0;
|
||||||
}
|
|
||||||
u->n += price;
|
u->n += price;
|
||||||
|
|
||||||
rsetmoney(r, rmoney(r) + price);
|
rsetmoney(r, rmoney(r) + price);
|
||||||
|
@ -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)
|
bool trade_needs_castle(const terrain_type *terrain, const race *rc)
|
||||||
{
|
{
|
||||||
static int rc_change, terrain_change;
|
static int rc_change, terrain_change;
|
||||||
|
@ -1220,8 +1198,9 @@ 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, skill = effskill(u, SK_TRADE, NULL);
|
int n, k;
|
||||||
econ_request *o;
|
econ_request *o;
|
||||||
|
attrib *a;
|
||||||
const item_type *itype = NULL;
|
const item_type *itype = NULL;
|
||||||
const luxury_type *ltype = NULL;
|
const luxury_type *ltype = NULL;
|
||||||
keyword_t kwd;
|
keyword_t kwd;
|
||||||
|
@ -1260,12 +1239,30 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n = trade_add(u, n, skill);
|
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
||||||
if (n <= 0) {
|
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);
|
cmistake(u, ord, 102, MSG_COMMERCE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(n >= 0);
|
||||||
|
/* die Menge der verkauften Gueter merken */
|
||||||
|
a->data.i += n;
|
||||||
|
|
||||||
s = gettoken(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||||
if (itype != NULL) {
|
if (itype != NULL) {
|
||||||
|
@ -1312,7 +1309,8 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
|
||||||
unit *maxowner = (unit *)NULL;
|
unit *maxowner = (unit *)NULL;
|
||||||
building *maxb = (building *)NULL;
|
building *maxb = (building *)NULL;
|
||||||
building *b;
|
building *b;
|
||||||
unit *hafenowner, *u;
|
unit *u;
|
||||||
|
unit *hafenowner;
|
||||||
static int counter[MAXLUXURIES];
|
static int counter[MAXLUXURIES];
|
||||||
static int ncounter = 0;
|
static int ncounter = 0;
|
||||||
static int bt_cache;
|
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 *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, skill;
|
int i, price;
|
||||||
int use = 0;
|
int use = 0;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -1402,12 +1397,9 @@ 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, skill) != 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
item *itm;
|
item *itm;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
|
u = g_requests[j]->unit;
|
||||||
a = a_find(u->attribs, &at_luxuries);
|
a = a_find(u->attribs, &at_luxuries);
|
||||||
if (!a) {
|
if (!a) {
|
||||||
a = a_add(&u->attribs, a_new(&at_luxuries));
|
a = a_add(&u->attribs, a_new(&at_luxuries));
|
||||||
|
@ -1455,9 +1447,8 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
|
||||||
counter[i] = 0;
|
counter[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (use > 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;
|
bool unlimited = true;
|
||||||
const item_type *itype;
|
const item_type *itype;
|
||||||
const luxury_type *ltype;
|
const luxury_type *ltype;
|
||||||
int n, i;
|
int n, k;
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
const char *s;
|
const char *s;
|
||||||
keyword_t kwd;
|
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. */
|
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt verkaufen. */
|
||||||
|
|
||||||
i = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
||||||
if (n > i) n = i;
|
k = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
||||||
|
if (n > k) n = k;
|
||||||
|
|
||||||
if (!n) {
|
if (!n) {
|
||||||
cmistake(u, ord, 54, MSG_COMMERCE);
|
cmistake(u, ord, 54, MSG_COMMERCE);
|
||||||
|
@ -1570,8 +1562,9 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
attrib *a;
|
||||||
econ_request *o;
|
econ_request *o;
|
||||||
int k, available;
|
int available;
|
||||||
|
|
||||||
if (!r->land || !r_demand(r, ltype)) {
|
if (!r->land || !r_demand(r, ltype)) {
|
||||||
cmistake(u, ord, 263, MSG_COMMERCE);
|
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
|
* produktion, wo fuer jedes produkt einzeln eine obere limite
|
||||||
* existiert, so dass man arrays von orders machen kann. */
|
* existiert, so dass man arrays von orders machen kann. */
|
||||||
|
|
||||||
/* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */
|
/* hat der Haendler bereits gehandelt, muss die Menge der bereits
|
||||||
k = u->number * 10 * effskill(u, SK_TRADE, NULL);
|
* 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 > k) n = k;
|
||||||
assert(n >= 0);
|
assert(n >= 0);
|
||||||
/* die Menge der verkauften Gueter merken */
|
/* die Menge der verkauften Gueter merken */
|
||||||
|
a->data.i += n;
|
||||||
o = (econ_request *)calloc(1, sizeof(econ_request));
|
o = (econ_request *)calloc(1, sizeof(econ_request));
|
||||||
if (!o) abort();
|
if (!o) abort();
|
||||||
o->unit = u;
|
o->unit = u;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
#include <attributes/movement.h>
|
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include <kernel/attrib.h>
|
#include <kernel/attrib.h>
|
||||||
|
@ -319,7 +318,7 @@ static void transfer_units(ship *s1, ship *s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ship_cursed(const ship *sh) {
|
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)
|
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", ""));
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (u->ship && u->ship->number == 1) {
|
if (u->ship) {
|
||||||
attrib *a = a_find(u->ship->attribs, &at_speedup);
|
attrib *a = a_find(u->ship->attribs, &at_speedup);
|
||||||
if (a == NULL) {
|
if (a == NULL) {
|
||||||
a = a_add(&u->ship->attribs, a_new(&at_speedup));
|
a = a_add(&u->ship->attribs, a_new(&at_speedup));
|
||||||
|
|
Loading…
Reference in New Issue