2010-08-08 10:06:34 +02:00
|
|
|
|
/*
|
|
|
|
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
|
#include <kernel/config.h>
|
2012-06-03 22:39:42 +02:00
|
|
|
|
#include <kernel/types.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "economy.h"
|
|
|
|
|
|
|
|
|
|
/* gamecode includes */
|
|
|
|
|
#include "archetype.h"
|
|
|
|
|
#include "give.h"
|
|
|
|
|
#include "laws.h"
|
|
|
|
|
#include "randenc.h"
|
|
|
|
|
#include "spy.h"
|
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include <kernel/alchemy.h>
|
|
|
|
|
#include <kernel/building.h>
|
|
|
|
|
#include <kernel/calendar.h>
|
2012-06-03 22:39:42 +02:00
|
|
|
|
#include <kernel/curse.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/equipment.h>
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/magic.h>
|
|
|
|
|
#include <kernel/message.h>
|
|
|
|
|
#include <kernel/move.h>
|
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
|
#include <kernel/resources.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/skill.h>
|
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
|
#include <kernel/terrainid.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/base36.h>
|
2012-05-29 21:17:25 +02:00
|
|
|
|
#include <util/bsdstring.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/event.h>
|
|
|
|
|
#include <util/goodies.h>
|
|
|
|
|
#include <util/lists.h>
|
|
|
|
|
#include <util/language.h>
|
|
|
|
|
#include <util/lists.h>
|
|
|
|
|
#include <util/message.h>
|
|
|
|
|
#include <util/parser.h>
|
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
|
|
|
|
|
#include <attributes/reduceproduction.h>
|
|
|
|
|
#include <attributes/racename.h>
|
|
|
|
|
#include <attributes/orcification.h>
|
|
|
|
|
|
|
|
|
|
#include <items/seed.h>
|
|
|
|
|
|
|
|
|
|
/* libs includes */
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdio.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
|
#include <stdlib.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
|
|
typedef struct request {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct request *next;
|
|
|
|
|
struct unit *unit;
|
|
|
|
|
struct order *ord;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int qty;
|
|
|
|
|
int no;
|
|
|
|
|
union {
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool goblin; /* stealing */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const struct luxury_type *ltype; /* trading */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} type;
|
|
|
|
|
} request;
|
|
|
|
|
|
|
|
|
|
static int working;
|
|
|
|
|
|
|
|
|
|
static request entertainers[1024];
|
|
|
|
|
static request *nextentertainer;
|
|
|
|
|
static int entertaining;
|
|
|
|
|
|
|
|
|
|
static int norders;
|
|
|
|
|
static request *oa;
|
|
|
|
|
|
|
|
|
|
#define RECRUIT_MERGE 1
|
|
|
|
|
#define RECRUIT_CLASSIC 2
|
|
|
|
|
#define RECRUIT_ARCHETYPES 4
|
|
|
|
|
static int rules_recruit = -1;
|
|
|
|
|
|
|
|
|
|
static void recruit_init(void)
|
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rules_recruit < 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rules_recruit = 0;
|
|
|
|
|
if (get_param_int(global.parameters, "recruit.allow_merge", 1)) {
|
|
|
|
|
rules_recruit |= RECRUIT_MERGE;
|
|
|
|
|
}
|
|
|
|
|
if (get_param_int(global.parameters, "recruit.classic", 1)) {
|
|
|
|
|
rules_recruit |= RECRUIT_CLASSIC;
|
|
|
|
|
}
|
|
|
|
|
if (get_param_int(global.parameters, "recruit.archetype", 0)) {
|
|
|
|
|
rules_recruit |= RECRUIT_ARCHETYPES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int income(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2013-05-02 03:42:20 +02:00
|
|
|
|
switch (old_race(u_race(u))) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case RC_FIREDRAGON:
|
|
|
|
|
return 150 * u->number;
|
|
|
|
|
case RC_DRAGON:
|
|
|
|
|
return 1000 * u->number;
|
|
|
|
|
case RC_WYRM:
|
|
|
|
|
return 5000 * u->number;
|
|
|
|
|
default:
|
|
|
|
|
return 20 * u->number;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void scramble(void *data, int n, size_t width)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int j;
|
|
|
|
|
char temp[64];
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(width <= sizeof(temp));
|
|
|
|
|
for (j = 0; j != n; ++j) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int k = rng_int() % n;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (k == j)
|
|
|
|
|
continue;
|
|
|
|
|
memcpy(temp, (char *)data + j * width, width);
|
|
|
|
|
memcpy((char *)data + j * width, (char *)data + k * width, width);
|
|
|
|
|
memcpy((char *)data + k * width, temp, width);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandorders(region * r, request * requests)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
request *o;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* Alle Units ohne request haben ein -1, alle units mit orders haben ein
|
|
|
|
|
* 0 hier stehen */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (u = r->units; u; u = u->next)
|
|
|
|
|
u->n = -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
norders = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (o = requests; o; o = o->next) {
|
|
|
|
|
if (o->qty > 0) {
|
|
|
|
|
norders += o->qty;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (norders > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int i = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
oa = (request *) calloc(norders, sizeof(request));
|
|
|
|
|
for (o = requests; o; o = o->next) {
|
|
|
|
|
if (o->qty > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int j;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (j = o->qty; j; j--) {
|
|
|
|
|
oa[i] = *o;
|
|
|
|
|
oa[i].unit->n = 0;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
scramble(oa, norders, sizeof(request));
|
|
|
|
|
} else {
|
|
|
|
|
oa = NULL;
|
|
|
|
|
}
|
|
|
|
|
while (requests) {
|
|
|
|
|
request *o = requests->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
free_order(requests->ord);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
free(requests);
|
|
|
|
|
requests = o;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void change_level(unit * u, skill_t sk, int bylevel)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
skill *sv = get_skill(u, sk);
|
|
|
|
|
assert(bylevel > 0);
|
|
|
|
|
if (sv == 0)
|
|
|
|
|
sv = add_skill(u, sk);
|
|
|
|
|
sk_set(sv, sv->level + bylevel);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct recruitment {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct recruitment *next;
|
|
|
|
|
faction *f;
|
|
|
|
|
request *requests;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int total, assigned;
|
|
|
|
|
} recruitment;
|
|
|
|
|
|
2012-07-26 10:35:09 +02:00
|
|
|
|
/** Creates a list of recruitment structs, one for each faction. Adds every quantifyable request
|
|
|
|
|
* to the faction's struct and to total.
|
|
|
|
|
*/
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static recruitment *select_recruitment(request ** rop,
|
|
|
|
|
int (*quantify) (const struct race *, int), int *total)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
recruitment *recruits = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
while (*rop) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
recruitment *rec = recruits;
|
|
|
|
|
request *ro = *rop;
|
|
|
|
|
unit *u = ro->unit;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
const race *rc = u_race(u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int qty = quantify(rc, ro->qty);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (qty < 0) {
|
|
|
|
|
rop = &ro->next; /* skip this one */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
*rop = ro->next; /* remove this one */
|
|
|
|
|
while (rec && rec->f != u->faction)
|
|
|
|
|
rec = rec->next;
|
|
|
|
|
if (rec == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rec = malloc(sizeof(recruitment));
|
|
|
|
|
rec->f = u->faction;
|
|
|
|
|
rec->total = 0;
|
|
|
|
|
rec->assigned = 0;
|
|
|
|
|
rec->requests = NULL;
|
|
|
|
|
rec->next = recruits;
|
|
|
|
|
recruits = rec;
|
|
|
|
|
}
|
|
|
|
|
*total += qty;
|
|
|
|
|
rec->total += qty;
|
|
|
|
|
ro->next = rec->requests;
|
|
|
|
|
rec->requests = ro;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return recruits;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void add_recruits(unit * u, int number, int wanted)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
|
|
|
|
assert(number <= wanted);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (number > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *unew;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
char equipment[64];
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->number == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
set_number(u, number);
|
|
|
|
|
u->hp = number * unit_max_hp(u);
|
|
|
|
|
unew = u;
|
|
|
|
|
} else {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
unew = create_unit(r, u->faction, number, u_race(u), 0, NULL, u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 21:17:25 +02:00
|
|
|
|
strlcpy(equipment, "new_", sizeof(equipment));
|
2013-05-02 03:42:20 +02:00
|
|
|
|
strlcat(equipment, u_race(u)->_name[0], sizeof(equipment));
|
2012-05-29 21:17:25 +02:00
|
|
|
|
strlcat(equipment, "_unit", sizeof(equipment));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
equip_unit(unew, get_equipment(equipment));
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(unew)->ec_flags & ECF_REC_HORSES) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
change_level(unew, SK_RIDING, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (unew != u) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
transfermen(unew, u, unew->number);
|
|
|
|
|
remove_unit(&r->units, unew);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (number < wanted) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("recruit",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit region amount want", u, r, number, wanted));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int any_recruiters(const struct race *rc, int qty)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
return (int)(qty * 2 * rc->recruit_multi);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 10:35:09 +02:00
|
|
|
|
/*static int peasant_recruiters(const struct race *rc, int qty)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rc->ec_flags & ECF_REC_ETHEREAL)
|
|
|
|
|
return -1;
|
|
|
|
|
if (rc->ec_flags & ECF_REC_HORSES)
|
|
|
|
|
return -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return (int)(qty * 2 * rc->recruit_multi);
|
2012-07-26 10:35:09 +02:00
|
|
|
|
}*/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int horse_recruiters(const struct race *rc, int qty)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rc->ec_flags & ECF_REC_ETHEREAL)
|
|
|
|
|
return -1;
|
|
|
|
|
if (rc->ec_flags & ECF_REC_HORSES)
|
|
|
|
|
return (int)(qty * 2 * rc->recruit_multi);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int do_recruiting(recruitment * recruits, int available)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
recruitment *rec;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int recruited = 0;
|
|
|
|
|
|
2012-07-26 10:35:09 +02:00
|
|
|
|
/* try to assign recruits to factions fairly */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (available > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int n = 0;
|
|
|
|
|
int rest, mintotal = INT_MAX;
|
|
|
|
|
|
2012-07-26 10:35:09 +02:00
|
|
|
|
/* find smallest request */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (rec = recruits; rec != NULL; rec = rec->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int want = rec->total - rec->assigned;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want > 0) {
|
|
|
|
|
if (mintotal > want)
|
|
|
|
|
mintotal = want;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0)
|
|
|
|
|
break;
|
|
|
|
|
if (mintotal * n > available) {
|
|
|
|
|
mintotal = available / n;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rest = available - mintotal * n;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-07-26 10:35:09 +02:00
|
|
|
|
/* assign size of smallest request for everyone if possible; in the end roll dice to assign
|
|
|
|
|
* small rest */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (rec = recruits; rec != NULL; rec = rec->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int want = rec->total - rec->assigned;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int get = mintotal;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want > mintotal && rest < n && (rng_int() % n) < rest) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
--rest;
|
|
|
|
|
++get;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(get <= want);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
available -= get;
|
|
|
|
|
rec->assigned += get;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 10:35:09 +02:00
|
|
|
|
/* do actual recruiting */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (rec = recruits; rec != NULL; rec = rec->next) {
|
|
|
|
|
request *req;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int get = rec->assigned;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (req = rec->requests; req; req = req->next) {
|
|
|
|
|
unit *u = req->unit;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
const race *rc = u_race(u); /* race is set in recruit() */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int number, dec;
|
|
|
|
|
float multi = 2.0F * rc->recruit_multi;
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
number = _min(req->qty, (int)(get / multi));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rc->recruitcost) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
int afford = get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
number * rc->recruitcost) / rc->recruitcost;
|
2014-03-16 05:03:17 +01:00
|
|
|
|
number = _min(number, afford);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->number + number > UNIT_MAXSIZE) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, req->ord, "error_unit_size",
|
|
|
|
|
"maxsize", UNIT_MAXSIZE));
|
|
|
|
|
number = UNIT_MAXSIZE - u->number;
|
|
|
|
|
assert(number >= 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-07-26 10:35:09 +02:00
|
|
|
|
if (rc->recruitcost) {
|
|
|
|
|
use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
|
|
|
|
|
rc->recruitcost * number);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_recruits(u, number, req->qty);
|
|
|
|
|
dec = (int)(number * multi);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruited += dec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get -= dec;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return recruited;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void feedback_give_not_allowed(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_give_forbidden",
|
|
|
|
|
""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool check_give(unit * u, unit * u2, const item_type * itype,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int mask)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
if (u2) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->faction != u2->faction) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int rule = rule_give();
|
|
|
|
|
if (itype) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(mask == 0);
|
|
|
|
|
if (itype->rtype->ltype)
|
|
|
|
|
mask |= GIVE_LUXURIES;
|
|
|
|
|
else if (fval(itype, ITF_HERB))
|
|
|
|
|
mask |= GIVE_HERBS;
|
|
|
|
|
else
|
|
|
|
|
mask |= GIVE_GOODS;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return (rule & mask) != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
int rule = rule_give();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return (rule & GIVE_PEASANTS) != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void free_recruitments(recruitment * recruits)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
while (recruits) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
recruitment *rec = recruits;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruits = rec->next;
|
|
|
|
|
while (rec->requests) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
request *req = rec->requests;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rec->requests = req->next;
|
|
|
|
|
free(req);
|
|
|
|
|
}
|
|
|
|
|
free(rec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Rekrutierung */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandrecruit(region * r, request * recruitorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
recruitment *recruits = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
int orc_total = 0;
|
|
|
|
|
|
|
|
|
|
/* centaurs: */
|
|
|
|
|
recruits = select_recruitment(&recruitorders, horse_recruiters, &orc_total);
|
|
|
|
|
if (recruits) {
|
|
|
|
|
int recruited, horses = rhorses(r) * 2;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (orc_total < horses)
|
|
|
|
|
horses = orc_total;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruited = do_recruiting(recruits, horses);
|
|
|
|
|
rsethorses(r, (horses - recruited) / 2);
|
|
|
|
|
free_recruitments(recruits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* peasant limited: */
|
2012-07-26 10:35:09 +02:00
|
|
|
|
recruits = select_recruitment(&recruitorders, any_recruiters, &orc_total);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (recruits) {
|
|
|
|
|
int orc_recruited, orc_peasants = rpeasants(r) * 2;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int orc_frac = orc_peasants / RECRUITFRACTION; /* anzahl orks. 2 ork = 1 bauer */
|
|
|
|
|
if (orc_total < orc_frac)
|
|
|
|
|
orc_frac = orc_total;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
orc_recruited = do_recruiting(recruits, orc_frac);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(orc_recruited <= orc_frac);
|
|
|
|
|
rsetpeasants(r, (orc_peasants - orc_recruited) / 2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
free_recruitments(recruits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* no limit: */
|
|
|
|
|
recruits = select_recruitment(&recruitorders, any_recruiters, &orc_total);
|
|
|
|
|
if (recruits) {
|
2012-07-26 10:35:09 +02:00
|
|
|
|
int recruited, peasants = rpeasants(r) * 2;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruited = do_recruiting(recruits, INT_MAX);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (recruited > 0) {
|
2012-07-26 10:35:09 +02:00
|
|
|
|
rsetpeasants(r, (peasants - recruited) / 2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
free_recruitments(recruits);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(recruitorders == NULL);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int recruit_cost(const faction * f, const race * rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (is_monsters(f) || f->race == rc) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return rc->recruitcost;
|
|
|
|
|
} else if (valid_race(f, rc)) {
|
|
|
|
|
return rc->recruitcost;
|
|
|
|
|
/* return get_param_int(f->race->parameters, "other_cost", -1); */
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void recruit(unit * u, struct order *ord, request ** recruitorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
|
|
|
|
plane *pl;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
request *o;
|
|
|
|
|
int recruitcost = -1;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const faction *f = u->faction;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
const struct race *rc = u_race(u);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *str;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
n = getuint();
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->number == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
str = getstrtoken();
|
|
|
|
|
if (str && str[0]) {
|
|
|
|
|
/* Monster d<>rfen REKRUTIERE 15 dracoid machen
|
|
|
|
|
* also: secondary race */
|
|
|
|
|
rc = findrace(str, f->locale);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rc != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruitcost = recruit_cost(f, rc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (recruitcost < 0) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
rc = u_race(u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruitcost = recruit_cost(f, rc);
|
2012-04-16 06:56:44 +02:00
|
|
|
|
if (recruitcost < 0) {
|
|
|
|
|
recruitcost = INT_MAX;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-04-16 06:56:44 +02:00
|
|
|
|
assert(rc);
|
2013-05-02 03:42:20 +02:00
|
|
|
|
u_setrace(u, rc);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
#if GUARD_DISABLES_RECRUIT
|
|
|
|
|
/* this is a very special case because the recruiting unit may be empty
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* at this point and we have to look at the creating unit instead. This
|
|
|
|
|
* is done in cansee, which is called indirectly by is_guarded(). */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (is_guarded(r, u, GUARD_RECRUIT)) {
|
|
|
|
|
cmistake(u, ord, 70, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (rc == new_race[RC_INSECT]) {
|
|
|
|
|
gamedate date;
|
|
|
|
|
get_gamedate(turn, &date);
|
|
|
|
|
if (date.season == 0 && r->terrain != newterrain(T_DESERT)) {
|
|
|
|
|
#ifdef INSECT_POTION
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool usepotion = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u2;
|
|
|
|
|
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next)
|
|
|
|
|
if (fval(u2, UFL_WARMTH)) {
|
|
|
|
|
usepotion = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!usepotion)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#endif
|
2011-03-07 08:02:35 +01:00
|
|
|
|
{
|
|
|
|
|
cmistake(u, ord, 98, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
/* in Gletschern, Eisbergen gar nicht rekrutieren */
|
|
|
|
|
if (r_insectstalled(r)) {
|
|
|
|
|
cmistake(u, ord, 97, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (is_cursed(r->attribs, C_RIOT, 0)) {
|
|
|
|
|
/* Die Region befindet sich in Aufruhr */
|
|
|
|
|
cmistake(u, ord, 237, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(rc->ec_flags & ECF_REC_HORSES) && fval(r, RF_ORCIFIED)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rc != new_race[RC_ORC]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 238, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (recruitcost) {
|
|
|
|
|
pl = getplane(r);
|
|
|
|
|
if (pl && fval(pl, PFL_NORECRUITS)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_pflnorecruit", ""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
|
|
|
|
|
recruitcost) < recruitcost) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 142, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!playerrace(rc) || idle(u->faction)) {
|
|
|
|
|
cmistake(u, ord, 139, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (has_skill(u, SK_MAGIC)) {
|
|
|
|
|
/* error158;de;{unit} in {region}: '{command}' - Magier arbeiten
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* grunds<EFBFBD>tzlich nur alleine! */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 158, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (has_skill(u, SK_ALCHEMY)
|
|
|
|
|
&& count_skill(u->faction, SK_ALCHEMY) + n >
|
2011-03-07 08:02:35 +01:00
|
|
|
|
skill_limit(u->faction, SK_ALCHEMY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 156, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (recruitcost > 0) {
|
|
|
|
|
int pooled =
|
|
|
|
|
get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, recruitcost * n);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, pooled / recruitcost);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->wants = n;
|
|
|
|
|
|
|
|
|
|
if (!n) {
|
|
|
|
|
cmistake(u, ord, 142, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
o = (request *) calloc(1, sizeof(request));
|
|
|
|
|
o->qty = n;
|
|
|
|
|
o->unit = u;
|
|
|
|
|
o->ord = copy_order(ord);
|
|
|
|
|
addlist(recruitorders, o);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void friendly_takeover(region * r, faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int morale = region_get_morale(r);
|
|
|
|
|
region_set_owner(r, f, turn);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (morale > 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
morale = _max(0, morale - MORALE_TRANSFER);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
region_set_morale(r, morale, turn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-27 17:38:17 +02:00
|
|
|
|
void give_control(unit * u, unit * u2)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
{
|
2012-05-27 17:38:17 +02:00
|
|
|
|
if (u->building) {
|
|
|
|
|
if (u->faction != u2->faction && rule_region_owners()) {
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
faction *f = region_get_owner(r);
|
|
|
|
|
|
|
|
|
|
assert(u->building==u2->building);
|
|
|
|
|
if (f == u->faction) {
|
|
|
|
|
building *b = largestbuilding(r, &cmp_current_owner, false);
|
|
|
|
|
if (b == u->building) {
|
|
|
|
|
friendly_takeover(r, u2->faction);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-26 19:43:05 +02:00
|
|
|
|
building_set_owner(u2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-05-17 19:31:58 +02:00
|
|
|
|
if (u->ship) {
|
2012-05-26 19:43:05 +02:00
|
|
|
|
assert(u->ship==u2->ship);
|
|
|
|
|
ship_set_owner(u2);
|
2012-05-17 19:31:58 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int give_control_cmd(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u2;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
param_t p;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
u2 = getunit(r, u->faction);
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
p = findparam(s, u->faction->locale);
|
|
|
|
|
|
|
|
|
|
/* first, do all the ones that do not require HELP_GIVE or CONTACT */
|
|
|
|
|
if (p == P_CONTROL) {
|
2012-05-19 07:34:04 +02:00
|
|
|
|
message *msg = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!u2 || u2->number == 0) {
|
2012-05-19 07:34:04 +02:00
|
|
|
|
msg = msg_feedback(u, ord, "feedback_unit_not_found", "");
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (!u->building && !u->ship) {
|
2012-05-19 07:34:04 +02:00
|
|
|
|
msg = cmistake(u, ord, 140, MSG_EVENT);
|
|
|
|
|
} else if (u->building) {
|
|
|
|
|
if (u!=building_owner(u->building)) {
|
|
|
|
|
msg = cmistake(u, ord, 49, MSG_EVENT);
|
|
|
|
|
} else if (u2->building != u->building) {
|
|
|
|
|
msg = cmistake(u, ord, 33, MSG_EVENT);
|
|
|
|
|
}
|
|
|
|
|
} else if (u->ship) {
|
|
|
|
|
if (u!=ship_owner(u->ship)) {
|
|
|
|
|
msg = cmistake(u, ord, 49, MSG_EVENT);
|
|
|
|
|
} else if (u2->ship != u->ship) {
|
|
|
|
|
msg = cmistake(u, ord, 32, MSG_EVENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!msg) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
give_control(u, u2);
|
|
|
|
|
msg = msg_message("givecommand", "unit recipient", u, u2);
|
|
|
|
|
add_message(&u->faction->msgs, msg);
|
|
|
|
|
if (u->faction != u2->faction) {
|
|
|
|
|
add_message(&u2->faction->msgs, msg);
|
|
|
|
|
}
|
|
|
|
|
msg_release(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void give_cmd(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u2;
|
|
|
|
|
const char *s;
|
2012-05-20 07:47:52 +02:00
|
|
|
|
int n;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
param_t p;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
plane *pl;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
u2 = getunit(r, u->faction);
|
|
|
|
|
s = getstrtoken();
|
2012-05-20 07:47:52 +02:00
|
|
|
|
n = atoip(s);
|
|
|
|
|
p = (n>0) ? NOPARAM : findparam(s, u->faction->locale);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* first, do all the ones that do not require HELP_GIVE or CONTACT */
|
|
|
|
|
if (p == P_CONTROL) {
|
|
|
|
|
/* handled in give_control_cmd */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!u2 && !getunitpeasants) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
|
|
|
|
""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!check_give(u, u2, NULL, GIVE_ALLITEMS)) {
|
|
|
|
|
feedback_give_not_allowed(u, ord);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Damit Tarner nicht durch die Fehlermeldung enttarnt werden k<>nnen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u2 && !alliedunit(u2, u->faction, HELP_GIVE)
|
|
|
|
|
&& !cansee(u->faction, r, u2, 0) && !ucontact(u2, u)
|
|
|
|
|
&& !fval(u2, UFL_TAKEALL)) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
|
|
|
|
""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (u == u2) {
|
|
|
|
|
cmistake(u, ord, 8, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* UFL_TAKEALL ist ein grober Hack. Generalisierung tut not, ist aber nicht
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* wirklich einfach. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pl = rplane(r);
|
|
|
|
|
if (pl && fval(pl, PFL_NOGIVE) && (!u2 || !fval(u2, UFL_TAKEALL))) {
|
|
|
|
|
cmistake(u, ord, 268, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u2 && u_race(u2) == new_race[RC_SPELL]) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
|
|
|
|
""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) {
|
|
|
|
|
cmistake(u, ord, 40, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (p == P_HERBS) {
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool given = false;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_nogive", "race", u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!check_give(u, u2, NULL, GIVE_HERBS)) {
|
|
|
|
|
feedback_give_not_allowed(u, ord);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u2 && !(u_race(u2)->ec_flags & GETITEM)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!u2) {
|
|
|
|
|
if (!getunitpeasants) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
|
"feedback_unit_not_found", ""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (u->items) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item **itmp = &u->items;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*itmp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item *itm = *itmp;
|
|
|
|
|
const item_type *itype = itm->type;
|
|
|
|
|
if (fval(itype, ITF_HERB) && itm->number > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* give_item <20>ndert im fall,das man alles <20>bergibt, die
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* item-liste der unit, darum continue vor pointerumsetzten */
|
|
|
|
|
if (give_item(itm->number, itm->type, u, u2, ord) == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
given = true;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (*itmp != itm)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
itmp = &itm->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!given)
|
|
|
|
|
cmistake(u, ord, 38, MSG_COMMERCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (p == P_ZAUBER) {
|
|
|
|
|
cmistake(u, ord, 7, MSG_COMMERCE);
|
|
|
|
|
/* geht nimmer */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
else if (p == P_UNIT) { /* Einheiten uebergeben */
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEUNIT)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 167, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
give_unit(u, u2, ord);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
else if (p == P_ANY) {
|
2012-05-20 06:54:59 +02:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (!check_give(u, u2, NULL, GIVE_ALLITEMS)) {
|
|
|
|
|
feedback_give_not_allowed(u, ord);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-05-20 06:54:59 +02:00
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (*s == 0) { /* GIVE ALL items that you have */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* do these checks once, not for each item we have: */
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_nogive", "race", u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u2 && !(u_race(u2)->ec_flags & GETITEM)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* f<>r alle items einmal pr<70>fen, ob wir mehr als von diesem Typ
|
|
|
|
|
* reserviert ist besitzen und diesen Teil dann <EFBFBD>bergeben */
|
|
|
|
|
if (u->items) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item **itmp = &u->items;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*itmp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item *itm = *itmp;
|
|
|
|
|
const item_type *itype = itm->type;
|
|
|
|
|
if (itm->number > 0
|
|
|
|
|
&& itm->number - get_reservation(u, itype->rtype) > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n = itm->number - get_reservation(u, itype->rtype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (give_item(n, itype, u, u2, ord) == 0) {
|
|
|
|
|
if (*itmp != itm)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
itmp = &itm->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else {
|
2012-05-20 06:54:59 +02:00
|
|
|
|
if (isparam(s, u->faction->locale, P_PERSON)) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEPERSON)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));
|
2012-05-20 07:47:52 +02:00
|
|
|
|
} else {
|
|
|
|
|
n = u->number;
|
|
|
|
|
give_men(n, u, u2, ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2013-05-02 03:42:20 +02:00
|
|
|
|
} else if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_nogive", "race", u_race(u)));
|
|
|
|
|
} else if (u2 && !(u_race(u2)->ec_flags & GETITEM)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
|
2012-05-20 07:47:52 +02:00
|
|
|
|
} else {
|
|
|
|
|
itype = finditemtype(s, u->faction->locale);
|
|
|
|
|
if (itype != NULL) {
|
|
|
|
|
item *i = *i_find(&u->items, itype);
|
|
|
|
|
if (i != NULL) {
|
|
|
|
|
if (check_give(u, u2, itype, 0)) {
|
|
|
|
|
n = i->number - get_reservation(u, itype->rtype);
|
|
|
|
|
give_item(n, itype, u, u2, ord);
|
|
|
|
|
} else {
|
|
|
|
|
feedback_give_not_allowed(u, ord);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-20 07:47:52 +02:00
|
|
|
|
return;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (p == P_EACH) {
|
|
|
|
|
if (u2 == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, ord, "peasants_give_invalid", ""));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
s = getstrtoken(); /* skip one ahead to get the amount. */
|
2012-05-20 07:47:52 +02:00
|
|
|
|
n = atoip(s); /* n: Anzahl */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n *= u2->number;
|
|
|
|
|
}
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if (s == NULL) {
|
|
|
|
|
cmistake(u, ord, 113, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-20 07:47:52 +02:00
|
|
|
|
if (isparam(s, u->faction->locale, P_PERSON)) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEPERSON)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
give_men(n, u, u2, ord);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u2 != NULL) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_nogive", "race", u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u2)->ec_flags & GETITEM)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itype = finditemtype(s, u->faction->locale);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itype != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (check_give(u, u2, itype, 0)) {
|
|
|
|
|
give_item(n, itype, u, u2, ord);
|
|
|
|
|
} else {
|
|
|
|
|
feedback_give_not_allowed(u, ord);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
cmistake(u, ord, 123, MSG_COMMERCE);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int forget_cmd(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
skill_t sk;
|
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
if (is_cursed(u->attribs, C_SLAVE, 0)) {
|
|
|
|
|
/* charmed units shouldn't be losing their skills */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if ((sk = findskill(s, u->faction->locale)) != NOSKILL) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
set_level(u, sk, 0);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void add_spende(faction * f1, faction * f2, int amount, region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
donation *sp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
sp = r->donations;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (sp) {
|
|
|
|
|
if (sp->f1 == f1 && sp->f2 == f2) {
|
|
|
|
|
sp->amount += amount;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sp = sp->next;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
sp = calloc(1, sizeof(donation));
|
|
|
|
|
sp->f1 = f1;
|
|
|
|
|
sp->f2 = f2;
|
|
|
|
|
sp->amount = amount;
|
|
|
|
|
sp->next = r->donations;
|
|
|
|
|
r->donations = sp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool maintain(building * b, bool first)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* first==false -> take money from wherever you can */
|
|
|
|
|
{
|
|
|
|
|
int c;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = b->region;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool paid = true, work = first;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL
|
|
|
|
|
|| is_cursed(b->attribs, C_NOCOST, 0)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
fset(b, BLD_MAINTAINED);
|
|
|
|
|
fset(b, BLD_WORKING);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (fval(b, BLD_DONTPAY)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
u = building_owner(b);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
for (c = 0; b->type->maintenance[c].number; ++c) {
|
|
|
|
|
const maintenance *m = b->type->maintenance + c;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int need = m->number;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (fval(m, MTF_VARIABLE))
|
|
|
|
|
need = need * b->size;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (u) {
|
|
|
|
|
/* first ist im ersten versuch true, im zweiten aber false! Das
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* bedeutet, das in der Runde in die Region geschafften Resourcen
|
|
|
|
|
* nicht genutzt werden k<EFBFBD>nnen, weil die reserviert sind! */
|
|
|
|
|
if (!first)
|
|
|
|
|
need -= get_pooled(u, m->rtype, GET_ALL, need);
|
|
|
|
|
else
|
|
|
|
|
need -= get_pooled(u, m->rtype, GET_DEFAULT, need);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!first && need > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *ua;
|
|
|
|
|
for (ua = r->units; ua; ua = ua->next)
|
|
|
|
|
freset(ua->faction, FFL_SELECT);
|
|
|
|
|
fset(u->faction, FFL_SELECT); /* hat schon */
|
|
|
|
|
for (ua = r->units; ua; ua = ua->next) {
|
|
|
|
|
if (!fval(ua->faction, FFL_SELECT) && (ua->faction == u->faction
|
|
|
|
|
|| alliedunit(ua, u->faction, HELP_MONEY))) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
need -= get_pooled(ua, m->rtype, GET_ALL, need);
|
|
|
|
|
fset(ua->faction, FFL_SELECT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (need <= 0)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (need > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!fval(m, MTF_VITAL))
|
|
|
|
|
work = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
else {
|
|
|
|
|
paid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (paid && c > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* TODO: wieviel von was wurde bezahlt */
|
|
|
|
|
if (first) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("maintenance", "unit building", u,
|
|
|
|
|
b));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("maintenance_late", "building", b));
|
|
|
|
|
}
|
|
|
|
|
fset(b, BLD_MAINTAINED);
|
|
|
|
|
if (work) {
|
|
|
|
|
fset(b, BLD_WORKING);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (c = 0; b->type->maintenance[c].number; ++c) {
|
|
|
|
|
const maintenance *m = b->type->maintenance + c;
|
|
|
|
|
int cost = m->number;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!fval(m, MTF_VITAL) && !work)
|
|
|
|
|
continue;
|
|
|
|
|
if (fval(m, MTF_VARIABLE))
|
|
|
|
|
cost = cost * b->size;
|
|
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
|
cost -= use_pooled(u, m->rtype, GET_ALL, cost);
|
|
|
|
|
else
|
|
|
|
|
cost -=
|
|
|
|
|
use_pooled(u, m->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
|
|
|
|
|
cost);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!first && cost > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *ua;
|
|
|
|
|
for (ua = r->units; ua; ua = ua->next)
|
|
|
|
|
freset(ua->faction, FFL_SELECT);
|
|
|
|
|
fset(u->faction, FFL_SELECT); /* hat schon */
|
|
|
|
|
for (ua = r->units; ua; ua = ua->next) {
|
|
|
|
|
if (!fval(ua->faction, FFL_SELECT)
|
|
|
|
|
&& alliedunit(ua, u->faction, HELP_MONEY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int give = use_pooled(ua, m->rtype, GET_ALL, cost);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!give)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cost -= give;
|
|
|
|
|
fset(ua->faction, FFL_SELECT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (m->rtype == r_silver)
|
|
|
|
|
add_spende(ua->faction, u->faction, give, r);
|
|
|
|
|
if (cost <= 0)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(cost == 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_message("maintenancefail", "unit building", u, b));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
void maintain_buildings(region * r, bool crash)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
building **bp = &r->buildings;
|
|
|
|
|
while (*bp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
building *b = *bp;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool maintained = maintain(b, !crash);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* the second time, send a message */
|
|
|
|
|
if (crash) {
|
|
|
|
|
if (!fval(b, BLD_WORKING)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = building_owner(b);
|
|
|
|
|
const char *msgtype =
|
|
|
|
|
maintained ? "maintenance_nowork" : "maintenance_none";
|
|
|
|
|
struct message *msg = msg_message(msgtype, "building", b);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (u) {
|
|
|
|
|
add_message(&u->faction->msgs, msg);
|
|
|
|
|
r_addmessage(r, u->faction, msg);
|
|
|
|
|
} else {
|
|
|
|
|
add_message(&r->msgs, msg);
|
|
|
|
|
}
|
|
|
|
|
msg_release(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
bp = &b->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int recruit_archetype(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool merge = (u->number > 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int want;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
if (rules_recruit < 0)
|
|
|
|
|
recruit_init();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
want = getuint();
|
|
|
|
|
s = getstrtoken();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want > 0 && s && s[0]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int n = want;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const archetype *arch = find_archetype(s, u->faction->locale);
|
|
|
|
|
attrib *a = NULL;
|
|
|
|
|
|
|
|
|
|
if ((rules_recruit & RECRUIT_MERGE) == 0 && merge) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_must_be_new", ""));
|
|
|
|
|
/* TODO: error message */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (arch == NULL) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unknown_archetype",
|
|
|
|
|
"name", s));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* TODO: error message */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (arch->rules) {
|
|
|
|
|
/* Simple allow/deny style restrictions for archetypes (let only humans
|
|
|
|
|
* recruit gamedesigners, etc). These need to be more powerful to be
|
|
|
|
|
* useful, and the current way they are implemented is not, but the
|
|
|
|
|
* general idea strikes me as good. Also, feedback should be configurable
|
|
|
|
|
* for each failed rule.
|
|
|
|
|
*/
|
|
|
|
|
int k;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (k = 0; arch->rules[k].property; ++k) {
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool match = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (arch->rules[k].value[0] == '*')
|
|
|
|
|
match = true;
|
|
|
|
|
else if (strcmp(arch->rules[k].property, "race") == 0) {
|
|
|
|
|
const race *rc = rc_find(arch->rules[k].value);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
assert(rc);
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (rc == u_race(u))
|
2011-03-07 08:02:35 +01:00
|
|
|
|
match = true;
|
|
|
|
|
} else if (strcmp(arch->rules[k].property, "building") == 0) {
|
|
|
|
|
const building_type *btype = bt_find(arch->rules[k].value);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
assert(btype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->building && u->building->type == btype)
|
|
|
|
|
match = true;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (match) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (arch->rules[k].allow)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
else {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "recruit_rule_fail",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"property value", arch->rules[k].property,
|
|
|
|
|
arch->rules[k].value));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* TODO: error message */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (arch->btype) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->building == NULL || u->building->type != arch->btype) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
|
"unit_must_be_in_building", "type", arch->btype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* TODO: error message */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (arch->size) {
|
|
|
|
|
int maxsize = u->building->size;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->building->attribs, &at_recruit);
|
|
|
|
|
if (a != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
maxsize -= a->data.i;
|
|
|
|
|
}
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(maxsize / arch->size, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n <= 0) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
|
"recruit_capacity_exhausted", "building", u->building));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* TODO: error message */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = build(u, arch->ctype, 0, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n > 0) {
|
|
|
|
|
unit *u2;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (merge) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
u2 = create_unit(u->region, u->faction, 0, u_race(u), 0, 0, u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
|
|
|
|
u2 = u;
|
|
|
|
|
}
|
|
|
|
|
if (arch->exec) {
|
|
|
|
|
n = arch->exec(u2, arch, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
set_number(u2, n);
|
|
|
|
|
equip_unit(u2, arch->equip);
|
|
|
|
|
u2->hp = n * unit_max_hp(u2);
|
|
|
|
|
if (arch->size) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (a == NULL)
|
|
|
|
|
a = a_add(&u->building->attribs, a_new(&at_recruit));
|
|
|
|
|
a->data.i += n * arch->size;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("recruit_archetype",
|
|
|
|
|
"unit amount archetype", u, n, arch->name[n == 1]));
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u != u2 && u_race(u) == u_race(u2)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
transfermen(u2, u, u2->number);
|
|
|
|
|
}
|
|
|
|
|
return n;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else
|
|
|
|
|
switch (n) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case ENOMATERIALS:
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype,
|
|
|
|
|
want));
|
|
|
|
|
break;
|
|
|
|
|
case ELOWSKILL:
|
|
|
|
|
case ENEEDSKILL:
|
|
|
|
|
/* no skill, or not enough skill points to build */
|
|
|
|
|
cmistake(u, ord, 50, MSG_PRODUCE);
|
|
|
|
|
break;
|
|
|
|
|
case EBUILDINGREQ:
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, u->thisorder, "building_needed", "building",
|
|
|
|
|
arch->ctype->btype->_name));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"unhandled return value from build() in recruit_archetype");
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int recruit_archetypes(void)
|
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rules_recruit < 0)
|
|
|
|
|
recruit_init();
|
|
|
|
|
return (rules_recruit & RECRUIT_ARCHETYPES) != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void economics(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
request *recruitorders = NULL;
|
|
|
|
|
|
|
|
|
|
/* Geben vor Selbstmord (doquit)! Hier alle unmittelbaren Befehle.
|
|
|
|
|
* Rekrutieren vor allen Einnahmequellen. Bewachen JA vor Steuern
|
|
|
|
|
* eintreiben. */
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool destroyed = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->number > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
keyword_t kwd = get_keyword(ord);
|
|
|
|
|
if (kwd == K_DESTROY) {
|
|
|
|
|
if (!destroyed) {
|
|
|
|
|
if (destroy_cmd(u, ord) != 0)
|
|
|
|
|
ord = NULL;
|
|
|
|
|
destroyed = true;
|
|
|
|
|
}
|
2012-07-08 20:37:19 +02:00
|
|
|
|
} else if (kwd == K_GIVE) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
give_cmd(u, ord);
|
|
|
|
|
} else if (kwd == K_FORGET) {
|
|
|
|
|
forget_cmd(u, ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (u->orders == NULL) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* RECRUIT orders */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rules_recruit < 0)
|
|
|
|
|
recruit_init();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if ((rules_recruit & RECRUIT_MERGE) || u->number == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
|
|
|
|
if (get_keyword(ord) == K_RECRUIT) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rules_recruit & RECRUIT_ARCHETYPES) {
|
|
|
|
|
if (recruit_archetype(u, ord) >= 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rules_recruit & RECRUIT_CLASSIC) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
recruit(u, ord, &recruitorders);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (recruitorders)
|
|
|
|
|
expandrecruit(r, recruitorders);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
remove_empty_units_in_region(r);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void manufacture(unit * u, const item_type * itype, int want)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
int skill;
|
|
|
|
|
int minskill = itype->construction->minskill;
|
|
|
|
|
skill_t sk = itype->construction->skill;
|
|
|
|
|
|
|
|
|
|
skill = effskill(u, sk);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
skill =
|
|
|
|
|
skillmod(itype->rtype->attribs, u, u->region, sk, skill, SMF_PRODUCTION);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (skill < 0) {
|
|
|
|
|
/* an error occured */
|
|
|
|
|
int err = -skill;
|
|
|
|
|
cmistake(u, u->thisorder, err, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
want = maxbuild(u, itype->construction);
|
|
|
|
|
}
|
|
|
|
|
n = build(u, itype->construction, 0, want);
|
|
|
|
|
switch (n) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case ENEEDSKILL:
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, u->thisorder, "skill_needed", "skill", sk));
|
|
|
|
|
return;
|
|
|
|
|
case EBUILDINGREQ:
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, u->thisorder, "building_needed", "building",
|
|
|
|
|
itype->construction->btype->_name));
|
|
|
|
|
return;
|
|
|
|
|
case ELOWSKILL:
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, u->thisorder, "manufacture_skills",
|
|
|
|
|
"skill minskill product", sk, minskill, itype->rtype, 1));
|
|
|
|
|
return;
|
|
|
|
|
case ENOMATERIALS:
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
|
|
|
|
|
itype->construction, want));
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i_change(&u->items, itype, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want == INT_MAX)
|
|
|
|
|
want = n;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("manufacture",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit region amount wanted resource", u, u->region, n, want,
|
|
|
|
|
itype->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_cannotmake",
|
|
|
|
|
""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct allocation {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct allocation *next;
|
|
|
|
|
int want, get;
|
|
|
|
|
double save;
|
|
|
|
|
unsigned int flags;
|
|
|
|
|
unit *unit;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} allocation;
|
|
|
|
|
#define new_allocation() calloc(sizeof(allocation), 1)
|
|
|
|
|
#define free_allocation(a) free(a)
|
|
|
|
|
|
|
|
|
|
typedef struct allocation_list {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct allocation_list *next;
|
|
|
|
|
allocation *data;
|
|
|
|
|
const resource_type *type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} allocation_list;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static allocation_list *allocations;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool can_guard(const unit * guard, const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (fval(guard, UFL_ISNEW))
|
|
|
|
|
return false;
|
|
|
|
|
if (guard->number <= 0 || !cansee(guard->faction, guard->region, u, 0))
|
|
|
|
|
return false;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (besieged(guard) || !(fval(u_race(guard), RCF_UNARMEDGUARD)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|| armedmen(guard, true)))
|
|
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
return !alliedunit(guard, u->faction, HELP_GUARD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
AFL_DONE = 1 << 0,
|
|
|
|
|
AFL_LOWSKILL = 1 << 1
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype = resource2item(rtype);
|
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int dm = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
allocation_list *alist;
|
|
|
|
|
allocation *al;
|
|
|
|
|
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
|
|
|
|
|
resource_limit *rdata = (resource_limit *) a->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int amount, skill;
|
|
|
|
|
|
|
|
|
|
/* momentan kann man keine ressourcen abbauen, wenn man daf<61>r
|
|
|
|
|
* Materialverbrauch hat: */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(itype != NULL && (itype->construction == NULL
|
|
|
|
|
|| itype->construction->materials == NULL));
|
|
|
|
|
assert(rdata != NULL);
|
|
|
|
|
|
|
|
|
|
if (rdata->limit != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int avail = rdata->limit(r, rtype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (avail <= 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, u->thisorder, 121, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (besieged(u)) {
|
|
|
|
|
cmistake(u, u->thisorder, 60, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rdata->modifiers) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
resource_mod *mod = rdata->modifiers;
|
|
|
|
|
for (; mod->flags != 0; ++mod) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (mod->flags & RMF_REQUIREDBUILDING) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct building *b = inside_building(u);
|
|
|
|
|
const struct building_type *btype = b ? b->type : NULL;
|
|
|
|
|
if (mod->btype && mod->btype != btype) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, u->thisorder, 104, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
if (rdata->guard != 0) {
|
|
|
|
|
unit *u2;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (is_guard(u2, rdata->guard) != 0 && can_guard(u2, u)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "region_guarded", "guard", u2));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Bergw<67>chter k<>nnen Abbau von Eisen/Laen durch Bewachen verhindern.
|
|
|
|
|
* Als magische Wesen 'sehen' Bergw<EFBFBD>chter alles und werden durch
|
|
|
|
|
* Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen).
|
|
|
|
|
*/
|
|
|
|
|
if (itype == olditemtype[I_IRON] || itype == olditemtype[I_LAEN]) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u2;
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (is_guard(u, GUARD_MINING)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
&& !fval(u2, UFL_ISNEW)
|
|
|
|
|
&& u2->number && !alliedunit(u2, u->faction, HELP_GUARD)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "region_guarded", "guard", u2));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
assert(itype->construction->skill != 0
|
|
|
|
|
|| "limited resource needs a required skill for making it");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
skill = eff_skill(u, itype->construction->skill, u->region);
|
|
|
|
|
if (skill == 0) {
|
|
|
|
|
skill_t sk = itype->construction->skill;
|
|
|
|
|
add_message(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "skill_needed", "skill", sk));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (skill < itype->construction->minskill) {
|
|
|
|
|
skill_t sk = itype->construction->skill;
|
|
|
|
|
add_message(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "manufacture_skills",
|
|
|
|
|
"skill minskill product", sk, itype->construction->minskill,
|
|
|
|
|
itype->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct building *b = inside_building(u);
|
|
|
|
|
const struct building_type *btype = b ? b->type : NULL;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rdata->modifiers) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
resource_mod *mod = rdata->modifiers;
|
|
|
|
|
for (; mod->flags != 0; ++mod) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (mod->flags & RMF_SKILL) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (mod->btype == NULL || mod->btype == btype) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (mod->race == NULL || mod->race == u_race(u)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
skill += mod->value.i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
amount = skill * u->number;
|
|
|
|
|
/* nun ist amount die Gesamtproduktion der Einheit (in punkten) */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* mit Flinkfingerring verzehnfacht sich die Produktion */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
amount +=
|
2014-03-16 05:03:17 +01:00
|
|
|
|
skill * _min(u->number, get_item(u,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
I_RING_OF_NIMBLEFINGER)) * (roqf_factor() - 1);
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Schaffenstrunk: */
|
|
|
|
|
if ((dm = get_effect(u, oldpotiontype[P_DOMORE])) != 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
dm = _min(dm, u->number);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
change_effect(u, oldpotiontype[P_DOMORE], -dm);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
amount += dm * skill; /* dm Personen produzieren doppelt */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
amount /= itype->construction->minskill;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Limitierung durch Parameter m. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want > 0 && want < amount)
|
|
|
|
|
amount = want;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
alist = allocations;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (alist && alist->type != rtype)
|
|
|
|
|
alist = alist->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!alist) {
|
|
|
|
|
alist = calloc(sizeof(struct allocation_list), 1);
|
|
|
|
|
alist->next = allocations;
|
|
|
|
|
alist->type = rtype;
|
|
|
|
|
allocations = alist;
|
|
|
|
|
}
|
|
|
|
|
al = new_allocation();
|
|
|
|
|
al->want = amount;
|
|
|
|
|
al->save = 1.0;
|
|
|
|
|
al->next = alist->data;
|
|
|
|
|
al->unit = u;
|
|
|
|
|
alist->data = al;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rdata->modifiers) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct building *b = inside_building(u);
|
|
|
|
|
const struct building_type *btype = b ? b->type : NULL;
|
|
|
|
|
|
|
|
|
|
resource_mod *mod = rdata->modifiers;
|
|
|
|
|
for (; mod->flags != 0; ++mod) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (mod->flags & RMF_SAVEMATERIAL) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (mod->btype == NULL || mod->btype == btype) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (mod->race == NULL || mod->race == u_race(u)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
al->save *= mod->value.f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int required(int want, double save)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int norders = (int)(want * save);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (norders < want * save)
|
|
|
|
|
++norders;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return norders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype = resource2item(rtype);
|
|
|
|
|
rawmaterial *rm = rm_get(r, rtype);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int need;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool first = true;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rm != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
do {
|
|
|
|
|
int avail = rm->amount;
|
|
|
|
|
int norders = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
allocation *al;
|
|
|
|
|
|
|
|
|
|
if (avail <= 0) {
|
|
|
|
|
for (al = alist; al; al = al->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
al->get = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(avail > 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (al = alist; al; al = al->next)
|
|
|
|
|
if (!fval(al, AFL_DONE)) {
|
|
|
|
|
int req = required(al->want - al->get, al->save);
|
|
|
|
|
assert(al->get <= al->want && al->get >= 0);
|
|
|
|
|
if (eff_skill(al->unit, itype->construction->skill, r)
|
|
|
|
|
>= rm->level + itype->construction->minskill - 1) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (req) {
|
|
|
|
|
norders += req;
|
|
|
|
|
} else {
|
|
|
|
|
fset(al, AFL_DONE);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
fset(al, AFL_DONE);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (first)
|
|
|
|
|
fset(al, AFL_LOWSKILL);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
need = norders;
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
avail = _min(avail, norders);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (need > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int use = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (al = alist; al; al = al->next)
|
|
|
|
|
if (!fval(al, AFL_DONE)) {
|
|
|
|
|
if (avail > 0) {
|
|
|
|
|
int want = required(al->want - al->get, al->save);
|
|
|
|
|
int x = avail * want / norders;
|
|
|
|
|
/* Wenn Rest, dann w<>rfeln, ob ich was bekomme: */
|
|
|
|
|
if (rng_int() % norders < (avail * want) % norders)
|
|
|
|
|
++x;
|
|
|
|
|
avail -= x;
|
|
|
|
|
use += x;
|
|
|
|
|
norders -= want;
|
|
|
|
|
need -= x;
|
2014-03-16 05:03:17 +01:00
|
|
|
|
al->get = _min(al->want, al->get + (int)(x / al->save));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (use) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(use <= rm->amount);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rm->type->use(rm, r, use);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(avail == 0 || norders == 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
first = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} while (need > 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
allocation *al;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int norders = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
|
|
|
|
|
resource_limit *rdata = (resource_limit *) a->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int avail = rdata->value;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (al = alist; al; al = al->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
norders += required(al->want, al->save);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rdata->limit) {
|
|
|
|
|
avail = rdata->limit(r, rtype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (avail < 0)
|
|
|
|
|
avail = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
avail = _min(avail, norders);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (al = alist; al; al = al->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (avail > 0) {
|
|
|
|
|
int want = required(al->want, al->save);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int x = avail * want / norders;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Wenn Rest, dann w<>rfeln, ob ich was bekomme: */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rng_int() % norders < (avail * want) % norders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
++x;
|
|
|
|
|
avail -= x;
|
|
|
|
|
norders -= want;
|
2014-03-16 05:03:17 +01:00
|
|
|
|
al->get = _min(al->want, (int)(x / al->save));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rdata->produce) {
|
|
|
|
|
int use = required(al->get, al->save);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (use)
|
|
|
|
|
rdata->produce(r, rtype, use);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(avail == 0 || norders == 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
typedef void (*allocate_function) (const resource_type *, struct region *,
|
|
|
|
|
struct allocation *);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static allocate_function get_allocator(const struct resource_type *rtype)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (a != NULL) {
|
|
|
|
|
resource_limit *rdata = (resource_limit *) a->data.v;
|
|
|
|
|
if (rdata->value > 0 || rdata->limit != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return attrib_allocation;
|
|
|
|
|
}
|
|
|
|
|
return leveled_allocation;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void split_allocations(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
allocation_list **p_alist = &allocations;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
freset(r, RF_SELECT);
|
|
|
|
|
while (*p_alist) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
allocation_list *alist = *p_alist;
|
|
|
|
|
const resource_type *rtype = alist->type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
allocate_function alloc = get_allocator(rtype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype = resource2item(rtype);
|
|
|
|
|
allocation **p_al = &alist->data;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
freset(r, RF_SELECT);
|
|
|
|
|
alloc(rtype, r, alist->data);
|
|
|
|
|
|
|
|
|
|
while (*p_al) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
allocation *al = *p_al;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (al->get) {
|
|
|
|
|
assert(itype || !"not implemented for non-items");
|
|
|
|
|
i_change(&al->unit->items, itype, al->get);
|
|
|
|
|
produceexp(al->unit, itype->construction->skill, al->unit->number);
|
|
|
|
|
fset(r, RF_SELECT);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (al->want == INT_MAX)
|
|
|
|
|
al->want = al->get;
|
|
|
|
|
ADDMSG(&al->unit->faction->msgs, msg_message("produce",
|
|
|
|
|
"unit region amount wanted resource",
|
|
|
|
|
al->unit, al->unit->region, al->get, al->want, rtype));
|
|
|
|
|
*p_al = al->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
free_allocation(al);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
*p_alist = alist->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
free(alist);
|
|
|
|
|
}
|
|
|
|
|
allocations = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void create_potion(unit * u, const potion_type * ptype, int want)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int built;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (want == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
want = maxbuild(u, ptype->itype->construction);
|
|
|
|
|
}
|
|
|
|
|
built = build(u, ptype->itype->construction, 0, want);
|
|
|
|
|
switch (built) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case ELOWSKILL:
|
|
|
|
|
case ENEEDSKILL:
|
|
|
|
|
/* no skill, or not enough skill points to build */
|
|
|
|
|
cmistake(u, u->thisorder, 50, MSG_PRODUCE);
|
|
|
|
|
break;
|
|
|
|
|
case EBUILDINGREQ:
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, u->thisorder, "building_needed", "building",
|
|
|
|
|
ptype->itype->construction->btype->_name));
|
|
|
|
|
break;
|
|
|
|
|
case ECOMPLETE:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
case ENOMATERIALS:
|
|
|
|
|
/* something missing from the list of materials */
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
|
|
|
|
|
ptype->itype->construction, want));
|
|
|
|
|
return;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
i_change(&u->items, ptype->itype, built);
|
|
|
|
|
if (want == INT_MAX)
|
|
|
|
|
want = built;
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("manufacture",
|
|
|
|
|
"unit region amount wanted resource", u, u->region, built, want,
|
|
|
|
|
ptype->itype->rtype));
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void create_item(unit * u, const item_type * itype, int want)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
if (itype->construction && fval(itype->rtype, RTF_LIMITED)) {
|
|
|
|
|
#if GUARD_DISABLES_PRODUCTION == 1
|
|
|
|
|
if (is_guarded(u->region, u, GUARD_PRODUCE)) {
|
|
|
|
|
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
allocate_resource(u, itype->rtype, want);
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const potion_type *ptype = resource2potion(itype->rtype);
|
|
|
|
|
if (ptype != NULL)
|
|
|
|
|
create_potion(u, ptype, want);
|
|
|
|
|
else if (itype->construction && itype->construction->materials)
|
|
|
|
|
manufacture(u, itype, want);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
|
|
|
|
|
"error_cannotmake", ""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int make_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
|
|
|
|
const building_type *btype;
|
|
|
|
|
const ship_type *stype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
param_t p;
|
|
|
|
|
int m;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
const char *s;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const struct locale *lang = u->faction->locale;
|
|
|
|
|
char ibuf[16];
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
m = atoi((const char *)s);
|
|
|
|
|
sprintf(ibuf, "%d", m);
|
|
|
|
|
if (!strcmp(ibuf, (const char *)s)) {
|
|
|
|
|
/* first came a want-paramter */
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
} else {
|
|
|
|
|
m = INT_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = findparam(s, u->faction->locale);
|
|
|
|
|
|
|
|
|
|
/* MACHE TEMP kann hier schon gar nicht auftauchen, weil diese nicht in
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* thisorder abgespeichert werden - und auf den ist getstrtoken() beim
|
|
|
|
|
* aufruf von make geeicht */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (p == P_ROAD) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (pl && fval(pl, PFL_NOBUILD)) {
|
|
|
|
|
cmistake(u, ord, 275, MSG_PRODUCE);
|
|
|
|
|
} else {
|
|
|
|
|
direction_t d = finddirection(getstrtoken(), u->faction->locale);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (d != NODIRECTION) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
build_road(r, u, m, d);
|
|
|
|
|
} else {
|
|
|
|
|
/* Die Richtung wurde nicht erkannt */
|
|
|
|
|
cmistake(u, ord, 71, MSG_PRODUCE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (p == P_SHIP) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (pl && fval(pl, PFL_NOBUILD)) {
|
|
|
|
|
cmistake(u, ord, 276, MSG_PRODUCE);
|
|
|
|
|
} else {
|
|
|
|
|
continue_ship(r, u, m);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (p == P_HERBS) {
|
|
|
|
|
herbsearch(r, u, m);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* since the string can match several objects, like in 'academy' and
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* 'academy of arts', we need to figure out what the player meant.
|
|
|
|
|
* This is not 100% safe.
|
|
|
|
|
*/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
stype = findshiptype(s, lang);
|
|
|
|
|
btype = findbuildingtype(s, lang);
|
|
|
|
|
itype = finditemtype(s, lang);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itype != NULL && (btype != NULL || stype != NULL)) {
|
|
|
|
|
if (itype->construction == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* if the item cannot be made, we probably didn't mean to make it */
|
|
|
|
|
itype = NULL;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (stype != NULL) {
|
|
|
|
|
const char *sname = LOC(lang, stype->name[0]);
|
|
|
|
|
const char *iname = LOC(lang, resourcename(itype->rtype, 0));
|
|
|
|
|
if (strlen(iname) < strlen(sname))
|
|
|
|
|
stype = NULL;
|
|
|
|
|
else
|
|
|
|
|
itype = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *bname = LOC(lang, btype->_name);
|
|
|
|
|
const char *iname = LOC(lang, resourcename(itype->rtype, 0));
|
|
|
|
|
if (strlen(iname) < strlen(bname))
|
|
|
|
|
btype = NULL;
|
|
|
|
|
else
|
|
|
|
|
itype = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (btype != NULL && stype != NULL) {
|
|
|
|
|
const char *bname = LOC(lang, btype->_name);
|
|
|
|
|
const char *sname = LOC(lang, stype->name[0]);
|
|
|
|
|
if (strlen(sname) < strlen(bname))
|
|
|
|
|
btype = NULL;
|
|
|
|
|
else
|
|
|
|
|
stype = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stype != NOSHIP) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (pl && fval(pl, PFL_NOBUILD)) {
|
|
|
|
|
cmistake(u, ord, 276, MSG_PRODUCE);
|
|
|
|
|
} else {
|
|
|
|
|
create_ship(r, u, stype, m, ord);
|
|
|
|
|
}
|
|
|
|
|
} else if (btype != NOBUILDING) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (pl && fval(pl, PFL_NOBUILD)) {
|
|
|
|
|
cmistake(u, ord, 94, MSG_PRODUCE);
|
|
|
|
|
} else {
|
|
|
|
|
build_building(u, btype, m, ord);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (itype != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
create_item(u, itype, m);
|
|
|
|
|
} else {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void free_luxuries(struct attrib *a)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item *itm = (item *) a->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
a->data.v = NULL;
|
|
|
|
|
i_freeall(&itm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const attrib_type at_luxuries = {
|
|
|
|
|
"luxuries", NULL, free_luxuries, NULL, NULL, NULL
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandbuying(region * r, request * buyorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int max_products;
|
|
|
|
|
unit *u;
|
|
|
|
|
static struct trade {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const luxury_type *type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int number;
|
|
|
|
|
int multi;
|
|
|
|
|
} *trades, *trade;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int ntrades = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int i, j;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const luxury_type *ltype;
|
|
|
|
|
|
|
|
|
|
if (ntrades == 0) {
|
|
|
|
|
for (ltype = luxurytypes; ltype; ltype = ltype->next)
|
|
|
|
|
++ntrades;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
trades = gc_add(calloc(sizeof(struct trade), ntrades));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0, ltype = luxurytypes; i != ntrades; ++i, ltype = ltype->next)
|
|
|
|
|
trades[i].type = ltype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; i != ntrades; ++i) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
trades[i].number = 0;
|
|
|
|
|
trades[i].multi = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!buyorders)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Initialisation. multiplier ist der Multiplikator auf den
|
|
|
|
|
* Verkaufspreis. F<EFBFBD>r max_products Produkte kauft man das Produkt zum
|
|
|
|
|
* einfachen Verkaufspreis, danach erh<EFBFBD>ht sich der Multiplikator um 1.
|
|
|
|
|
* counter ist ein Z<EFBFBD>hler, der die gekauften Produkte z<EFBFBD>hlt. money
|
|
|
|
|
* wird f<EFBFBD>r die debug message gebraucht. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
max_products = rpeasants(r) / TRADE_FRACTION;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Kauf - auch so programmiert, da<64> er leicht erweiterbar auf mehrere
|
|
|
|
|
* G<EFBFBD>ter pro Monat ist. j sind die Befehle, i der Index des
|
|
|
|
|
* gehandelten Produktes. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (max_products > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
expandorders(r, buyorders);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!norders)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (j = 0; j != norders; j++) {
|
|
|
|
|
int price, multi;
|
|
|
|
|
ltype = oa[j].type.ltype;
|
|
|
|
|
trade = trades;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (trade->type != ltype)
|
|
|
|
|
++trade;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
multi = trade->multi;
|
|
|
|
|
price = ltype->price * multi;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
if (get_pooled(oa[j].unit, oldresourcetype[R_SILVER], GET_DEFAULT,
|
|
|
|
|
price) >= price) {
|
|
|
|
|
unit *u = oa[j].unit;
|
|
|
|
|
item *items;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* litems z<>hlt die G<>ter, die verkauft wurden, u->n das Geld, das
|
|
|
|
|
* verdient wurde. Dies mu<EFBFBD> gemacht werden, weil der Preis st<EFBFBD>ndig sinkt,
|
|
|
|
|
* man sich also das verdiente Geld und die verkauften Produkte separat
|
|
|
|
|
* merken mu<EFBFBD>. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->attribs, &at_luxuries);
|
|
|
|
|
if (a == NULL)
|
|
|
|
|
a = a_add(&u->attribs, a_new(&at_luxuries));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
items = a->data.v;
|
|
|
|
|
i_change(&items, ltype->itype, 1);
|
|
|
|
|
a->data.v = items;
|
|
|
|
|
i_change(&oa[j].unit->items, ltype->itype, 1);
|
|
|
|
|
use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, price);
|
|
|
|
|
if (u->n < 0)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->n = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
u->n += price;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rsetmoney(r, rmoney(r) + price);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Falls mehr als max_products Bauern ein Produkt verkauft haben, steigt
|
|
|
|
|
* der Preis Multiplikator f<EFBFBD>r das Produkt um den Faktor 1. Der Z<EFBFBD>hler
|
|
|
|
|
* wird wieder auf 0 gesetzt. */
|
|
|
|
|
if (++trade->number == max_products) {
|
|
|
|
|
trade->number = 0;
|
|
|
|
|
++trade->multi;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
|
|
|
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(oa);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Ausgabe an Einheiten */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->attribs, &at_luxuries);
|
|
|
|
|
item *itm;
|
|
|
|
|
if (a == NULL)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("buy", "unit money", u, u->n));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (itm = (item *) a->data.v; itm; itm = itm->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (itm->number) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("buyamount",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit amount resource", u, itm->number, itm->type->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrib_type at_trades = {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"trades",
|
|
|
|
|
DEFAULT_INIT,
|
|
|
|
|
DEFAULT_FINALIZE,
|
|
|
|
|
DEFAULT_AGE,
|
|
|
|
|
NO_WRITE,
|
|
|
|
|
NO_READ
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void buy(unit * u, request ** buyorders, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int n, k;
|
|
|
|
|
request *o;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a;
|
|
|
|
|
const item_type *itype = NULL;
|
|
|
|
|
const luxury_type *ltype = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
|
|
|
|
cmistake(u, ord, 69, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
|
|
|
|
cmistake(u, ord, 69, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* Im Augenblick kann man nur 1 Produkt kaufen. expandbuying ist aber
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* schon daf<EFBFBD>r ausger<EFBFBD>stet, mehrere Produkte zu kaufen. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
n = getuint();
|
|
|
|
|
if (!n) {
|
|
|
|
|
cmistake(u, ord, 26, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (besieged(u)) {
|
|
|
|
|
/* Belagerte Einheiten k<>nnen nichts kaufen. */
|
|
|
|
|
cmistake(u, ord, 60, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == new_race[RC_INSECT]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* entweder man ist insekt, oder... */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->terrain != newterrain(T_SWAMP) && r->terrain != newterrain(T_DESERT)
|
|
|
|
|
&& !rbuildings(r)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 119, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* ...oder in der Region mu<6D> es eine Burg geben. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
building *b;
|
|
|
|
|
static const struct building_type *bt_castle;
|
|
|
|
|
if (!bt_castle)
|
|
|
|
|
bt_castle = bt_find("castle");
|
|
|
|
|
for (b = r->buildings; b; b = b->next) {
|
|
|
|
|
if (b->type == bt_castle && b->size >= 2)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (b == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 119, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ein H<>ndler kann nur 10 G<>ter pro Talentpunkt handeln. */
|
|
|
|
|
k = u->number * 10 * eff_skill(u, SK_TRADE, r);
|
|
|
|
|
|
|
|
|
|
/* hat der H<>ndler bereits gehandelt, muss die Menge der bereits
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* verkauften/gekauften G<EFBFBD>ter abgezogen werden */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
a = a_find(u->attribs, &at_trades);
|
|
|
|
|
if (!a) {
|
|
|
|
|
a = a_add(&u->attribs, a_new(&at_trades));
|
|
|
|
|
} else {
|
|
|
|
|
k -= a->data.i;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, k);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (!n) {
|
|
|
|
|
cmistake(u, ord, 102, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(n >= 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* die Menge der verkauften G<>ter merken */
|
|
|
|
|
a->data.i += n;
|
|
|
|
|
|
|
|
|
|
itype = finditemtype(getstrtoken(), u->faction->locale);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itype != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ltype = resource2luxury(itype->rtype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ltype == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 124, MSG_COMMERCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (r_demand(r, ltype)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "luxury_notsold", ""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
o = (request *) calloc(1, sizeof(request));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
o->type.ltype = ltype; /* sollte immer gleich sein */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
o->unit = u;
|
|
|
|
|
o->qty = n;
|
|
|
|
|
addlist(buyorders, o);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/* Steuers<72>tze in % bei Burggr<67><72>e */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 };
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandselling(region * r, request * sellorders, int limit)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int money, price, j, max_products;
|
|
|
|
|
/* int m, n = 0; */
|
|
|
|
|
int maxsize = 0, maxeffsize = 0;
|
|
|
|
|
int taxcollected = 0;
|
|
|
|
|
int hafencollected = 0;
|
|
|
|
|
unit *maxowner = (unit *) NULL;
|
|
|
|
|
building *maxb = (building *) NULL;
|
|
|
|
|
building *b;
|
|
|
|
|
unit *u;
|
|
|
|
|
unit *hafenowner;
|
|
|
|
|
static int *counter;
|
|
|
|
|
static int ncounter = 0;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ncounter == 0) {
|
|
|
|
|
const luxury_type *ltype;
|
|
|
|
|
for (ltype = luxurytypes; ltype; ltype = ltype->next)
|
|
|
|
|
++ncounter;
|
|
|
|
|
counter = (int *)gc_add(calloc(sizeof(int), ncounter));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
memset(counter, 0, sizeof(int) * ncounter);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
if (!sellorders) { /* NEIN, denn Insekten k<>nnen in || !r->buildings) */
|
|
|
|
|
return; /* S<>mpfen und W<>sten auch so handeln */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
/* Stelle Eigent<6E>mer der gr<67><72>ten Burg fest. Bekommt Steuern aus jedem
|
|
|
|
|
* Verkauf. Wenn zwei Burgen gleicher Gr<EFBFBD><EFBFBD>e bekommt gar keiner etwas. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (b = rbuildings(r); b; b = b->next) {
|
|
|
|
|
if (b->size > maxsize && building_owner(b) != NULL
|
2011-03-07 08:02:35 +01:00
|
|
|
|
&& b->type == bt_find("castle")) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
maxb = b;
|
|
|
|
|
maxsize = b->size;
|
|
|
|
|
maxowner = building_owner(b);
|
|
|
|
|
} else if (b->size == maxsize && b->type == bt_find("castle")) {
|
|
|
|
|
maxb = (building *) NULL;
|
|
|
|
|
maxowner = (unit *) NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
hafenowner = owner_buildingtyp(r, bt_find("harbour"));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (maxb != (building *) NULL && maxowner != (unit *) NULL) {
|
|
|
|
|
maxeffsize = buildingeffsize(maxb, false);
|
|
|
|
|
if (maxeffsize == 0) {
|
|
|
|
|
maxb = (building *) NULL;
|
|
|
|
|
maxowner = (unit *) NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Die Region muss genug Geld haben, um die Produkte kaufen zu k<>nnen. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
money = rmoney(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* max_products sind 1/100 der Bev<65>lkerung, falls soviele Produkte
|
|
|
|
|
* verkauft werden - counter[] - sinkt die Nachfrage um 1 Punkt.
|
|
|
|
|
* multiplier speichert r->demand f<EFBFBD>r die debug message ab. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
max_products = rpeasants(r) / TRADE_FRACTION;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (max_products <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (r->terrain == newterrain(T_DESERT)
|
|
|
|
|
&& buildingtype_exists(r, bt_find("caravan"), true)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
max_products = rpeasants(r) * 2 / TRADE_FRACTION;
|
|
|
|
|
}
|
|
|
|
|
/* Verkauf: so programmiert, dass er leicht auf mehrere Gueter pro
|
|
|
|
|
* Runde erweitert werden kann. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
expandorders(r, sellorders);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!norders)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (j = 0; j != norders; j++) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const luxury_type *search = NULL;
|
|
|
|
|
const luxury_type *ltype = oa[j].type.ltype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int multi = r_demand(r, ltype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int i = -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int use = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (search != ltype) {
|
|
|
|
|
i = 0;
|
|
|
|
|
for (search = luxurytypes; search != ltype; search = search->next)
|
|
|
|
|
++i;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (counter[i] >= limit)
|
|
|
|
|
continue;
|
|
|
|
|
if (counter[i] + 1 > max_products && multi > 1)
|
|
|
|
|
--multi;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
price = ltype->price * multi;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (money >= price) {
|
|
|
|
|
int abgezogenhafen = 0;
|
|
|
|
|
int abgezogensteuer = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = oa[j].unit;
|
|
|
|
|
item *itm;
|
|
|
|
|
attrib *a = a_find(u->attribs, &at_luxuries);
|
|
|
|
|
if (a == NULL)
|
|
|
|
|
a = a_add(&u->attribs, a_new(&at_luxuries));
|
|
|
|
|
itm = (item *) a->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i_change(&itm, ltype->itype, 1);
|
|
|
|
|
a->data.v = itm;
|
|
|
|
|
++use;
|
|
|
|
|
if (u->n < 0)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->n = 0;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (hafenowner != NULL) {
|
|
|
|
|
if (hafenowner->faction != u->faction) {
|
|
|
|
|
abgezogenhafen = price / 10;
|
|
|
|
|
hafencollected += abgezogenhafen;
|
|
|
|
|
price -= abgezogenhafen;
|
|
|
|
|
money -= abgezogenhafen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (maxb != NULL) {
|
|
|
|
|
if (maxowner->faction != u->faction) {
|
|
|
|
|
abgezogensteuer = price * tax_per_size[maxeffsize] / 100;
|
|
|
|
|
taxcollected += abgezogensteuer;
|
|
|
|
|
price -= abgezogensteuer;
|
|
|
|
|
money -= abgezogensteuer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
u->n += price;
|
|
|
|
|
change_money(u, price);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* r->money -= price; --- dies wird eben nicht ausgef<65>hrt, denn die
|
|
|
|
|
* Produkte k<EFBFBD>nnen auch als Steuern eingetrieben werden. In der Region
|
|
|
|
|
* wurden Silberst<EFBFBD>cke gegen Luxusg<EFBFBD>ter des selben Wertes eingetauscht!
|
|
|
|
|
* Falls mehr als max_products Kunden ein Produkt gekauft haben, sinkt
|
|
|
|
|
* die Nachfrage f<EFBFBD>r das Produkt um 1. Der Z<EFBFBD>hler wird wieder auf 0
|
|
|
|
|
* gesetzt. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (++counter[i] > max_products) {
|
|
|
|
|
int d = r_demand(r, ltype);
|
|
|
|
|
if (d > 1) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
r_setdemand(r, ltype, d - 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
counter[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (use > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#ifdef NDEBUG
|
|
|
|
|
use_pooled(oa[j].unit, ltype->itype->rtype, GET_DEFAULT, use);
|
|
|
|
|
#else
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* int i = */ use_pooled(oa[j].unit, ltype->itype->rtype, GET_DEFAULT,
|
|
|
|
|
use);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* assert(i==use); */
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(oa);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Steuern. Hier werden die Steuern dem Besitzer der gr<67><72>ten Burg gegeben. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (maxowner) {
|
|
|
|
|
if (taxcollected > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
change_money(maxowner, (int)taxcollected);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_income(maxowner, IC_TRADETAX, taxcollected, taxcollected);
|
|
|
|
|
/* TODO: Meldung
|
|
|
|
|
* "%s verdient %d Silber durch den Handel in %s.",
|
|
|
|
|
* unitname(maxowner), (int) taxcollected, regionname(r)); */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hafenowner) {
|
|
|
|
|
if (hafencollected > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
change_money(hafenowner, (int)hafencollected);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_income(hafenowner, IC_TRADETAX, hafencollected, hafencollected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Berichte an die Einheiten */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
attrib *a = a_find(u->attribs, &at_luxuries);
|
|
|
|
|
item *itm;
|
|
|
|
|
if (a == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
for (itm = (item *) a->data.v; itm; itm = itm->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (itm->number) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("sellamount",
|
|
|
|
|
"unit amount resource", u, itm->number, itm->type->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
add_income(u, IC_TRADE, u->n, u->n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool sell(unit * u, request ** sellorders, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool unlimited = true;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype;
|
|
|
|
|
const luxury_type *ltype = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int n;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
const char *s;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
cmistake(u, ord, 69, MSG_INCOME);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* sellorders sind KEIN array, weil f<>r alle items DIE SELBE resource
|
|
|
|
|
* (das geld der region) aufgebraucht wird. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (findparam(s, u->faction->locale) == P_ANY) {
|
|
|
|
|
unlimited = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
n = rpeasants(r) / TRADE_FRACTION;
|
|
|
|
|
if (r->terrain == newterrain(T_DESERT)
|
|
|
|
|
&& buildingtype_exists(r, bt_find("caravan"), true))
|
|
|
|
|
n *= 2;
|
|
|
|
|
if (n == 0) {
|
|
|
|
|
cmistake(u, ord, 303, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
n = atoi((const char *)s);
|
|
|
|
|
if (n == 0) {
|
|
|
|
|
cmistake(u, ord, 27, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Belagerte Einheiten k<>nnen nichts verkaufen. */
|
|
|
|
|
|
|
|
|
|
if (besieged(u)) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error60", ""));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* In der Region mu<6D> es eine Burg geben. */
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == new_race[RC_INSECT]) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->terrain != newterrain(T_SWAMP) && r->terrain != newterrain(T_DESERT)
|
|
|
|
|
&& !rbuildings(r)) {
|
|
|
|
|
cmistake(u, ord, 119, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ...oder in der Region mu<6D> es eine Burg geben. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
building *b;
|
|
|
|
|
static const struct building_type *bt_castle;
|
|
|
|
|
if (!bt_castle)
|
|
|
|
|
bt_castle = bt_find("castle");
|
|
|
|
|
for (b = r->buildings; b; b = b->next) {
|
|
|
|
|
if (b->type == bt_castle && b->size >= 2)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (b == NULL) {
|
|
|
|
|
cmistake(u, ord, 119, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ein H<>ndler kann nur 10 G<>ter pro Talentpunkt verkaufen. */
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, u->number * 10 * eff_skill(u, SK_TRADE, r));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
if (!n) {
|
|
|
|
|
cmistake(u, ord, 54, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
itype = finditemtype(s, u->faction->locale);
|
|
|
|
|
if (itype != NULL)
|
|
|
|
|
ltype = resource2luxury(itype->rtype);
|
|
|
|
|
if (ltype == NULL) {
|
|
|
|
|
cmistake(u, ord, 126, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
attrib *a;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
request *o;
|
|
|
|
|
int k, available;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!r_demand(r, ltype)) {
|
|
|
|
|
cmistake(u, ord, 263, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
available = get_pooled(u, itype->rtype, GET_DEFAULT, INT_MAX);
|
|
|
|
|
|
|
|
|
|
/* Wenn andere Einheiten das selbe verkaufen, mu<6D> ihr Zeug abgezogen
|
|
|
|
|
* werden damit es nicht zweimal verkauft wird: */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (o = *sellorders; o; o = o->next) {
|
|
|
|
|
if (o->type.ltype == ltype && o->unit->faction == u->faction) {
|
|
|
|
|
int fpool =
|
|
|
|
|
o->qty - get_pooled(o->unit, itype->rtype, GET_RESERVE, INT_MAX);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
available -= _max(0, fpool);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, available);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n <= 0) {
|
|
|
|
|
cmistake(u, ord, 264, MSG_COMMERCE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* Hier wird request->type verwendet, weil die obere limit durch
|
|
|
|
|
* das silber gegeben wird (region->money), welches f<EFBFBD>r alle
|
|
|
|
|
* (!) produkte als summe gilt, als nicht wie bei der
|
|
|
|
|
* produktion, wo f<EFBFBD>r jedes produkt einzeln eine obere limite
|
|
|
|
|
* existiert, so dass man arrays von orders machen kann. */
|
|
|
|
|
|
|
|
|
|
/* Ein H<>ndler kann nur 10 G<>ter pro Talentpunkt handeln. */
|
|
|
|
|
k = u->number * 10 * eff_skill(u, SK_TRADE, r);
|
|
|
|
|
|
|
|
|
|
/* hat der H<>ndler bereits gehandelt, muss die Menge der bereits
|
|
|
|
|
* verkauften/gekauften G<EFBFBD>ter 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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, k);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(n >= 0);
|
|
|
|
|
/* die Menge der verkauften G<>ter merken */
|
|
|
|
|
a->data.i += n;
|
|
|
|
|
o = (request *) calloc(1, sizeof(request));
|
|
|
|
|
o->unit = u;
|
|
|
|
|
o->qty = n;
|
|
|
|
|
o->type.ltype = ltype;
|
|
|
|
|
addlist(sellorders, o);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
return unlimited;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandstealing(region * r, request * stealorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int i;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
expandorders(r, stealorders);
|
|
|
|
|
if (!norders)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* F<>r jede unit in der Region wird Geld geklaut, wenn sie Opfer eines
|
|
|
|
|
* Beklauen-Orders ist. Jedes Opfer mu<EFBFBD> einzeln behandelt werden.
|
|
|
|
|
*
|
|
|
|
|
* u ist die beklaute unit. oa.unit ist die klauende unit.
|
|
|
|
|
*/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i != norders && oa[i].unit->n <= oa[i].unit->wants; i++) {
|
|
|
|
|
unit *u = findunitg(oa[i].no, r);
|
|
|
|
|
int n = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u && u->region == r) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n = get_pooled(u, r_silver, GET_ALL, INT_MAX);
|
|
|
|
|
}
|
|
|
|
|
#ifndef GOBLINKILL
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (oa[i].type.goblin) { /* Goblin-Spezialklau */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int uct = 0;
|
|
|
|
|
unit *u2;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(effskill(oa[i].unit, SK_STEALTH) >= 4
|
|
|
|
|
|| !"this goblin\'s skill is too low");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u2->faction == u->faction) {
|
|
|
|
|
uct += maintenance_cost(u2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
n -= uct * 2;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n > 10 && rplane(r) && (rplane(r)->flags & PFL_NOALLIANCES)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* In Questen nur reduziertes Klauen */
|
|
|
|
|
n = 10;
|
|
|
|
|
}
|
|
|
|
|
if (n > 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, oa[i].unit->wants);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
use_pooled(u, r_silver, GET_ALL, n);
|
|
|
|
|
oa[i].unit->n = n;
|
|
|
|
|
change_money(oa[i].unit, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("stealeffect", "unit region amount",
|
|
|
|
|
u, u->region, n));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
add_income(oa[i].unit, IC_STEAL, oa[i].unit->wants, oa[i].unit->n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
fset(oa[i].unit, UFL_LONGACTION | UFL_NOTMOVING);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
free(oa);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void plant(region * r, unit * u, int raw)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n, i, skill, planted = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype;
|
|
|
|
|
static const resource_type *rt_water = NULL;
|
|
|
|
|
if (rt_water == NULL)
|
|
|
|
|
rt_water = rt_find("p2");
|
|
|
|
|
|
|
|
|
|
assert(rt_water != NULL);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!fval(r->terrain, LAND_REGION)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (rherbtype(r) == NULL) {
|
|
|
|
|
cmistake(u, u->thisorder, 108, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Skill pr<70>fen */
|
|
|
|
|
skill = eff_skill(u, SK_HERBALISM, r);
|
|
|
|
|
itype = rherbtype(r);
|
|
|
|
|
if (skill < 6) {
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "plant_skills",
|
|
|
|
|
"skill minskill product", SK_HERBALISM, 6, itype->rtype, 1));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* Wasser des Lebens pr<70>fen */
|
|
|
|
|
if (get_pooled(u, rt_water, GET_DEFAULT, 1) == 0) {
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "resource_missing", "missing", rt_water));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
n = get_pooled(u, itype->rtype, GET_DEFAULT, skill * u->number);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Kr<4B>uter pr<70>fen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "resource_missing", "missing",
|
|
|
|
|
itype->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(skill * u->number, n);
|
|
|
|
|
n = _min(raw, n);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* F<>r jedes Kraut Talent*10% Erfolgschance. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = n; i > 0; i--) {
|
|
|
|
|
if (rng_int() % 10 < skill)
|
|
|
|
|
planted++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
produceexp(u, SK_HERBALISM, u->number);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Alles ok. Abziehen. */
|
|
|
|
|
use_pooled(u, rt_water, GET_DEFAULT, 1);
|
|
|
|
|
use_pooled(u, itype->rtype, GET_DEFAULT, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsetherbs(r, rherbs(r) + planted);
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("plant", "unit region amount herb",
|
|
|
|
|
u, r, planted, itype->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void planttrees(region * r, unit * u, int raw)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n, i, skill, planted = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const resource_type *rtype;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!fval(r->terrain, LAND_REGION)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Mallornb<6E>ume kann man nur in Mallornregionen z<>chten */
|
|
|
|
|
if (fval(r, RF_MALLORN)) {
|
|
|
|
|
rtype = rt_mallornseed;
|
|
|
|
|
} else {
|
|
|
|
|
rtype = rt_seed;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Skill pr<70>fen */
|
|
|
|
|
skill = eff_skill(u, SK_HERBALISM, r);
|
|
|
|
|
if (skill < 6) {
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "plant_skills",
|
|
|
|
|
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (fval(r, RF_MALLORN) && skill < 7) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "plant_skills",
|
|
|
|
|
"skill minskill product", SK_HERBALISM, 7, rtype, 1));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
raw = _min(raw, skill * u->number);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n = get_pooled(u, rtype, GET_DEFAULT, raw);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(raw, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* F<>r jeden Samen Talent*10% Erfolgschance. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = n; i > 0; i--) {
|
|
|
|
|
if (rng_int() % 10 < skill)
|
|
|
|
|
planted++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsettrees(r, 0, rtrees(r, 0) + planted);
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Alles ok. Abziehen. */
|
|
|
|
|
produceexp(u, SK_HERBALISM, u->number);
|
|
|
|
|
use_pooled(u, rtype, GET_DEFAULT, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("plant",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit region amount herb", u, r, planted, rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* z<>chte b<>ume */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void breedtrees(region * r, unit * u, int raw)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n, i, skill, planted = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const resource_type *rtype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
static int gamecookie = -1;
|
|
|
|
|
static int current_season;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
if (gamecookie != global.cookie) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
gamedate date;
|
|
|
|
|
get_gamedate(turn, &date);
|
|
|
|
|
current_season = date.season;
|
|
|
|
|
gamecookie = global.cookie;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* B<>ume z<>chten geht nur im Fr<46>hling */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (current_season != SEASON_SPRING) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
planttrees(r, u, raw);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!fval(r->terrain, LAND_REGION)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Mallornb<6E>ume kann man nur in Mallornregionen z<>chten */
|
|
|
|
|
if (fval(r, RF_MALLORN)) {
|
|
|
|
|
rtype = rt_mallornseed;
|
|
|
|
|
} else {
|
|
|
|
|
rtype = rt_seed;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Skill pr<70>fen */
|
|
|
|
|
skill = eff_skill(u, SK_HERBALISM, r);
|
|
|
|
|
if (skill < 12) {
|
|
|
|
|
planttrees(r, u, raw);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
raw = _min(skill * u->number, raw);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n = get_pooled(u, rtype, GET_DEFAULT, raw);
|
|
|
|
|
/* Samen pr<70>fen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(raw, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* F<>r jeden Samen Talent*5% Erfolgschance. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = n; i > 0; i--) {
|
|
|
|
|
if (rng_int() % 100 < skill * 5)
|
|
|
|
|
planted++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsettrees(r, 1, rtrees(r, 1) + planted);
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Alles ok. Abziehen. */
|
|
|
|
|
produceexp(u, SK_HERBALISM, u->number);
|
|
|
|
|
use_pooled(u, rtype, GET_DEFAULT, n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("plant",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit region amount herb", u, r, planted, rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* z<>chte pferde */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void breedhorses(region * r, unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n, c;
|
|
|
|
|
int gezuechtet = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct building *b = inside_building(u);
|
|
|
|
|
const struct building_type *btype = b ? b->type : NULL;
|
|
|
|
|
|
|
|
|
|
if (btype != bt_find("stables")) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, u->thisorder, 122, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (get_item(u, I_HORSE) < 2) {
|
|
|
|
|
cmistake(u, u->thisorder, 107, MSG_PRODUCE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(u->number * eff_skill(u, SK_HORSE_TRAINING, r), get_item(u, I_HORSE));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (c = 0; c < n; c++) {
|
|
|
|
|
if (rng_int() % 100 < eff_skill(u, SK_HORSE_TRAINING, r)) {
|
|
|
|
|
i_change(&u->items, olditemtype[I_HORSE], 1);
|
|
|
|
|
gezuechtet++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
produceexp(u, SK_HORSE_TRAINING, u->number);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("raised",
|
|
|
|
|
"unit amount", u, gezuechtet));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void breed_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int m;
|
|
|
|
|
const char *s;
|
|
|
|
|
param_t p;
|
|
|
|
|
region *r = u->region;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const resource_type *rtype = NULL;
|
|
|
|
|
|
|
|
|
|
if (r->land == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* z<>chte [<anzahl>] <parameter> */
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
m = atoi((const char *)s);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (m != 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* first came a want-paramter */
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
} else {
|
|
|
|
|
m = INT_MAX;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!s[0]) {
|
|
|
|
|
p = P_ANY;
|
|
|
|
|
} else {
|
|
|
|
|
p = findparam(s, u->faction->locale);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
switch (p) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_HERBS:
|
|
|
|
|
plant(r, u, m);
|
|
|
|
|
break;
|
|
|
|
|
case P_TREES:
|
|
|
|
|
breedtrees(r, u, m);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (p != P_ANY) {
|
|
|
|
|
rtype = findresourcetype(s, u->faction->locale);
|
|
|
|
|
if (rtype == rt_mallornseed || rtype == rt_seed) {
|
|
|
|
|
breedtrees(r, u, m);
|
|
|
|
|
break;
|
|
|
|
|
} else if (rtype != oldresourcetype[R_HORSE]) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ""));
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
breedhorses(r, u);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const char *rough_amount(int a, int m)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int p = (a * 100) / m;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (p < 10) {
|
|
|
|
|
return "sehr wenige";
|
|
|
|
|
} else if (p < 30) {
|
|
|
|
|
return "wenige";
|
|
|
|
|
} else if (p < 60) {
|
|
|
|
|
return "relativ viele";
|
|
|
|
|
} else if (p < 90) {
|
|
|
|
|
return "viele";
|
|
|
|
|
}
|
|
|
|
|
return "sehr viele";
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void research_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
/*
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (findparam(s, u->faction->locale) == P_HERBS) { */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (eff_skill(u, SK_HERBALISM, r) < 7) {
|
|
|
|
|
cmistake(u, ord, 227, MSG_EVENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
produceexp(u, SK_HERBALISM, u->number);
|
|
|
|
|
|
|
|
|
|
if (rherbs(r) > 0) {
|
|
|
|
|
const item_type *itype = rherbtype(r);
|
|
|
|
|
|
|
|
|
|
if (itype != NULL) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("researchherb",
|
|
|
|
|
"unit region amount herb",
|
|
|
|
|
u, r, rough_amount(rherbs(r), 100), itype->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("researchherb_none",
|
|
|
|
|
"unit region", u, r));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("researchherb_none",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit region", u, r));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int max_skill(region * r, faction * f, skill_t sk)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
int w = 0;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (u->faction == f) {
|
|
|
|
|
if (eff_skill(u, sk, r) > w) {
|
|
|
|
|
w = eff_skill(u, sk, r);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int n, i, id;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool goblin = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
request *o;
|
|
|
|
|
unit *u2 = NULL;
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
faction *f = NULL;
|
|
|
|
|
plane *pl;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
assert(skill_enabled[SK_PERCEPTION] && skill_enabled[SK_STEALTH]);
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!fval(u_race(u), RCF_CANSTEAL)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nosteal", "race",
|
2013-05-02 03:42:20 +02:00
|
|
|
|
u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (fval(r->terrain, SEA_REGION) && u_race(u) != new_race[RC_AQUARIAN]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pl = rplane(r);
|
|
|
|
|
if (pl && fval(pl, PFL_NOATTACK)) {
|
|
|
|
|
cmistake(u, ord, 270, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
id = read_unitid(u->faction, r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u2 = findunitr(r, id);
|
|
|
|
|
|
|
|
|
|
if (u2 && u2->region == u->region) {
|
|
|
|
|
f = u2->faction;
|
|
|
|
|
} else {
|
|
|
|
|
f = dfindhash(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u2->faction == f && cansee(u->faction, r, u2, 0))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!u2) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
|
|
|
|
""));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsImmune(u2->faction)) {
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, ord, "newbie_immunity_error", "turns", NewbieImmunity()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->faction->alliance && u->faction->alliance == u2->faction->alliance) {
|
|
|
|
|
cmistake(u, ord, 47, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(u->region == u2->region);
|
|
|
|
|
if (!can_contact(r, u, u2)) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error60", ""));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = eff_skill(u, SK_STEALTH, r) - max_skill(r, f, SK_PERCEPTION);
|
|
|
|
|
|
|
|
|
|
if (n <= 0) {
|
|
|
|
|
/* Wahrnehmung == Tarnung */
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) != new_race[RC_GOBLIN] || eff_skill(u, SK_STEALTH, r) <= 3) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("stealfail", "unit target", u, u2));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message("stealdetect", "unit", u2));
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message("thiefdiscover", "unit target",
|
|
|
|
|
u, u2));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("stealfatal", "unit target", u,
|
|
|
|
|
u2));
|
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message("thiefdiscover", "unit target", u,
|
|
|
|
|
u2));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n = 1;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
goblin = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
i = _min(u->number, get_item(u, I_RING_OF_NIMBLEFINGER));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i > 0) {
|
|
|
|
|
n *= STEALINCOME * (u->number + i * (roqf_factor() - 1));
|
|
|
|
|
} else {
|
|
|
|
|
n *= u->number * STEALINCOME;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->wants = n;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* wer dank unsichtbarkeitsringen klauen kann, muss nicht unbedingt ein
|
|
|
|
|
* guter dieb sein, schliesslich macht man immer noch sehr viel laerm */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
o = (request *) calloc(1, sizeof(request));
|
|
|
|
|
o->unit = u;
|
|
|
|
|
o->qty = 1; /* Betrag steht in u->wants */
|
|
|
|
|
o->no = u2->no;
|
|
|
|
|
o->type.goblin = goblin; /* Merken, wenn Goblin-Spezialklau */
|
|
|
|
|
addlist(stealorders, o);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
produceexp(u, SK_STEALTH, _min(n, u->number));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandentertainment(region * r)
|
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
int m = entertainmoney(r);
|
|
|
|
|
request *o;
|
|
|
|
|
|
|
|
|
|
for (o = &entertainers[0]; o != nextentertainer; ++o) {
|
|
|
|
|
double part = m / (double)entertaining;
|
|
|
|
|
u = o->unit;
|
|
|
|
|
if (entertaining <= m)
|
|
|
|
|
u->n = o->qty;
|
|
|
|
|
else
|
|
|
|
|
u->n = (int)(o->qty * part);
|
|
|
|
|
change_money(u, u->n);
|
|
|
|
|
rsetmoney(r, rmoney(r) - u->n);
|
|
|
|
|
m -= u->n;
|
|
|
|
|
entertaining -= o->qty;
|
|
|
|
|
|
|
|
|
|
/* Nur soviel PRODUCEEXP wie auch tats<74>chlich gemacht wurde */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
produceexp(u, SK_ENTERTAINMENT, _min(u->n, u->number));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
add_income(u, IC_ENTERTAIN, o->qty, u->n);
|
|
|
|
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void entertain_cmd(unit * u, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int max_e;
|
|
|
|
|
request *o;
|
|
|
|
|
static int entertainbase = 0;
|
|
|
|
|
static int entertainperlevel = 0;
|
|
|
|
|
|
|
|
|
|
if (!entertainbase) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *str = get_param(global.parameters, "entertain.base");
|
|
|
|
|
entertainbase = str ? atoi(str) : 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (!entertainperlevel) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *str = get_param(global.parameters, "entertain.perlevel");
|
|
|
|
|
entertainperlevel = str ? atoi(str) : 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (fval(u, UFL_WERE)) {
|
|
|
|
|
cmistake(u, ord, 58, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!effskill(u, SK_ENTERTAINMENT)) {
|
|
|
|
|
cmistake(u, ord, 58, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (besieged(u)) {
|
|
|
|
|
cmistake(u, ord, 60, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
|
|
|
|
cmistake(u, ord, 69, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (is_cursed(r->attribs, C_DEPRESSION, 0)) {
|
|
|
|
|
cmistake(u, ord, 28, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->wants = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* entertainperlevel);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
max_e = getuint();
|
|
|
|
|
if (max_e != 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
u->wants = _min(u->wants, max_e);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
o = nextentertainer++;
|
|
|
|
|
o->unit = u;
|
|
|
|
|
o->qty = u->wants;
|
|
|
|
|
entertaining += o->qty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \return number of working spaces taken by players
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
expandwork(region * r, request * work_begin, request * work_end, int maxwork)
|
|
|
|
|
{
|
|
|
|
|
int earnings;
|
|
|
|
|
/* n: verbleibende Einnahmen */
|
|
|
|
|
/* fishes: maximale Arbeiter */
|
|
|
|
|
int jobs = maxwork;
|
|
|
|
|
int p_wage = wage(r, NULL, NULL, turn);
|
|
|
|
|
int money = rmoney(r);
|
|
|
|
|
request *o;
|
|
|
|
|
|
|
|
|
|
for (o = work_begin; o != work_end; ++o) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = o->unit;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int workers;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->number == 0)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (jobs >= working)
|
|
|
|
|
workers = u->number;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
else {
|
|
|
|
|
workers = u->number * jobs / working;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rng_int() % working < (u->number * jobs) % working)
|
|
|
|
|
workers++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(workers >= 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
u->n = workers * wage(u->region, u->faction, u_race(u), turn);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
jobs -= workers;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(jobs >= 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
change_money(u, u->n);
|
|
|
|
|
working -= o->unit->number;
|
|
|
|
|
add_income(u, IC_WORK, o->qty, u->n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (jobs > rpeasants(r)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
jobs = rpeasants(r);
|
|
|
|
|
}
|
|
|
|
|
earnings = jobs * p_wage;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rule_blessed_harvest() == HARVEST_TAXES) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* E3 rules */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const curse_type *blessedharvest_ct;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!blessedharvest_ct) {
|
|
|
|
|
blessedharvest_ct = ct_find("blessedharvest");
|
|
|
|
|
}
|
|
|
|
|
if (blessedharvest_ct && r->attribs) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int happy =
|
|
|
|
|
(int)curse_geteffect(get_curse(r->attribs, blessedharvest_ct));
|
2014-03-16 05:03:17 +01:00
|
|
|
|
happy = _min(happy, jobs);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
earnings += happy;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rsetmoney(r, money + earnings);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int do_work(unit * u, order * ord, request * o)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (playerrace(u_race(u))) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int w;
|
|
|
|
|
|
|
|
|
|
if (fval(u, UFL_WERE)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ord)
|
|
|
|
|
cmistake(u, ord, 313, MSG_INCOME);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (besieged(u)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ord)
|
|
|
|
|
cmistake(u, ord, 60, MSG_INCOME);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ord)
|
|
|
|
|
cmistake(u, ord, 69, MSG_INCOME);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-05-02 03:42:20 +02:00
|
|
|
|
w = wage(r, u->faction, u_race(u), turn);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
u->wants = u->number * w;
|
|
|
|
|
o->unit = u;
|
|
|
|
|
o->qty = u->number * w;
|
|
|
|
|
working += u->number;
|
|
|
|
|
return 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (ord && !is_monsters(u->faction)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2013-05-02 03:42:20 +02:00
|
|
|
|
msg_feedback(u, ord, "race_cantwork", "race", u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void expandtax(region * r, request * taxorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
expandorders(r, taxorders);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!norders)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i != norders && rmoney(r) > TAXFRACTION; i++) {
|
|
|
|
|
change_money(oa[i].unit, TAXFRACTION);
|
|
|
|
|
oa[i].unit->n += TAXFRACTION;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsetmoney(r, rmoney(r) - TAXFRACTION);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
free(oa);
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (u->n >= 0) {
|
|
|
|
|
add_income(u, IC_TAX, u->wants, u->n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void tax_cmd(unit * u, struct order *ord, request ** taxorders)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
/* Steuern werden noch vor der Forschung eingetrieben */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u2;
|
|
|
|
|
int n;
|
|
|
|
|
request *o;
|
|
|
|
|
int max;
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!humanoidrace(u_race(u)) && !is_monsters(u->faction)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 228, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fval(u, UFL_WERE)) {
|
|
|
|
|
cmistake(u, ord, 228, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (besieged(u)) {
|
|
|
|
|
cmistake(u, ord, 60, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
n = armedmen(u, false);
|
|
|
|
|
|
|
|
|
|
if (!n) {
|
|
|
|
|
cmistake(u, ord, 48, MSG_INCOME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
max = getuint();
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (max == 0)
|
|
|
|
|
max = INT_MAX;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!playerrace(u_race(u))) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
u->wants = _min(income(u), max);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
u->wants = _min(n * eff_skill(u, SK_TAXING, r) * 20, max);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u2 = is_guarded(r, u, GUARD_TAX);
|
|
|
|
|
if (u2) {
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, ord, "region_guarded", "guard", u2));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* die einnahmen werden in fraktionen von 10 silber eingeteilt: diese
|
|
|
|
|
* fraktionen werden dann bei eintreiben unter allen eintreibenden
|
|
|
|
|
* einheiten aufgeteilt. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
o = (request *) calloc(1, sizeof(request));
|
|
|
|
|
o->qty = u->wants / TAXFRACTION;
|
|
|
|
|
o->unit = u;
|
|
|
|
|
addlist(taxorders, o);
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define MAX_WORKERS 2048
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void auto_work(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
request workers[MAX_WORKERS];
|
2011-03-07 08:02:35 +01:00
|
|
|
|
request *nextworker = workers;
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!(u->flags & UFL_LONGACTION) && !is_monsters(u->faction)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (do_work(u, NULL, nextworker) == 0) {
|
|
|
|
|
assert(nextworker - workers < MAX_WORKERS);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
++nextworker;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (nextworker != workers) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
expandwork(r, workers, nextworker, maxworkingpeasants(r));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void peasant_taxes(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f;
|
|
|
|
|
unit *u;
|
|
|
|
|
building *b;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int money;
|
|
|
|
|
int maxsize;
|
|
|
|
|
|
|
|
|
|
f = region_get_owner(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f == NULL || is_mourning(r, turn)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
money = rmoney(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (money <= 0)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
b = largestbuilding(r, cmp_taxes, false);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (b == NULL)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
u = building_owner(b);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u == NULL || u->faction != f)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
maxsize = buildingeffsize(b, false);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (maxsize > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
double taxfactor = money * b->type->taxes(b, maxsize);
|
|
|
|
|
double morale = money * region_get_morale(r) * MORALE_TAX_FACTOR;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (taxfactor > morale)
|
|
|
|
|
taxfactor = morale;
|
|
|
|
|
if (taxfactor > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int taxmoney = (int)taxfactor;
|
|
|
|
|
change_money(u, taxmoney);
|
|
|
|
|
rsetmoney(r, money - taxmoney);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("income_tax",
|
|
|
|
|
"unit region amount", u, r, taxmoney));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void produce(struct region *r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
request workers[MAX_WORKERS];
|
|
|
|
|
request *taxorders, *sellorders, *stealorders, *buyorders;
|
|
|
|
|
unit *u;
|
|
|
|
|
int todo;
|
|
|
|
|
static int rule_autowork = -1;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool limited = true;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
request *nextworker = workers;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
assert(r);
|
|
|
|
|
|
|
|
|
|
/* das sind alles befehle, die 30 tage brauchen, und die in thisorder
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* stehen! von allen 30-tage befehlen wird einfach der letzte verwendet
|
|
|
|
|
* (dosetdefaults).
|
|
|
|
|
*
|
|
|
|
|
* kaufen vor einnahmequellen. da man in einer region dasselbe produkt
|
|
|
|
|
* nicht kaufen und verkaufen kann, ist die reihenfolge wegen der
|
|
|
|
|
* produkte egal. nicht so wegen dem geld.
|
|
|
|
|
*
|
|
|
|
|
* lehren vor lernen. */
|
|
|
|
|
|
|
|
|
|
if (rule_autowork < 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rule_autowork = get_param_int(global.parameters, "work.auto", 0);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
assert(rmoney(r) >= 0);
|
|
|
|
|
assert(rpeasants(r) >= 0);
|
|
|
|
|
|
|
|
|
|
if (r->land && rule_auto_taxation()) {
|
|
|
|
|
/* new taxation rules, region owners make money based on morale and building */
|
|
|
|
|
peasant_taxes(r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buyorders = 0;
|
|
|
|
|
sellorders = 0;
|
|
|
|
|
working = 0;
|
|
|
|
|
nextentertainer = &entertainers[0];
|
|
|
|
|
entertaining = 0;
|
|
|
|
|
taxorders = 0;
|
|
|
|
|
stealorders = 0;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool trader = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == new_race[RC_SPELL] || fval(u, UFL_LONGACTION))
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == new_race[RC_INSECT] && r_insectstalled(r) &&
|
2011-03-07 08:02:35 +01:00
|
|
|
|
!is_cursed(u->attribs, C_KAELTESCHUTZ, 0))
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (fval(u, UFL_LONGACTION) && u->thisorder == NULL) {
|
2010-11-12 05:11:19 +01:00
|
|
|
|
/* this message was already given in laws.setdefaults
|
2011-03-07 08:02:35 +01:00
|
|
|
|
cmistake(u, u->thisorder, 52, MSG_PRODUCE);
|
|
|
|
|
*/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
keyword_t kwd = get_keyword(ord);
|
|
|
|
|
if (kwd == K_BUY) {
|
|
|
|
|
buy(u, &buyorders, ord);
|
|
|
|
|
trader = true;
|
|
|
|
|
} else if (kwd == K_SELL) {
|
|
|
|
|
/* sell returns true if the sale is not limited
|
|
|
|
|
* by the region limit */
|
|
|
|
|
limited &= !sell(u, &sellorders, ord);
|
|
|
|
|
trader = true;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (trader) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->attribs, &at_trades);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (a && a->data.i) {
|
|
|
|
|
produceexp(u, SK_TRADE, u->number);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
todo = get_keyword(u->thisorder);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (todo == NOKEYWORD)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (fval(r->terrain, SEA_REGION) && u_race(u) != new_race[RC_AQUARIAN]
|
|
|
|
|
&& !(u_race(u)->flags & RCF_SWIM)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
&& todo != K_STEAL && todo != K_SPY && todo != K_SABOTAGE)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
switch (todo) {
|
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_ENTERTAIN:
|
|
|
|
|
entertain_cmd(u, u->thisorder);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_WORK:
|
|
|
|
|
if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) {
|
|
|
|
|
assert(nextworker - workers < MAX_WORKERS);
|
|
|
|
|
++nextworker;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_TAX:
|
|
|
|
|
tax_cmd(u, u->thisorder, &taxorders);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_STEAL:
|
|
|
|
|
steal_cmd(u, u->thisorder, &stealorders);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_SPY:
|
|
|
|
|
spy_cmd(u, u->thisorder);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_SABOTAGE:
|
|
|
|
|
sabotage_cmd(u, u->thisorder);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_PLANT:
|
|
|
|
|
case K_BREED:
|
|
|
|
|
breed_cmd(u, u->thisorder);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_RESEARCH:
|
|
|
|
|
research_cmd(u, u->thisorder);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Entertainment (expandentertainment) und Besteuerung (expandtax) vor den
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* Befehlen, die den Bauern mehr Geld geben, damit man aus den Zahlen der
|
|
|
|
|
* letzten Runde berechnen kann, wieviel die Bauern f<EFBFBD>r Unterhaltung
|
|
|
|
|
* auszugeben bereit sind. */
|
|
|
|
|
if (entertaining)
|
|
|
|
|
expandentertainment(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!rule_autowork) {
|
|
|
|
|
expandwork(r, workers, nextworker, maxworkingpeasants(r));
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (taxorders)
|
|
|
|
|
expandtax(r, taxorders);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* An erster Stelle Kaufen (expandbuying), die Bauern so Geld bekommen, um
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* nachher zu beim Verkaufen (expandselling) den Spielern abkaufen zu
|
|
|
|
|
* k<EFBFBD>nnen. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (buyorders)
|
|
|
|
|
expandbuying(r, buyorders);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (sellorders) {
|
|
|
|
|
int limit = rpeasants(r) / TRADE_FRACTION;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->terrain == newterrain(T_DESERT)
|
|
|
|
|
&& buildingtype_exists(r, bt_find("caravan"), true))
|
2010-08-08 10:06:34 +02:00
|
|
|
|
limit *= 2;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
expandselling(r, sellorders, limited ? limit : INT_MAX);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Die Spieler sollen alles Geld verdienen, bevor sie beklaut werden
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* (expandstealing). */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (stealorders)
|
|
|
|
|
expandstealing(r, stealorders);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
assert(rmoney(r) >= 0);
|
|
|
|
|
assert(rpeasants(r) >= 0);
|
|
|
|
|
}
|