2016-11-01 17:25:52 +01:00
|
|
|
/*
|
2014-08-08 01:03:46 +02:00
|
|
|
Copyright (c) 1998-2014,
|
|
|
|
Enno Rehling <enno@eressea.de>
|
2014-07-23 08:10:14 +02:00
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
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>
|
|
|
|
#include "laws.h"
|
|
|
|
|
2014-03-22 21:49:18 +01:00
|
|
|
#include <modules/gmcmd.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-09-29 23:19:59 +02:00
|
|
|
#include "alchemy.h"
|
|
|
|
#include "battle.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "economy.h"
|
2014-09-29 23:19:59 +02:00
|
|
|
#include "keyword.h"
|
|
|
|
#include "market.h"
|
2014-12-10 19:04:02 +01:00
|
|
|
#include "morale.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "monster.h"
|
2014-09-29 23:19:59 +02:00
|
|
|
#include "move.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "randenc.h"
|
2016-11-15 23:34:20 +01:00
|
|
|
#include "renumber.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "spy.h"
|
|
|
|
#include "study.h"
|
2014-09-29 23:19:59 +02:00
|
|
|
#include "wormhole.h"
|
2015-09-12 12:24:10 +02:00
|
|
|
#include "prefix.h"
|
2016-09-20 20:27:41 +02:00
|
|
|
#include "reports.h"
|
2016-01-28 12:25:16 +01:00
|
|
|
#include "teleport.h"
|
2015-09-12 12:54:49 +02:00
|
|
|
#include "calendar.h"
|
2015-09-12 22:49:43 +02:00
|
|
|
#include "guard.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
#include <kernel/alliance.h>
|
2012-06-30 20:07:28 +02:00
|
|
|
#include <kernel/ally.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/connection.h>
|
2012-06-03 22:39:42 +02:00
|
|
|
#include <kernel/curse.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/group.h>
|
|
|
|
#include <kernel/item.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/order.h>
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/resources.h>
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
#include <kernel/spell.h>
|
2012-05-24 09:56:54 +02:00
|
|
|
#include <kernel/spellbook.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/terrain.h>
|
2011-03-07 08:02:35 +01:00
|
|
|
#include <kernel/terrainid.h> /* for volcanoes in emigration (needs a flag) */
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
/* attributes includes */
|
|
|
|
#include <attributes/racename.h>
|
|
|
|
#include <attributes/raceprefix.h>
|
2014-11-01 12:09:56 +01:00
|
|
|
#include <attributes/stealth.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/bsdstring.h>
|
|
|
|
#include <util/event.h>
|
|
|
|
#include <util/goodies.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/lists.h>
|
|
|
|
#include <util/log.h>
|
2016-11-11 01:59:43 +01:00
|
|
|
#include <util/message.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/parser.h>
|
2016-01-12 23:52:30 +01:00
|
|
|
#include <util/password.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/rand.h>
|
|
|
|
#include <util/rng.h>
|
|
|
|
#include <util/umlaut.h>
|
2016-11-11 01:59:43 +01:00
|
|
|
#include <util/unicode.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#include <attributes/otherfaction.h>
|
|
|
|
|
2016-11-11 01:59:43 +01:00
|
|
|
#include <quicklist.h>
|
2014-07-26 22:52:25 +02:00
|
|
|
#include <iniparser.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <stdlib.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
/* chance that a peasant dies of starvation: */
|
2015-05-15 19:08:44 +02:00
|
|
|
#define PEASANT_STARVATION_CHANCE 0.9
|
2010-08-08 10:06:34 +02:00
|
|
|
/* Pferdevermehrung */
|
|
|
|
#define HORSEGROWTH 4
|
|
|
|
/* Wanderungschance pro Pferd */
|
|
|
|
#define HORSEMOVE 3
|
|
|
|
/* Vermehrungschance pro Baum */
|
2011-03-07 08:02:35 +01:00
|
|
|
#define FORESTGROWTH 10000 /* In Millionstel */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/** Ausbreitung und Vermehrung */
|
|
|
|
#define MAXDEMAND 25
|
2011-03-07 08:02:35 +01:00
|
|
|
#define DMRISE 0.1F /* weekly chance that demand goes up */
|
|
|
|
#define DMRISEHAFEN 0.2F /* weekly chance that demand goes up with harbor */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* - exported global symbols ----------------------------------- */
|
|
|
|
|
2016-11-16 22:46:01 +01:00
|
|
|
int NewbieImmunity(void)
|
|
|
|
{
|
|
|
|
return config_get_int("NewbieImmunity", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsImmune(const faction * f)
|
|
|
|
{
|
|
|
|
return !fval(f, FFL_NPC) && f->age < NewbieImmunity();
|
|
|
|
}
|
|
|
|
|
|
|
|
int NMRTimeout(void)
|
|
|
|
{
|
|
|
|
return config_get_int("nmr.timeout", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LongHunger(const struct unit *u)
|
|
|
|
{
|
|
|
|
if (u != NULL) {
|
|
|
|
if (!fval(u, UFL_HUNGER))
|
|
|
|
return false;
|
|
|
|
if (u_race(u) == get_race(RC_DAEMON))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return config_get_int("hunger.long", 0) != 0;
|
|
|
|
}
|
|
|
|
|
2015-07-05 14:07:59 +02:00
|
|
|
static bool RemoveNMRNewbie(void)
|
2011-03-07 08:02:35 +01:00
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
int value = config_get_int("nmr.removenewbie", 0);
|
2015-11-22 16:14:27 +01:00
|
|
|
return value != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void age_unit(region * r, unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-10-03 20:36:46 +02:00
|
|
|
static int rc_cache;
|
|
|
|
static const race *rc_spell;
|
|
|
|
|
|
|
|
if (rc_changed(&rc_cache)) {
|
|
|
|
rc_spell = get_race(RC_SPELL);
|
|
|
|
}
|
|
|
|
if (u_race(u) == rc_spell) {
|
2014-07-23 08:10:14 +02:00
|
|
|
if (--u->age <= 0) {
|
|
|
|
remove_unit(&r->units, u);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
else {
|
|
|
|
++u->age;
|
|
|
|
if (u->number > 0 && u_race(u)->age) {
|
|
|
|
u_race(u)->age(u);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (u->region && is_astral(u->region)) {
|
|
|
|
item **itemp = &u->items;
|
|
|
|
while (*itemp) {
|
|
|
|
item *itm = *itemp;
|
|
|
|
if ((itm->type->flags & ITF_NOTLOST) == 0) {
|
|
|
|
if (itm->type->flags & (ITF_BIG | ITF_ANIMAL | ITF_CURSED)) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("itemcrumble",
|
|
|
|
"unit region item amount",
|
|
|
|
u, u->region, itm->type->rtype, itm->number));
|
|
|
|
i_free(i_remove(itemp, itm));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemp = &itm->next;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void live(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit **up = &r->units;
|
|
|
|
|
|
|
|
get_food(r);
|
|
|
|
|
|
|
|
while (*up) {
|
|
|
|
unit *u = *up;
|
|
|
|
/* IUW: age_unit() kann u loeschen, u->next ist dann
|
2015-07-06 19:53:09 +02:00
|
|
|
* undefiniert, also muessen wir hier schon das nächste
|
2014-07-23 08:10:14 +02:00
|
|
|
* Element bestimmen */
|
|
|
|
|
|
|
|
int effect = get_effect(u, oldpotiontype[P_FOOL]);
|
|
|
|
if (effect > 0) { /* Trank "Dumpfbackenbrot" */
|
|
|
|
skill *sv = u->skills, *sb = NULL;
|
|
|
|
while (sv != u->skills + u->skill_size) {
|
|
|
|
if (sb == NULL || skill_compare(sv, sb) > 0) {
|
|
|
|
sb = sv;
|
|
|
|
}
|
|
|
|
++sv;
|
|
|
|
}
|
|
|
|
/* bestes Talent raussuchen */
|
|
|
|
if (sb != NULL) {
|
|
|
|
int weeks = _min(effect, u->number);
|
|
|
|
reduce_skill(u, sb, weeks);
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("dumbeffect",
|
|
|
|
"unit weeks skill", u, weeks, (skill_t)sb->id));
|
2015-08-02 21:37:12 +02:00
|
|
|
} /* sonst Glück gehabt: wer nix weiss, kann nix vergessen... */
|
2014-07-23 08:10:14 +02:00
|
|
|
change_effect(u, oldpotiontype[P_FOOL], -effect);
|
|
|
|
}
|
|
|
|
age_unit(r, u);
|
|
|
|
if (*up == u)
|
|
|
|
up = &u->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This procedure calculates the number of emigrating peasants for the given
|
|
|
|
* region r. There are two incentives for peasants to emigrate:
|
|
|
|
* 1) They prefer the less crowded areas.
|
|
|
|
* Example: mountains, 700 peasants (max 1000), 70% inhabited
|
|
|
|
* plain, 5000 peasants (max 10000), 50% inhabited
|
|
|
|
* 700*(PEASANTSWANDER_WEIGHT/100)*((70-50)/100) peasants wander
|
|
|
|
* from mountains to plain.
|
|
|
|
* Effect : peasents will leave densely populated regions.
|
|
|
|
* 2) Peasants prefer richer neighbour regions.
|
|
|
|
* Example: region A, 700 peasants, wealth $10500, $15 per head
|
|
|
|
* region B, 2500 peasants, wealth $25000, $10 per head
|
|
|
|
* Some peasants will emigrate from B to A because $15 > $10
|
|
|
|
* exactly: 2500*(PEASANTSGREED_WEIGHT1/100)*((15-10)/100)
|
|
|
|
* Not taken in consideration:
|
|
|
|
* - movement because of monsters.
|
|
|
|
* - movement because of wars
|
|
|
|
* - movement because of low loyalty relating to present parties.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_EMIGRATION(p) ((p)/MAXDIRECTIONS)
|
|
|
|
#define MAX_IMMIGRATION(p) ((p)*2/3)
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void calculate_emigration(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int i;
|
2016-11-15 20:43:36 +01:00
|
|
|
int maxp = region_maxworkers(r);
|
2014-07-23 08:10:14 +02:00
|
|
|
int rp = rpeasants(r);
|
|
|
|
int max_immigrants = MAX_IMMIGRATION(maxp - rp);
|
|
|
|
|
|
|
|
if (r->terrain == newterrain(T_VOLCANO)
|
|
|
|
|| r->terrain == newterrain(T_VOLCANO_SMOKING)) {
|
|
|
|
max_immigrants = max_immigrants / 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; max_immigrants > 0 && i != MAXDIRECTIONS; i++) {
|
2015-02-01 19:14:06 +01:00
|
|
|
int dir = (turn + 1 + i) % MAXDIRECTIONS;
|
2014-07-23 08:10:14 +02:00
|
|
|
region *rc = rconnect(r, (direction_t)dir);
|
|
|
|
|
|
|
|
if (rc != NULL && fval(rc->terrain, LAND_REGION)) {
|
|
|
|
int rp2 = rpeasants(rc);
|
2016-11-15 20:43:36 +01:00
|
|
|
int maxp2 = region_maxworkers(rc);
|
2014-07-23 08:10:14 +02:00
|
|
|
int max_emigration = MAX_EMIGRATION(rp2 - maxp2);
|
|
|
|
|
|
|
|
if (max_emigration > 0) {
|
|
|
|
max_emigration = _min(max_emigration, max_immigrants);
|
|
|
|
r->land->newpeasants += max_emigration;
|
|
|
|
rc->land->newpeasants -= max_emigration;
|
|
|
|
max_immigrants -= max_emigration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-01-15 13:13:41 +01:00
|
|
|
|
2015-05-15 19:08:44 +02:00
|
|
|
static double peasant_growth_factor(void)
|
2015-01-30 17:40:04 +01:00
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
return config_get_flt("rules.peasants.growth.factor", 0.0001F * PEASANTGROWTH);
|
2015-01-29 23:50:45 +01:00
|
|
|
}
|
|
|
|
|
2015-01-30 22:11:33 +01:00
|
|
|
#ifdef SLOWLUCK
|
2015-02-01 19:14:06 +01:00
|
|
|
int peasant_luck_effect(int peasants, int luck, int maxp, double variance) {
|
2015-11-22 16:14:27 +01:00
|
|
|
int n, births = 0;
|
2015-05-15 19:08:44 +02:00
|
|
|
double factor = peasant_growth_factor();
|
2015-01-30 22:11:33 +01:00
|
|
|
for (n = peasants; n && luck; --n) {
|
|
|
|
int chances = 0;
|
|
|
|
|
|
|
|
if (luck > 0) {
|
|
|
|
--luck;
|
|
|
|
chances += PEASANTLUCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (chances--) {
|
|
|
|
if (rng_double() < factor) {
|
|
|
|
/* Only raise with 75% chance if peasants have
|
|
|
|
* reached 90% of maxpopulation */
|
|
|
|
if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) {
|
|
|
|
++births;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return births;
|
|
|
|
}
|
|
|
|
#else
|
2015-05-15 19:08:44 +02:00
|
|
|
static double peasant_luck_factor(void)
|
2015-01-30 17:40:04 +01:00
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
return config_get_flt("rules.peasants.peasantluck.factor", PEASANTLUCK);
|
2015-01-15 13:13:41 +01:00
|
|
|
}
|
|
|
|
|
2015-02-01 19:14:06 +01:00
|
|
|
int peasant_luck_effect(int peasants, int luck, int maxp, double variance)
|
2015-01-30 17:40:04 +01:00
|
|
|
{
|
2015-01-30 22:11:33 +01:00
|
|
|
int births = 0;
|
2015-02-01 19:14:06 +01:00
|
|
|
double mean;
|
|
|
|
if (luck == 0) return 0;
|
|
|
|
|
2015-05-15 19:08:44 +02:00
|
|
|
mean = peasant_luck_factor() * peasant_growth_factor() * _min(luck, peasants);
|
|
|
|
mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE);
|
2015-01-30 22:11:33 +01:00
|
|
|
|
|
|
|
births = RAND_ROUND(normalvariate(mean, variance * mean));
|
|
|
|
if (births <= 0)
|
|
|
|
births = 1;
|
|
|
|
if (births > peasants / 2)
|
|
|
|
births = peasants / 2 + 1;
|
|
|
|
return births;
|
2015-01-14 22:33:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 02:52:26 +01:00
|
|
|
#endif
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void peasants(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int peasants = rpeasants(r);
|
|
|
|
int money = rmoney(r);
|
2014-09-18 12:10:42 +02:00
|
|
|
int maxp = production(r);
|
2014-07-23 08:10:14 +02:00
|
|
|
int n, satiated;
|
|
|
|
int dead = 0;
|
|
|
|
|
2015-11-22 10:44:46 +01:00
|
|
|
if (peasants > 0 && config_get_int("rules.peasants.growth", 1)) {
|
2015-01-14 22:33:58 +01:00
|
|
|
int luck = 0;
|
2015-01-15 13:13:41 +01:00
|
|
|
double fraction = peasants * peasant_growth_factor();
|
2015-01-14 22:33:58 +01:00
|
|
|
int births = RAND_ROUND(fraction);
|
2014-07-23 08:10:14 +02:00
|
|
|
attrib *a = a_find(r->attribs, &at_peasantluck);
|
|
|
|
|
|
|
|
if (a != NULL) {
|
2015-01-14 22:33:58 +01:00
|
|
|
luck = a->data.i * 1000;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 17:40:04 +01:00
|
|
|
luck = peasant_luck_effect(peasants, luck, maxp, .5);
|
2015-02-01 19:14:06 +01:00
|
|
|
if (luck > 0)
|
|
|
|
ADDMSG(&r->msgs, msg_message("peasantluck_success", "births", luck));
|
2015-01-15 03:45:07 +01:00
|
|
|
peasants += births + luck;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Alle werden satt, oder halt soviele für die es auch Geld gibt */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
satiated = _min(peasants, money / maintenance_cost(NULL));
|
|
|
|
rsetmoney(r, money - satiated * maintenance_cost(NULL));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Von denjenigen, die nicht satt geworden sind, verhungert der
|
2015-07-06 19:53:09 +02:00
|
|
|
* Großteil. dead kann nie größer als rpeasants(r) - satiated werden,
|
|
|
|
* so dass rpeasants(r) >= 0 bleiben muß. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-22 16:14:27 +01:00
|
|
|
/* Es verhungert maximal die unterernährten Bevölkerung. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
n = _min(peasants - satiated, rpeasants(r));
|
2015-05-15 19:08:44 +02:00
|
|
|
dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (dead > 0) {
|
|
|
|
message *msg = add_message(&r->msgs, msg_message("phunger", "dead", dead));
|
|
|
|
msg_release(msg);
|
|
|
|
peasants -= dead;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
rsetpeasants(r, peasants);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
typedef struct migration {
|
2014-07-23 08:10:14 +02:00
|
|
|
struct migration *next;
|
|
|
|
region *r;
|
|
|
|
int horses;
|
|
|
|
int trees;
|
2010-08-08 10:06:34 +02:00
|
|
|
} migration;
|
|
|
|
|
|
|
|
#define MSIZE 1023
|
2011-03-07 08:02:35 +01:00
|
|
|
migration *migrants[MSIZE];
|
|
|
|
migration *free_migrants;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static migration *get_migrants(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int key = reg_hashkey(r);
|
|
|
|
int index = key % MSIZE;
|
|
|
|
migration *m = migrants[index];
|
|
|
|
while (m && m->r != r)
|
|
|
|
m = m->next;
|
|
|
|
if (m == NULL) {
|
|
|
|
/* Es gibt noch keine Migration. Also eine erzeugen
|
|
|
|
*/
|
|
|
|
m = free_migrants;
|
|
|
|
if (!m)
|
|
|
|
m = calloc(1, sizeof(migration));
|
|
|
|
else {
|
|
|
|
free_migrants = free_migrants->next;
|
|
|
|
m->horses = 0;
|
|
|
|
m->trees = 0;
|
|
|
|
}
|
|
|
|
m->r = r;
|
|
|
|
m->next = migrants[index];
|
|
|
|
migrants[index] = m;
|
|
|
|
}
|
|
|
|
return m;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void migrate(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int key = reg_hashkey(r);
|
|
|
|
int index = key % MSIZE;
|
|
|
|
migration **hp = &migrants[index];
|
|
|
|
fset(r, RF_MIGRATION);
|
|
|
|
while (*hp && (*hp)->r != r)
|
|
|
|
hp = &(*hp)->next;
|
|
|
|
if (*hp) {
|
|
|
|
migration *m = *hp;
|
|
|
|
rsethorses(r, rhorses(r) + m->horses);
|
|
|
|
/* Was macht das denn hier?
|
|
|
|
* Baumwanderung wird in trees() gemacht.
|
2015-07-06 19:53:09 +02:00
|
|
|
* wer fragt das? Die Baumwanderung war abhängig von der
|
2014-07-23 08:10:14 +02:00
|
|
|
* Auswertungsreihenfolge der regionen,
|
2015-07-06 19:53:09 +02:00
|
|
|
* das hatte ich geändert. jemand hat es wieder gelöscht, toll.
|
2015-08-02 21:37:12 +02:00
|
|
|
* ich habe es wieder aktiviert, muss getestet werden.
|
2014-07-23 08:10:14 +02:00
|
|
|
*/
|
|
|
|
*hp = m->next;
|
|
|
|
m->next = free_migrants;
|
|
|
|
free_migrants = m;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void horses(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int horses, maxhorses;
|
|
|
|
direction_t n;
|
|
|
|
|
|
|
|
/* Logistisches Wachstum, Optimum bei halbem Maximalbesatz. */
|
2016-11-15 20:43:36 +01:00
|
|
|
maxhorses = region_maxworkers(r) / 10;
|
2014-07-23 08:10:14 +02:00
|
|
|
maxhorses = _max(0, maxhorses);
|
|
|
|
horses = rhorses(r);
|
|
|
|
if (horses > 0) {
|
|
|
|
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
|
2015-05-15 19:08:44 +02:00
|
|
|
rsethorses(r, (int)(horses * 0.9));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else if (maxhorses) {
|
|
|
|
int i;
|
|
|
|
double growth =
|
|
|
|
(RESOURCE_QUANTITY * HORSEGROWTH * 200 * (maxhorses -
|
2015-11-22 16:14:27 +01:00
|
|
|
horses)) / maxhorses;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (growth > 0) {
|
|
|
|
if (a_find(r->attribs, &at_horseluck))
|
|
|
|
growth *= 2;
|
|
|
|
/* printf("Horses: <%d> %d -> ", growth, horses); */
|
2015-05-15 19:08:44 +02:00
|
|
|
i = (int)(0.5 + (horses * 0.0001) * growth);
|
2014-07-23 08:10:14 +02:00
|
|
|
/* printf("%d\n", horses); */
|
|
|
|
rsethorses(r, horses + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pferde wandern in Nachbarregionen.
|
|
|
|
* Falls die Nachbarregion noch berechnet
|
2015-08-02 21:37:12 +02:00
|
|
|
* werden muss, wird eine migration-Struktur gebildet,
|
2015-07-06 19:53:09 +02:00
|
|
|
* die dann erst in die Berechnung der Nachbarstruktur einfließt.
|
2014-07-23 08:10:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
for (n = 0; n != MAXDIRECTIONS; n++) {
|
|
|
|
region *r2 = rconnect(r, n);
|
|
|
|
if (r2 && fval(r2->terrain, WALK_INTO)) {
|
|
|
|
int pt = (rhorses(r) * HORSEMOVE) / 100;
|
|
|
|
pt = (int)normalvariate(pt, pt / 4.0);
|
|
|
|
pt = _max(0, pt);
|
|
|
|
if (fval(r2, RF_MIGRATION))
|
|
|
|
rsethorses(r2, rhorses(r2) + pt);
|
|
|
|
else {
|
|
|
|
migration *nb;
|
|
|
|
/* haben wir die Migration schonmal benutzt?
|
2015-07-06 19:53:09 +02:00
|
|
|
* wenn nicht, müssen wir sie suchen.
|
2014-07-23 08:10:14 +02:00
|
|
|
* Wandernde Pferde vermehren sich nicht.
|
|
|
|
*/
|
|
|
|
nb = get_migrants(r2);
|
|
|
|
nb->horses += pt;
|
|
|
|
}
|
|
|
|
/* Wandernde Pferde sollten auch abgezogen werden */
|
|
|
|
rsethorses(r, rhorses(r) - pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(rhorses(r) >= 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int count_race(const region * r, const race * rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u;
|
|
|
|
int c = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u = r->units; u; u = u->next)
|
|
|
|
if (u_race(u) == rc)
|
|
|
|
c += u->number;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return c;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-11-24 19:32:52 +01:00
|
|
|
attrib_type at_germs = {
|
|
|
|
"germs",
|
|
|
|
DEFAULT_INIT,
|
|
|
|
DEFAULT_FINALIZE,
|
|
|
|
DEFAULT_AGE,
|
|
|
|
a_writeshorts,
|
|
|
|
a_readshorts,
|
2016-02-09 06:43:19 +01:00
|
|
|
NULL,
|
2015-11-24 19:32:52 +01:00
|
|
|
ATF_UNIQUE
|
|
|
|
};
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
static void
|
2011-03-07 08:02:35 +01:00
|
|
|
growing_trees_e3(region * r, const int current_season,
|
2015-11-22 16:14:27 +01:00
|
|
|
const int last_weeks_season)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
static const int transform[4][3] = {
|
2015-01-30 20:37:14 +01:00
|
|
|
{ -1, -1, 0 },
|
|
|
|
{ TREE_SEED, TREE_SAPLING, 2 },
|
|
|
|
{ TREE_SAPLING, TREE_TREE, 2 },
|
|
|
|
{ TREE_TREE, TREE_SEED, 2 }
|
2014-07-23 08:10:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (r->land && current_season != last_weeks_season
|
|
|
|
&& transform[current_season][2]) {
|
|
|
|
int src_type = transform[current_season][0];
|
|
|
|
int dst_type = transform[current_season][1];
|
|
|
|
int src = rtrees(r, src_type);
|
|
|
|
int dst = rtrees(r, dst_type);
|
|
|
|
int grow = src / transform[current_season][2];
|
|
|
|
if (grow > 0) {
|
|
|
|
if (src_type != TREE_TREE) {
|
|
|
|
rsettrees(r, src_type, src - grow);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
rsettrees(r, dst_type, dst + grow);
|
|
|
|
|
|
|
|
if (dst_type == TREE_SEED && r->terrain->size) {
|
|
|
|
region *rn[MAXDIRECTIONS];
|
|
|
|
int d;
|
|
|
|
double fgrow = grow / (double)MAXDIRECTIONS;
|
|
|
|
|
|
|
|
get_neighbours(r, rn);
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
|
|
|
region *rx = rn[d];
|
|
|
|
if (rx && rx->land) {
|
|
|
|
double scale = 1.0;
|
|
|
|
int g;
|
|
|
|
double fg, ch;
|
|
|
|
int seeds = rtrees(rx, dst_type);
|
|
|
|
|
|
|
|
if (r->terrain->size > rx->terrain->size) {
|
|
|
|
scale = (scale * rx->terrain->size) / r->terrain->size;
|
|
|
|
}
|
|
|
|
fg = scale * fgrow;
|
|
|
|
g = (int)fg;
|
|
|
|
ch = fg - g;
|
|
|
|
if (chance(ch))
|
|
|
|
++g;
|
|
|
|
if (g > 0) {
|
|
|
|
rsettrees(rx, dst_type, seeds + g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
growing_trees(region * r, const int current_season, const int last_weeks_season)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int growth, grownup_trees, i, seeds, sprout;
|
|
|
|
direction_t d;
|
|
|
|
attrib *a;
|
|
|
|
|
|
|
|
if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) {
|
|
|
|
double seedchance = 0.01F * RESOURCE_QUANTITY;
|
|
|
|
int elves = count_race(r, get_race(RC_ELF));
|
|
|
|
|
|
|
|
a = a_find(r->attribs, &at_germs);
|
|
|
|
if (a && last_weeks_season == SEASON_SPRING) {
|
2015-07-06 19:53:09 +02:00
|
|
|
/* ungekeimte Samen bleiben erhalten, Sprößlinge wachsen */
|
2014-07-23 08:10:14 +02:00
|
|
|
sprout = _min(a->data.sa[1], rtrees(r, 1));
|
2015-07-06 19:53:09 +02:00
|
|
|
/* aus dem gesamt Sprößlingepool abziehen */
|
2014-07-23 08:10:14 +02:00
|
|
|
rsettrees(r, 1, rtrees(r, 1) - sprout);
|
2015-07-06 19:53:09 +02:00
|
|
|
/* zu den Bäumen hinzufügen */
|
2014-07-23 08:10:14 +02:00
|
|
|
rsettrees(r, 2, rtrees(r, 2) + sprout);
|
|
|
|
|
|
|
|
a_removeall(&r->attribs, &at_germs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
|
|
|
|
rsettrees(r, 1, (int)(rtrees(r, 1) * 0.9));
|
|
|
|
rsettrees(r, 2, (int)(rtrees(r, 2) * 0.9));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (production(r) <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Grundchance 1.0% */
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Jeder Elf in der Region erhöht die Chance marginal */
|
2014-09-18 12:10:42 +02:00
|
|
|
elves = _min(elves, production(r) / 8);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (elves) {
|
|
|
|
seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY);
|
|
|
|
}
|
|
|
|
grownup_trees = rtrees(r, 2);
|
|
|
|
seeds = 0;
|
|
|
|
|
|
|
|
if (grownup_trees > 0) {
|
|
|
|
double remainder = seedchance * grownup_trees;
|
|
|
|
seeds = (int)(remainder);
|
|
|
|
remainder -= seeds;
|
|
|
|
if (chance(remainder)) {
|
|
|
|
++seeds;
|
|
|
|
}
|
|
|
|
if (seeds > 0) {
|
|
|
|
seeds += rtrees(r, 0);
|
|
|
|
rsettrees(r, 0, seeds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Bäume breiten sich in Nachbarregionen aus. */
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
/* Gesamtzahl der Samen:
|
2015-07-06 19:53:09 +02:00
|
|
|
* bis zu 6% (FORESTGROWTH*3) der Bäume samen in die Nachbarregionen */
|
2014-07-23 08:10:14 +02:00
|
|
|
seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000;
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
|
|
|
region *r2 = rconnect(r, d);
|
|
|
|
if (r2 && fval(r2->terrain, LAND_REGION) && r2->terrain->size) {
|
|
|
|
/* Eine Landregion, wir versuchen Samen zu verteilen:
|
2015-07-06 19:53:09 +02:00
|
|
|
* Die Chance, das Samen ein Stück Boden finden, in dem sie
|
|
|
|
* keimen können, hängt von der Bewuchsdichte und der
|
|
|
|
* verfügbaren Fläche ab. In Gletschern gibt es weniger
|
|
|
|
* Möglichkeiten als in Ebenen. */
|
2014-07-23 08:10:14 +02:00
|
|
|
sprout = 0;
|
2016-11-23 18:56:40 +01:00
|
|
|
seedchance = (1000.0 * region_maxworkers(r2)) / r2->terrain->size;
|
2014-07-23 08:10:14 +02:00
|
|
|
for (i = 0; i < seeds / MAXDIRECTIONS; i++) {
|
|
|
|
if (rng_int() % 10000 < seedchance)
|
|
|
|
sprout++;
|
|
|
|
}
|
|
|
|
rsettrees(r2, 0, rtrees(r2, 0) + sprout);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
else if (current_season == SEASON_SPRING) {
|
|
|
|
|
|
|
|
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0))
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* in at_germs merken uns die Zahl der Samen und Sprößlinge, die
|
|
|
|
* dieses Jahr älter werden dürfen, damit nicht ein Same im selben
|
2014-07-23 08:10:14 +02:00
|
|
|
* Zyklus zum Baum werden kann */
|
|
|
|
a = a_find(r->attribs, &at_germs);
|
|
|
|
if (!a) {
|
|
|
|
a = a_add(&r->attribs, a_new(&at_germs));
|
|
|
|
a->data.sa[0] = (short)rtrees(r, 0);
|
|
|
|
a->data.sa[1] = (short)rtrees(r, 1);
|
|
|
|
}
|
2015-08-02 21:37:12 +02:00
|
|
|
/* wir haben 6 Wochen zum wachsen, jeder Same/Spross hat 18% Chance
|
2014-07-23 08:10:14 +02:00
|
|
|
* zu wachsen, damit sollten nach 5-6 Wochen alle gewachsen sein */
|
|
|
|
growth = 1800;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Samenwachstum */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Raubbau abfangen, es dürfen nie mehr Samen wachsen, als aktuell
|
2014-07-23 08:10:14 +02:00
|
|
|
* in der Region sind */
|
|
|
|
seeds = _min(a->data.sa[0], rtrees(r, 0));
|
|
|
|
sprout = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < seeds; i++) {
|
|
|
|
if (rng_int() % 10000 < growth)
|
|
|
|
sprout++;
|
|
|
|
}
|
|
|
|
/* aus dem Samenpool dieses Jahres abziehen */
|
|
|
|
a->data.sa[0] = (short)(seeds - sprout);
|
|
|
|
/* aus dem gesamt Samenpool abziehen */
|
|
|
|
rsettrees(r, 0, rtrees(r, 0) - sprout);
|
2015-07-06 19:53:09 +02:00
|
|
|
/* zu den Sprößlinge hinzufügen */
|
2014-07-23 08:10:14 +02:00
|
|
|
rsettrees(r, 1, rtrees(r, 1) + sprout);
|
|
|
|
|
|
|
|
/* Baumwachstum */
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* hier gehen wir davon aus, das Jungbäume nicht ohne weiteres aus
|
|
|
|
* der Region entfernt werden können, da Jungbäume in der gleichen
|
|
|
|
* Runde nachwachsen, wir also nicht mehr zwischen diesjährigen und
|
|
|
|
* 'alten' Jungbäumen unterscheiden könnten */
|
2014-07-23 08:10:14 +02:00
|
|
|
sprout = _min(a->data.sa[1], rtrees(r, 1));
|
|
|
|
grownup_trees = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sprout; i++) {
|
|
|
|
if (rng_int() % 10000 < growth)
|
|
|
|
grownup_trees++;
|
|
|
|
}
|
2015-07-06 19:53:09 +02:00
|
|
|
/* aus dem Sprößlingepool dieses Jahres abziehen */
|
2014-07-23 08:10:14 +02:00
|
|
|
a->data.sa[1] = (short)(sprout - grownup_trees);
|
2015-07-06 19:53:09 +02:00
|
|
|
/* aus dem gesamt Sprößlingepool abziehen */
|
2014-07-23 08:10:14 +02:00
|
|
|
rsettrees(r, 1, rtrees(r, 1) - grownup_trees);
|
2015-07-06 19:53:09 +02:00
|
|
|
/* zu den Bäumen hinzufügen */
|
2014-07-23 08:10:14 +02:00
|
|
|
rsettrees(r, 2, rtrees(r, 2) + grownup_trees);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
growing_herbs(region * r, const int current_season, const int last_weeks_season)
|
|
|
|
{
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Jetzt die Kräutervermehrung. Vermehrt wird logistisch:
|
2014-07-23 08:10:14 +02:00
|
|
|
*
|
|
|
|
* Jedes Kraut hat eine Wahrscheinlichkeit von (100-(vorhandene
|
2015-07-06 19:53:09 +02:00
|
|
|
* Kräuter))% sich zu vermehren. */
|
2014-07-23 08:10:14 +02:00
|
|
|
if (current_season != SEASON_WINTER) {
|
|
|
|
int i;
|
|
|
|
for (i = rherbs(r); i > 0; i--) {
|
|
|
|
if (rng_int() % 100 < (100 - rherbs(r)))
|
|
|
|
rsetherbs(r, (short)(rherbs(r) + 1));
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 09:48:43 +01:00
|
|
|
void immigration(void)
|
|
|
|
{
|
|
|
|
region *r;
|
|
|
|
log_info(" - Einwanderung...");
|
2015-11-22 10:44:46 +01:00
|
|
|
int repopulate = config_get_int("rules.economy.repopulate_maximum", 90);
|
2014-12-15 09:48:43 +01:00
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
if (r->land && r->land->newpeasants) {
|
|
|
|
int rp = rpeasants(r) + r->land->newpeasants;
|
|
|
|
rsetpeasants(r, _max(0, rp));
|
|
|
|
}
|
2015-12-07 19:41:47 +01:00
|
|
|
/* Genereate some (0-6 depending on the income) peasants out of nothing */
|
|
|
|
/* if less than 50 are in the region and there is space and no monster or demon units in the region */
|
2016-01-31 22:10:37 +01:00
|
|
|
if (repopulate) {
|
|
|
|
int peasants = rpeasants(r);
|
2016-01-31 22:17:55 +01:00
|
|
|
int income = wage(r, NULL, NULL, turn) - maintenance_cost(NULL) + 1;
|
2016-11-15 20:43:36 +01:00
|
|
|
if (income >= 0 && r->land && (peasants < repopulate) && region_maxworkers(r) >(peasants + 30) * 2) {
|
2016-01-31 22:10:37 +01:00
|
|
|
int badunit = 0;
|
|
|
|
unit *u;
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
if (!playerrace(u_race(u)) || u_race(u) == get_race(RC_DAEMON)) {
|
|
|
|
badunit = 1;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-15 09:48:43 +01:00
|
|
|
}
|
2016-01-31 22:10:37 +01:00
|
|
|
if (badunit == 0) {
|
2016-01-31 22:12:08 +01:00
|
|
|
peasants += (int)(rng_double()*income);
|
2016-01-30 23:04:41 +01:00
|
|
|
rsetpeasants(r, peasants);
|
|
|
|
}
|
2014-12-15 09:48:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-15 20:25:36 +02:00
|
|
|
void nmr_warnings(void)
|
2015-07-03 15:31:57 +02:00
|
|
|
{
|
|
|
|
faction *f, *fa;
|
|
|
|
#define FRIEND (HELP_GUARD|HELP_MONEY)
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
|
|
|
|
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
|
|
|
|
if (turn - f->lastorders == NMRTimeout() - 1) {
|
|
|
|
ADDMSG(&f->msgs, msg_message("nmr_warning_final", ""));
|
|
|
|
}
|
|
|
|
if ((turn - f->lastorders) >= 2) {
|
|
|
|
message *msg = NULL;
|
|
|
|
for (fa = factions; fa; fa = fa->next) {
|
|
|
|
int warn = 0;
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("rules.alliances", 0) != 0) {
|
2015-07-03 15:31:57 +02:00
|
|
|
if (f->alliance && f->alliance == fa->alliance) {
|
|
|
|
warn = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (alliedfaction(NULL, f, fa, FRIEND)
|
|
|
|
&& alliedfaction(NULL, fa, f, FRIEND)) {
|
|
|
|
warn = 1;
|
|
|
|
}
|
|
|
|
if (warn) {
|
|
|
|
if (msg == NULL) {
|
|
|
|
msg =
|
|
|
|
msg_message("warn_dropout", "faction turns", f,
|
2015-11-22 16:14:27 +01:00
|
|
|
turn - f->lastorders);
|
2015-07-03 15:31:57 +02:00
|
|
|
}
|
|
|
|
add_message(&fa->msgs, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg != NULL)
|
|
|
|
msg_release(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void demographics(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r;
|
|
|
|
static int last_weeks_season = -1;
|
|
|
|
static int current_season = -1;
|
2016-09-11 12:48:00 +02:00
|
|
|
int plant_rules = config_get_int("rules.grow.formula", 2);
|
|
|
|
const struct building_type *bt_harbour = bt_find("harbour");
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (current_season < 0) {
|
|
|
|
gamedate date;
|
|
|
|
get_gamedate(turn, &date);
|
|
|
|
current_season = date.season;
|
|
|
|
get_gamedate(turn - 1, &date);
|
|
|
|
last_weeks_season = date.season;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
2015-12-22 19:33:44 +01:00
|
|
|
++r->age; /* also oceans. no idea why we didn't always do that */
|
2014-07-23 08:10:14 +02:00
|
|
|
live(r);
|
|
|
|
|
|
|
|
if (!fval(r->terrain, SEA_REGION)) {
|
|
|
|
/* die Nachfrage nach Produkten steigt. */
|
|
|
|
struct demand *dmd;
|
|
|
|
if (r->land) {
|
|
|
|
for (dmd = r->land->demands; dmd; dmd = dmd->next) {
|
|
|
|
if (dmd->value > 0 && dmd->value < MAXDEMAND) {
|
|
|
|
float rise = DMRISE;
|
2016-09-11 12:48:00 +02:00
|
|
|
if (buildingtype_exists(r, bt_harbour, true))
|
2014-07-23 08:10:14 +02:00
|
|
|
rise = DMRISEHAFEN;
|
|
|
|
if (rng_double() < rise)
|
|
|
|
++dmd->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Seuchen erst nachdem die Bauern sich vermehrt haben
|
|
|
|
* und gewandert sind */
|
|
|
|
|
|
|
|
calculate_emigration(r);
|
|
|
|
peasants(r);
|
|
|
|
if (r->age > 20) {
|
2016-11-15 20:43:36 +01:00
|
|
|
double mwp = _max(region_maxworkers(r), 1);
|
2014-12-16 14:18:29 +01:00
|
|
|
double prob =
|
|
|
|
pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0)
|
|
|
|
* PLAGUE_CHANCE;
|
|
|
|
|
|
|
|
if (rng_double() < prob) {
|
|
|
|
plagues(r);
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
horses(r);
|
2015-12-22 19:33:44 +01:00
|
|
|
if (plant_rules == 2) { /* E2 */
|
2014-07-23 08:10:14 +02:00
|
|
|
growing_trees(r, current_season, last_weeks_season);
|
|
|
|
growing_herbs(r, current_season, last_weeks_season);
|
|
|
|
}
|
2015-12-22 19:33:44 +01:00
|
|
|
else if (plant_rules==1) { /* E3 */
|
2014-07-23 08:10:14 +02:00
|
|
|
growing_trees_e3(r, current_season, last_weeks_season);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update_resources(r);
|
|
|
|
if (r->land)
|
|
|
|
migrate(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (free_migrants) {
|
|
|
|
migration *m = free_migrants->next;
|
|
|
|
free(free_migrants);
|
|
|
|
free_migrants = m;
|
|
|
|
};
|
|
|
|
|
|
|
|
remove_empty_units();
|
2014-12-15 09:48:43 +01:00
|
|
|
immigration();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2012-06-14 08:25:20 +02:00
|
|
|
/* test if the unit can slip through a siege undetected.
|
|
|
|
* returns 0 if siege is successful, or 1 if the building is either
|
|
|
|
* not besieged or the unit can slip through the siege due to better stealth.
|
|
|
|
*/
|
|
|
|
static int slipthru(const region * r, const unit * u, const building * b)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u2;
|
|
|
|
int n, o;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* b ist die burg, in die man hinein oder aus der man heraus will. */
|
|
|
|
if (b == NULL || b->besieged < b->size * SIEGEFACTOR) {
|
|
|
|
return 1;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* u wird am hinein- oder herausschluepfen gehindert, wenn STEALTH <=
|
|
|
|
* OBSERVATION +2 der belagerer u2 ist */
|
2015-08-27 16:16:55 +02:00
|
|
|
n = effskill(u, SK_STEALTH, r);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
if (usiege(u2) == b) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (invisible(u, u2) >= u->number)
|
|
|
|
continue;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2015-08-27 16:16:55 +02:00
|
|
|
o = effskill(u2, SK_PERCEPTION, r);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (o + 2 >= n) {
|
|
|
|
return 0; /* entdeckt! */
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return 1;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int can_contact(const region * r, const unit * u, const unit * u2) {
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* hier geht es nur um die belagerung von burgen */
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (u->building == u2->building) {
|
|
|
|
return 1;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* unit u is trying to contact u2 - unasked for contact. wenn u oder u2
|
|
|
|
* nicht in einer burg ist, oder die burg nicht belagert ist, ist
|
|
|
|
* slipthru () == 1. ansonsten ist es nur 1, wenn man die belagerer */
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (slipthru(u->region, u, u->building) && slipthru(u->region, u2, u2->building)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return (alliedunit(u, u2->faction, HELP_GIVE));
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
int contact_cmd(unit * u, order * ord)
|
2012-06-14 08:25:20 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u2;
|
2014-12-10 19:04:02 +01:00
|
|
|
int n;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-10 19:04:02 +01:00
|
|
|
n = read_unitid(u->faction, u->region);
|
|
|
|
u2 = findunit(n);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (u2 != NULL) {
|
2014-12-10 19:04:02 +01:00
|
|
|
if (!can_contact(u->region, u, u2)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, u->thisorder, 23, MSG_EVENT);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
usetcontact(u, u2);
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int leave_cmd(unit * u, struct order *ord)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r = u->region;
|
|
|
|
|
|
|
|
if (fval(u, UFL_ENTER)) {
|
|
|
|
/* if we just entered this round, then we don't leave again */
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (fval(r->terrain, SEA_REGION) && u->ship) {
|
|
|
|
if (!fval(u_race(u), RCF_SWIM)) {
|
|
|
|
cmistake(u, ord, 11, MSG_MOVE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (has_horses(u)) {
|
|
|
|
cmistake(u, ord, 231, MSG_MOVE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!slipthru(r, u, u->building)) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "entrance_besieged",
|
|
|
|
"building", u->building));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
leave(u, true);
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int quit_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 14:30:04 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
faction *f = u->faction;
|
|
|
|
const char *passwd;
|
2014-08-23 09:17:58 +02:00
|
|
|
keyword_t kwd;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
kwd = init_order(ord);
|
2014-11-01 21:57:06 +01:00
|
|
|
assert(kwd == K_QUIT);
|
2014-12-22 16:28:17 +01:00
|
|
|
passwd = gettoken(token, sizeof(token));
|
2014-12-22 14:30:04 +01:00
|
|
|
if (checkpasswd(f, (const char *)passwd)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
fset(f, FFL_QUIT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char buffer[64];
|
|
|
|
write_order(ord, buffer, sizeof(buffer));
|
|
|
|
cmistake(u, ord, 86, MSG_EVENT);
|
2016-11-17 21:29:15 +01:00
|
|
|
log_warning("QUIT with illegal password for faction %s: %s\n", itoa36(f->no), buffer);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
static bool mayenter(region * r, unit * u, building * b)
|
2012-06-14 08:25:20 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u2;
|
|
|
|
if (fval(b, BLD_UNGUARDED))
|
|
|
|
return true;
|
|
|
|
u2 = building_owner(b);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (u2 == NULL || ucontact(u2, u)
|
|
|
|
|| alliedunit(u2, u->faction, HELP_GUARD))
|
|
|
|
return true;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return false;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mayboard(const unit * u, ship * sh)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u2 = ship_owner(sh);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return (!u2 || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD));
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
static bool CheckOverload(void)
|
2012-06-14 08:25:20 +02:00
|
|
|
{
|
2015-11-22 16:14:27 +01:00
|
|
|
return config_get_int("rules.check_overload", 0) != 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2014-11-21 17:13:45 +01:00
|
|
|
int enter_ship(unit * u, struct order *ord, int id, bool report)
|
2012-06-14 08:25:20 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r = u->region;
|
|
|
|
ship *sh;
|
2014-11-21 17:13:45 +01:00
|
|
|
const race * rc = u_race(u);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Muss abgefangen werden, sonst koennten Schwimmer an
|
|
|
|
* Bord von Schiffen an Land gelangen. */
|
2015-01-30 20:37:14 +01:00
|
|
|
if (!(rc->flags & (RCF_CANSAIL | RCF_WALK | RCF_FLY))) {
|
2014-11-21 17:13:45 +01:00
|
|
|
if (report) {
|
|
|
|
cmistake(u, ord, 233, MSG_MOVE);
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sh = findship(id);
|
|
|
|
if (sh == NULL || sh->region != r) {
|
2014-11-21 17:13:45 +01:00
|
|
|
if (report) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 20, MSG_MOVE);
|
2014-11-21 17:13:45 +01:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (sh == u->ship) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!mayboard(u, sh)) {
|
2014-11-21 17:13:45 +01:00
|
|
|
if (report) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 34, MSG_MOVE);
|
2014-11-21 17:13:45 +01:00
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (CheckOverload()) {
|
|
|
|
int sweight, scabins;
|
|
|
|
int mweight = shipcapacity(sh);
|
|
|
|
int mcabins = sh->type->cabins;
|
|
|
|
|
|
|
|
if (mweight > 0) {
|
|
|
|
getshipweight(sh, &sweight, &scabins);
|
|
|
|
sweight += weight(u);
|
|
|
|
if (mcabins) {
|
|
|
|
int pweight = u->number * u_race(u)->weight;
|
|
|
|
/* weight goes into number of cabins, not cargo */
|
|
|
|
scabins += pweight;
|
|
|
|
sweight -= pweight;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (sweight > mweight || (mcabins && (scabins > mcabins))) {
|
|
|
|
if (report)
|
|
|
|
cmistake(u, ord, 34, MSG_MOVE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leave(u, false)) {
|
|
|
|
u_set_ship(u, sh);
|
|
|
|
fset(u, UFL_ENTER);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (report) {
|
|
|
|
cmistake(u, ord, 150, MSG_MOVE);
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2014-11-21 16:39:49 +01:00
|
|
|
int enter_building(unit * u, order * ord, int id, bool report)
|
2012-06-14 08:25:20 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r = u->region;
|
|
|
|
building *b;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Schwimmer können keine Gebäude betreten, außer diese sind
|
2014-07-23 08:10:14 +02:00
|
|
|
* auf dem Ozean */
|
|
|
|
if (!fval(u_race(u), RCF_WALK) && !fval(u_race(u), RCF_FLY)) {
|
|
|
|
if (!fval(r->terrain, SEA_REGION)) {
|
|
|
|
if (report) {
|
|
|
|
cmistake(u, ord, 232, MSG_MOVE);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
b = findbuilding(id);
|
|
|
|
if (b == NULL || b->region != r) {
|
|
|
|
if (report) {
|
|
|
|
cmistake(u, ord, 6, MSG_MOVE);
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!mayenter(r, u, b)) {
|
|
|
|
if (report) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_denied",
|
|
|
|
"building", b));
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!slipthru(r, u, b)) {
|
|
|
|
if (report) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_besieged",
|
|
|
|
"building", b));
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (leave(u, 0)) {
|
|
|
|
fset(u, UFL_ENTER);
|
|
|
|
u_set_building(u, b);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (report) {
|
|
|
|
cmistake(u, ord, 150, MSG_MOVE);
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
static void do_contact(region * r)
|
2012-06-14 08:25:20 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit * u;
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
order *ord;
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
|
|
|
keyword_t kwd = getkeyword(ord);
|
|
|
|
if (kwd == K_CONTACT) {
|
|
|
|
contact_cmd(u, ord);
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
2012-06-18 02:24:23 +02:00
|
|
|
}
|
|
|
|
|
2012-06-24 08:04:12 +02:00
|
|
|
void do_enter(struct region *r, bool is_final_attempt)
|
2012-06-18 02:24:23 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit **uptr;
|
|
|
|
|
|
|
|
for (uptr = &r->units; *uptr;) {
|
|
|
|
unit *u = *uptr;
|
|
|
|
order **ordp = &u->orders;
|
|
|
|
|
|
|
|
while (*ordp) {
|
|
|
|
order *ord = *ordp;
|
|
|
|
if (getkeyword(ord) == K_ENTER) {
|
2014-12-22 14:21:24 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
param_t p;
|
|
|
|
int id;
|
|
|
|
unit *ulast = NULL;
|
|
|
|
const char * s;
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
p = findparam_ex(s, u->faction->locale);
|
|
|
|
id = getid();
|
|
|
|
|
|
|
|
switch (p) {
|
|
|
|
case P_BUILDING:
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
if (u->building && u->building->no == id)
|
|
|
|
break;
|
|
|
|
if (enter_building(u, ord, id, is_final_attempt)) {
|
|
|
|
unit *ub;
|
|
|
|
for (ub = u; ub; ub = ub->next) {
|
|
|
|
if (ub->building == u->building) {
|
|
|
|
ulast = ub;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case P_SHIP:
|
|
|
|
if (u->ship && u->ship->no == id)
|
|
|
|
break;
|
|
|
|
if (enter_ship(u, ord, id, is_final_attempt)) {
|
|
|
|
unit *ub;
|
|
|
|
ulast = u;
|
|
|
|
for (ub = u; ub; ub = ub->next) {
|
|
|
|
if (ub->ship == u->ship) {
|
|
|
|
ulast = ub;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (is_final_attempt) {
|
|
|
|
cmistake(u, ord, 79, MSG_MOVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ulast != NULL) {
|
|
|
|
/* Wenn wir hier angekommen sind, war der Befehl
|
2015-07-06 19:53:09 +02:00
|
|
|
* erfolgreich und wir löschen ihn, damit er im
|
|
|
|
* zweiten Versuch nicht nochmal ausgeführt wird. */
|
2014-07-23 08:10:14 +02:00
|
|
|
*ordp = ord->next;
|
|
|
|
ord->next = NULL;
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
if (ulast != u) {
|
|
|
|
/* put u behind ulast so it's the last unit in the building */
|
|
|
|
*uptr = u->next;
|
|
|
|
u->next = ulast->next;
|
|
|
|
ulast->next = u;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (*ordp == ord)
|
|
|
|
ordp = &ord->next;
|
|
|
|
}
|
|
|
|
if (*uptr == u)
|
|
|
|
uptr = &u->next;
|
|
|
|
}
|
2012-06-14 08:25:20 +02:00
|
|
|
}
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
int dropouts[2];
|
2011-03-07 08:02:35 +01:00
|
|
|
int *age = NULL;
|
|
|
|
|
|
|
|
static void nmr_death(faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-11-22 16:14:27 +01:00
|
|
|
int rule = config_get_int("rules.nmr.destroy", 0) != 0;
|
2014-07-23 08:10:14 +02:00
|
|
|
if (rule) {
|
|
|
|
unit *u;
|
|
|
|
for (u = f->units; u; u = u->nextF) {
|
|
|
|
if (u->building && building_owner(u->building) == u) {
|
|
|
|
remove_building(&u->region->buildings, u->building);
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
static void remove_idle_players(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-01-11 09:55:47 +01:00
|
|
|
faction **fp;
|
2016-08-07 00:40:10 +02:00
|
|
|
int timeout = NMRTimeout();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
log_info(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-01-11 09:55:47 +01:00
|
|
|
for (fp = &factions; *fp;) {
|
|
|
|
faction *f = *fp;
|
2016-08-07 00:40:10 +02:00
|
|
|
|
|
|
|
if (timeout > 0 && turn - f->lastorders >= timeout) {
|
2014-07-23 08:10:14 +02:00
|
|
|
nmr_death(f);
|
2016-01-11 09:55:47 +01:00
|
|
|
destroyfaction(fp);
|
2016-08-07 00:40:10 +02:00
|
|
|
} else {
|
|
|
|
if (fval(f, FFL_NOIDLEOUT)) {
|
|
|
|
f->lastorders = turn;
|
|
|
|
}
|
|
|
|
else if (turn != f->lastorders) {
|
|
|
|
char info[256];
|
|
|
|
sprintf(info, "%d Einheiten, %d Personen, %d Silber",
|
|
|
|
f->no_units, f->num_total, f->money);
|
|
|
|
}
|
|
|
|
fp = &f->next;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben...");
|
|
|
|
|
|
|
|
age = calloc(_max(4, turn + 1), sizeof(int));
|
2016-01-11 09:55:47 +01:00
|
|
|
for (fp = &factions; *fp;) {
|
|
|
|
faction *f = *fp;
|
2016-01-11 11:54:45 +01:00
|
|
|
if (!is_monsters(f)) {
|
2015-01-30 20:37:14 +01:00
|
|
|
if (RemoveNMRNewbie() && !fval(f, FFL_NOIDLEOUT)) {
|
|
|
|
if (f->age >= 0 && f->age <= turn)
|
|
|
|
++age[f->age];
|
|
|
|
if (f->age == 2 || f->age == 3) {
|
|
|
|
if (f->lastorders == turn - 2) {
|
|
|
|
++dropouts[f->age - 2];
|
2016-01-11 09:55:47 +01:00
|
|
|
destroyfaction(fp);
|
2015-01-30 20:37:14 +01:00
|
|
|
continue;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 09:55:47 +01:00
|
|
|
fp = &f->next;
|
|
|
|
}
|
2012-06-18 02:24:23 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
void quit(void)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
faction **fptr = &factions;
|
|
|
|
while (*fptr) {
|
|
|
|
faction *f = *fptr;
|
|
|
|
if (f->flags & FFL_QUIT) {
|
2016-01-11 09:55:47 +01:00
|
|
|
destroyfaction(fptr);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
++f->age;
|
|
|
|
if (f->age + 1 < NewbieImmunity()) {
|
|
|
|
ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns",
|
|
|
|
NewbieImmunity() - f->age - 1));
|
|
|
|
}
|
|
|
|
fptr = &f->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remove_idle_players();
|
|
|
|
remove_empty_units();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* HELFE partei [<ALLES | SILBER | GIB | KAEMPFE | WAHRNEHMUNG>] [NICHT] */
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
int ally_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 14:30:04 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
ally *sf, **sfp;
|
|
|
|
faction *f;
|
|
|
|
int keyword, not_kw;
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
f = getfaction();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (f == NULL || is_monsters(f)) {
|
|
|
|
cmistake(u, ord, 66, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (f == u->faction)
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2015-08-05 12:19:17 +02:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
keyword = P_ANY;
|
2015-11-22 16:14:27 +01:00
|
|
|
}
|
2015-08-05 12:19:17 +02:00
|
|
|
else {
|
2014-07-23 08:10:14 +02:00
|
|
|
keyword = findparam(s, u->faction->locale);
|
2015-08-05 12:19:17 +02:00
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
sfp = &u->faction->allies;
|
|
|
|
if (fval(u, UFL_GROUP)) {
|
|
|
|
attrib *a = a_find(u->attribs, &at_group);
|
|
|
|
if (a)
|
|
|
|
sfp = &((group *)a->data.v)->allies;
|
|
|
|
}
|
|
|
|
for (sf = *sfp; sf; sf = sf->next)
|
|
|
|
if (sf->faction == f)
|
|
|
|
break; /* Gleich die passende raussuchen, wenn vorhanden */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
not_kw = getparam(u->faction->locale); /* HELFE partei [modus] NICHT */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!sf) {
|
|
|
|
if (keyword == P_NOT || not_kw == P_NOT) {
|
|
|
|
/* Wir helfen der Partei gar nicht... */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
2014-10-31 15:13:05 +01:00
|
|
|
sf = ally_add(sfp, f);
|
2014-07-23 08:10:14 +02:00
|
|
|
sf->status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (keyword) {
|
|
|
|
case P_NOT:
|
|
|
|
sf->status = 0;
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case NOPARAM:
|
|
|
|
cmistake(u, ord, 137, MSG_EVENT);
|
|
|
|
return 0;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_ANY:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = 0;
|
|
|
|
else
|
|
|
|
sf->status = HELP_ALL;
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_TRAVEL:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = sf->status & (HELP_ALL - HELP_TRAVEL);
|
|
|
|
else
|
|
|
|
sf->status = sf->status | HELP_TRAVEL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case P_GIVE:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = sf->status & (HELP_ALL - HELP_GIVE);
|
|
|
|
else
|
|
|
|
sf->status = sf->status | HELP_GIVE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case P_MONEY:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = sf->status & (HELP_ALL - HELP_MONEY);
|
|
|
|
else
|
|
|
|
sf->status = sf->status | HELP_MONEY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case P_FIGHT:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = sf->status & (HELP_ALL - HELP_FIGHT);
|
|
|
|
else
|
|
|
|
sf->status = sf->status | HELP_FIGHT;
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_FACTIONSTEALTH:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = sf->status & (HELP_ALL - HELP_FSTEALTH);
|
|
|
|
else
|
|
|
|
sf->status = sf->status | HELP_FSTEALTH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case P_GUARD:
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
sf->status = sf->status & (HELP_ALL - HELP_GUARD);
|
|
|
|
else
|
|
|
|
sf->status = sf->status | HELP_GUARD;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
sf->status &= HelpMask();
|
|
|
|
|
|
|
|
if (sf->status == 0) { /* Alle HELPs geloescht */
|
|
|
|
removelist(sfp, sf);
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static struct local_names *pnames;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void init_prefixnames(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; localenames[i]; ++i) {
|
|
|
|
const struct locale *lang = get_locale(localenames[i]);
|
|
|
|
bool exist = false;
|
|
|
|
struct local_names *in = pnames;
|
|
|
|
|
|
|
|
while (in != NULL) {
|
|
|
|
if (in->lang == lang) {
|
|
|
|
exist = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
in = in->next;
|
|
|
|
}
|
|
|
|
if (in == NULL)
|
|
|
|
in = calloc(sizeof(local_names), 1);
|
|
|
|
in->next = pnames;
|
|
|
|
in->lang = lang;
|
|
|
|
|
2015-09-12 12:41:04 +02:00
|
|
|
if (!exist && race_prefixes) {
|
2014-07-23 08:10:14 +02:00
|
|
|
int key;
|
|
|
|
for (key = 0; race_prefixes[key]; ++key) {
|
|
|
|
variant var;
|
|
|
|
const char *pname =
|
2015-01-08 20:55:29 +01:00
|
|
|
LOC(lang, mkname("prefix", race_prefixes[key]));
|
2014-07-23 08:10:14 +02:00
|
|
|
if (findtoken(in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) {
|
|
|
|
var.i = key;
|
2016-09-06 20:57:07 +02:00
|
|
|
addtoken((struct tnode **)&in->names, pname, var);
|
|
|
|
addtoken((struct tnode **)&in->names, LOC(lang, mkname("prefix",
|
2014-07-23 08:10:14 +02:00
|
|
|
race_prefixes[key])), var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pnames = in;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
int prefix_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
attrib **ap;
|
|
|
|
const char *s;
|
|
|
|
local_names *in = pnames;
|
|
|
|
variant var;
|
|
|
|
const struct locale *lang = u->faction->locale;
|
|
|
|
|
|
|
|
while (in != NULL) {
|
|
|
|
if (in->lang == lang)
|
|
|
|
break;
|
|
|
|
in = in->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (in == NULL) {
|
|
|
|
init_prefixnames();
|
|
|
|
for (in = pnames; in->lang != lang; in = in->next);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
if (!s || !*s) {
|
2014-07-23 08:10:14 +02:00
|
|
|
attrib *a = NULL;
|
|
|
|
if (fval(u, UFL_GROUP)) {
|
|
|
|
a = a_find(u->attribs, &at_group);
|
|
|
|
}
|
|
|
|
if (a) {
|
|
|
|
group *g = (group *)a->data.v;
|
|
|
|
a_removeall(&g->attribs, &at_raceprefix);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a_removeall(&u->faction->attribs, &at_raceprefix);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2014-08-24 21:49:55 +02:00
|
|
|
else if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) {
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (race_prefixes[var.i] == NULL) {
|
|
|
|
cmistake(u, ord, 299, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ap = &u->faction->attribs;
|
|
|
|
if (fval(u, UFL_GROUP)) {
|
|
|
|
attrib *a = a_find(u->attribs, &at_group);
|
2015-07-06 19:53:09 +02:00
|
|
|
if (a) {
|
2015-11-22 16:14:27 +01:00
|
|
|
group *g = (group *)a->data.v;
|
2014-07-23 08:10:14 +02:00
|
|
|
ap = &g->attribs;
|
2015-11-22 16:14:27 +01:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
set_prefix(ap, race_prefixes[var.i]);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static cmp_building_cb get_cmp_region_owner(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
if (rule_region_owners()) {
|
|
|
|
return &cmp_current_owner;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return &cmp_wage;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
int display_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
char **s = NULL;
|
|
|
|
const char *str;
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
str = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
switch (findparam_ex(str, u->faction->locale)) {
|
|
|
|
case P_BUILDING:
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
if (!u->building) {
|
|
|
|
cmistake(u, ord, 145, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (building_owner(u->building) != u) {
|
|
|
|
cmistake(u, ord, 5, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!fval(u->building->type, BTF_NAMECHANGE) && u->building->display && u->building->display[0]) {
|
|
|
|
cmistake(u, ord, 278, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = &u->building->display;
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_SHIP:
|
|
|
|
if (!u->ship) {
|
|
|
|
cmistake(u, ord, 144, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ship_owner(u->ship) != u) {
|
|
|
|
cmistake(u, ord, 12, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = &u->ship->display;
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_UNIT:
|
|
|
|
s = &u->display;
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_PRIVAT:
|
2014-12-22 16:28:17 +01:00
|
|
|
usetprivate(u, getstrtoken());
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_REGION:
|
|
|
|
if (!u->building) {
|
|
|
|
cmistake(u, ord, 145, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (building_owner(u->building) != u) {
|
|
|
|
cmistake(u, ord, 148, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (u->building != largestbuilding(r, get_cmp_region_owner(), false)) {
|
|
|
|
cmistake(u, ord, 147, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = &r->display;
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
default:
|
|
|
|
cmistake(u, ord, 110, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (s != NULL) {
|
|
|
|
const char *s2 = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
free(*s);
|
2014-12-20 22:18:38 +01:00
|
|
|
if (s2) {
|
|
|
|
*s = _strdup(s2);
|
|
|
|
if (strlen(s2) >= DISPLAYSIZE) {
|
|
|
|
(*s)[DISPLAYSIZE] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*s = 0;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
bool renamed_building(const building * b)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
const struct locale *lang = locales;
|
|
|
|
size_t len = strlen(b->name);
|
|
|
|
for (; lang; lang = nextlocale(lang)) {
|
|
|
|
const char *bdname = LOC(lang, b->type->_name);
|
|
|
|
if (bdname) {
|
|
|
|
size_t bdlen = strlen(bdname);
|
|
|
|
if (len >= bdlen && strncmp(b->name, bdname, bdlen) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return true;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int rename_cmd(unit * u, order * ord, char **s, const char *s2)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-11-11 01:59:43 +01:00
|
|
|
char name[NAMESIZE];
|
2015-10-13 14:27:42 +02:00
|
|
|
assert(s2);
|
|
|
|
if (!s2[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 84, MSG_EVENT);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* TODO: Validate to make sure people don't have illegal characters in
|
|
|
|
* names, phishing-style? () come to mind. */
|
2016-11-11 01:59:43 +01:00
|
|
|
strlcpy(name, s2, sizeof(name));
|
|
|
|
unicode_utf8_trim(name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
free(*s);
|
2016-11-11 01:59:43 +01:00
|
|
|
*s = _strdup(name);
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 14:27:42 +02:00
|
|
|
static bool try_rename(unit *u, building *b, order *ord) {
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *owner = b ? building_owner(b) : 0;
|
|
|
|
bool foreign = !(owner && owner->faction == u->faction);
|
|
|
|
|
|
|
|
if (!b) {
|
|
|
|
cmistake(u, ord, u->building ? 6 : 145, MSG_EVENT);
|
2015-10-13 14:27:42 +02:00
|
|
|
return false;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fval(b->type, BTF_NAMECHANGE) && renamed_building(b)) {
|
|
|
|
cmistake(u, ord, 278, MSG_EVENT);
|
2015-10-13 14:27:42 +02:00
|
|
|
return false;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (foreign) {
|
|
|
|
if (renamed_building(b)) {
|
|
|
|
cmistake(u, ord, 246, MSG_EVENT);
|
2015-10-13 14:27:42 +02:00
|
|
|
return false;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (owner) {
|
|
|
|
if (cansee(owner->faction, u->region, u, 0)) {
|
|
|
|
ADDMSG(&owner->faction->msgs,
|
|
|
|
msg_message("renamed_building_seen",
|
2015-10-13 14:27:42 +02:00
|
|
|
"building renamer region", b, u, u->region));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&owner->faction->msgs,
|
|
|
|
msg_message("renamed_building_notseen",
|
2015-10-13 14:27:42 +02:00
|
|
|
"building region", b, u->region));
|
|
|
|
}
|
|
|
|
if (owner != u) {
|
|
|
|
cmistake(u, ord, 148, MSG_PRODUCE);
|
|
|
|
return false;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-13 14:27:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2015-10-13 14:27:42 +02:00
|
|
|
int
|
|
|
|
rename_building(unit * u, order * ord, building * b, const char *name)
|
|
|
|
{
|
|
|
|
assert(name);
|
|
|
|
if (!try_rename(u, b, ord)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return rename_cmd(u, ord, &b->name, name);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
int name_cmd(struct unit *u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
building *b = u->building;
|
|
|
|
region *r = u->region;
|
|
|
|
char **s = NULL;
|
|
|
|
param_t p;
|
|
|
|
bool foreign = false;
|
|
|
|
const char *str;
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
str = gettoken(token, sizeof(token));
|
2012-05-16 21:06:44 +02:00
|
|
|
p = findparam_ex(str, u->faction->locale);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (p == P_FOREIGN) {
|
2014-12-22 16:28:17 +01:00
|
|
|
str = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
foreign = true;
|
|
|
|
p = findparam_ex(str, u->faction->locale);
|
2011-03-08 08:44:20 +01:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
switch (p) {
|
|
|
|
case P_ALLIANCE:
|
|
|
|
if (!foreign && f_get_alliance(u->faction)) {
|
|
|
|
alliance *al = u->faction->alliance;
|
|
|
|
faction *lead = alliance_get_leader(al);
|
|
|
|
if (lead == u->faction) {
|
|
|
|
s = &al->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case P_BUILDING:
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
if (foreign) {
|
|
|
|
b = getbuilding(u->region);
|
|
|
|
}
|
2015-10-13 14:27:42 +02:00
|
|
|
if (try_rename(u, b, ord)) {
|
|
|
|
s = &b->name;
|
|
|
|
}
|
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_FACTION:
|
|
|
|
if (foreign) {
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
f = getfaction();
|
|
|
|
if (!f) {
|
|
|
|
cmistake(u, ord, 66, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->age < 10) {
|
|
|
|
cmistake(u, ord, 248, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const struct locale *lang = locales;
|
2015-07-07 00:49:12 +02:00
|
|
|
size_t f_len = strlen(f->name);
|
2014-07-23 08:10:14 +02:00
|
|
|
for (; lang; lang = nextlocale(lang)) {
|
|
|
|
const char *fdname = LOC(lang, "factiondefault");
|
|
|
|
size_t fdlen = strlen(fdname);
|
2015-07-07 00:49:12 +02:00
|
|
|
if (f_len >= fdlen && strncmp(f->name, fdname, fdlen) == 0) {
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lang == NULL) {
|
|
|
|
cmistake(u, ord, 247, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cansee(f, r, u, 0)) {
|
|
|
|
ADDMSG(&f->msgs,
|
|
|
|
msg_message("renamed_faction_seen", "unit region", u, r));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&f->msgs, msg_message("renamed_faction_notseen", "", r));
|
|
|
|
}
|
|
|
|
s = &f->name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s = &u->faction->name;
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
case P_SHIP:
|
|
|
|
if (foreign) {
|
|
|
|
ship *sh = getship(r);
|
|
|
|
unit *uo;
|
|
|
|
|
|
|
|
if (!sh) {
|
|
|
|
cmistake(u, ord, 20, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const struct locale *lang = locales;
|
2015-07-07 00:49:12 +02:00
|
|
|
size_t sh_len = strlen(sh->name);
|
2014-07-23 08:10:14 +02:00
|
|
|
for (; lang; lang = nextlocale(lang)) {
|
|
|
|
const char *sdname = LOC(lang, sh->type->_name);
|
|
|
|
size_t sdlen = strlen(sdname);
|
2015-07-07 00:49:12 +02:00
|
|
|
if (sh_len >= sdlen && strncmp(sh->name, sdname, sdlen) == 0) {
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdname = LOC(lang, parameters[P_SHIP]);
|
|
|
|
sdlen = strlen(sdname);
|
2015-07-07 00:49:12 +02:00
|
|
|
if (sh_len >= sdlen && strncmp(sh->name, sdname, sdlen) == 0) {
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (lang == NULL) {
|
|
|
|
cmistake(u, ord, 245, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uo = ship_owner(sh);
|
|
|
|
if (uo) {
|
|
|
|
if (cansee(uo->faction, r, u, 0)) {
|
|
|
|
ADDMSG(&uo->faction->msgs,
|
|
|
|
msg_message("renamed_ship_seen", "ship renamer region", sh, u, r));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&uo->faction->msgs,
|
|
|
|
msg_message("renamed_ship_notseen", "ship region", sh, r));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = &sh->name;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
else {
|
|
|
|
if (!u->ship) {
|
|
|
|
cmistake(u, ord, 144, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ship_owner(u->ship) != u) {
|
|
|
|
cmistake(u, ord, 12, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = &u->ship->name;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_UNIT:
|
|
|
|
if (foreign) {
|
2014-12-12 21:06:47 +01:00
|
|
|
unit *u2 = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-12 21:06:47 +01:00
|
|
|
getunit(r, u->faction, &u2);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!u2 || !cansee(u->faction, r, u2, 0)) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
"feedback_unit_not_found", ""));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2015-02-11 16:47:26 +01:00
|
|
|
char udefault[32];
|
|
|
|
default_name(u2, udefault, sizeof(udefault));
|
|
|
|
if (strcmp(unit_getname(u2), udefault) != 0) {
|
|
|
|
cmistake(u, ord, 244, MSG_EVENT);
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cansee(u2->faction, r, u, 0)) {
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message("renamed_seen",
|
|
|
|
"renamer renamed region", u, u2, r));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&u2->faction->msgs, msg_message("renamed_notseen",
|
|
|
|
"renamed region", u2, r));
|
|
|
|
}
|
2015-02-11 07:55:35 +01:00
|
|
|
s = &u2->_name;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-02-11 07:55:35 +01:00
|
|
|
s = &u->_name;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
case P_REGION:
|
|
|
|
if (!b) {
|
|
|
|
cmistake(u, ord, 145, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (building_owner(b) != u) {
|
|
|
|
cmistake(u, ord, 148, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b != largestbuilding(r, get_cmp_region_owner(), false)) {
|
|
|
|
cmistake(u, ord, 147, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
s = &r->land->name;
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_GROUP:
|
|
|
|
{
|
|
|
|
attrib *a = NULL;
|
|
|
|
if (fval(u, UFL_GROUP))
|
|
|
|
a = a_find(u->attribs, &at_group);
|
|
|
|
if (a) {
|
|
|
|
group *g = (group *)a->data.v;
|
|
|
|
s = &g->name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmistake(u, ord, 109, MSG_EVENT);
|
2011-03-08 08:44:20 +01:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
default:
|
|
|
|
cmistake(u, ord, 109, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (s != NULL) {
|
2015-02-08 10:33:45 +01:00
|
|
|
const char *name = getstrtoken();
|
|
|
|
if (name) {
|
|
|
|
rename_cmd(u, ord, s, name);
|
|
|
|
}
|
2015-10-13 14:27:42 +02:00
|
|
|
else {
|
|
|
|
cmistake(u, ord, 84, MSG_EVENT);
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!cansee(f, r, u, 0)) {
|
|
|
|
u = NULL;
|
|
|
|
}
|
|
|
|
if (!receiver) { /* BOTSCHAFT an PARTEI */
|
|
|
|
ADDMSG(&f->msgs,
|
|
|
|
msg_message("regionmessage", "region sender string", r, u, s));
|
|
|
|
}
|
|
|
|
else { /* BOTSCHAFT an EINHEIT */
|
|
|
|
ADDMSG(&f->msgs,
|
|
|
|
msg_message("unitmessage", "region unit sender string", r,
|
2015-11-22 16:14:27 +01:00
|
|
|
receiver, u, s));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 08:02:35 +01:00
|
|
|
mailunit(region * r, unit * u, int n, struct order *ord, const char *s)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u2 = findunitr(r, n);
|
|
|
|
|
|
|
|
if (u2 && cansee(u->faction, r, u2, 0)) {
|
|
|
|
deliverMail(u2->faction, r, u, s, u2);
|
|
|
|
/* now done in prepare_mail_cmd */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Immer eine Meldung - sonst koennte man so getarnte EHs enttarnen:
|
|
|
|
* keine Meldung -> EH hier. */
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, ord, "feedback_unit_not_found", ""));
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void mailfaction(unit * u, int n, struct order *ord, const char *s)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
faction *f;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
f = findfaction(n);
|
|
|
|
if (f && n > 0)
|
|
|
|
deliverMail(f, u->region, u, s, NULL);
|
|
|
|
else
|
|
|
|
cmistake(u, ord, 66, MSG_MESSAGE);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
int mail_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r = u->region;
|
|
|
|
unit *u2;
|
|
|
|
const char *s;
|
|
|
|
int n, cont;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Falls kein Parameter, ist das eine Einheitsnummer;
|
2015-08-02 21:37:12 +02:00
|
|
|
* das Füllwort "AN" muss wegfallen, da gültige Nummer! */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
do {
|
|
|
|
cont = 0;
|
|
|
|
switch (findparam_ex(s, u->faction->locale)) {
|
|
|
|
case P_REGION:
|
2015-07-06 19:53:09 +02:00
|
|
|
/* können alle Einheiten in der Region sehen */
|
2014-07-23 08:10:14 +02:00
|
|
|
s = getstrtoken();
|
2014-12-12 11:28:37 +01:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&r->msgs, msg_message("mail_result", "unit message", u, s));
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_FACTION:
|
|
|
|
n = getfactionid();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-23 09:23:37 +01:00
|
|
|
if (!u2) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 66, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
s = getstrtoken();
|
2015-10-10 22:50:15 +02:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mailfaction(u, n, ord, s);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_UNIT:
|
|
|
|
n = getid();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
if (u2->no == n && cansee(u->faction, r, u2, 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-23 09:23:37 +01:00
|
|
|
if (!u2) {
|
2014-07-23 08:10:14 +02:00
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
"feedback_unit_not_found", ""));
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
s = getstrtoken();
|
2015-10-10 22:50:15 +02:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
attrib *a = a_find(u2->attribs, &at_eventhandler);
|
|
|
|
if (a != NULL) {
|
|
|
|
event_arg args[3];
|
|
|
|
args[0].data.v = (void *)s;
|
|
|
|
args[0].type = "string";
|
|
|
|
args[1].data.v = (void *)u;
|
|
|
|
args[1].type = "unit";
|
|
|
|
args[2].type = NULL;
|
|
|
|
handle_event(a, "message", args);
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
mailunit(r, u, n, ord, s);
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_BUILDING:
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
{
|
|
|
|
building *b = getbuilding(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!b) {
|
|
|
|
cmistake(u, ord, 6, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-10-10 22:50:15 +02:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next)
|
|
|
|
freset(u2->faction, FFL_SELECT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
if (u2->building == b && !fval(u2->faction, FFL_SELECT)
|
|
|
|
&& cansee(u->faction, r, u2, 0)) {
|
|
|
|
mailunit(r, u, u2->no, ord, s);
|
|
|
|
fset(u2->faction, FFL_SELECT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_SHIP:
|
|
|
|
{
|
|
|
|
ship *sh = getship(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!sh) {
|
|
|
|
cmistake(u, ord, 20, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-10-10 22:50:15 +02:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next)
|
|
|
|
freset(u2->faction, FFL_SELECT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
if (u2->ship == sh && !fval(u2->faction, FFL_SELECT)
|
|
|
|
&& cansee(u->faction, r, u2, 0)) {
|
|
|
|
mailunit(r, u, u2->no, ord, s);
|
|
|
|
fset(u2->faction, FFL_SELECT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
default:
|
|
|
|
/* possibly filler token? */
|
|
|
|
s = getstrtoken();
|
|
|
|
if (s && *s)
|
|
|
|
cont = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (cont);
|
|
|
|
cmistake(u, ord, 149, MSG_MESSAGE);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int banner_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-09-21 16:43:17 +02:00
|
|
|
const char * s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
free(u->faction->banner);
|
2014-09-21 16:43:17 +02:00
|
|
|
u->faction->banner = s ? _strdup(s) : 0;
|
2014-07-23 08:10:14 +02:00
|
|
|
add_message(&u->faction->msgs, msg_message("changebanner", "value",
|
|
|
|
u->faction->banner));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int email_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-11 23:23:11 +01:00
|
|
|
if (!s || !s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 85, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
faction *f = u->faction;
|
2014-12-22 16:28:17 +01:00
|
|
|
if (set_email(&f->email, s) != 0) {
|
2014-07-23 08:10:14 +02:00
|
|
|
log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), s);
|
|
|
|
ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ADDMSG(&f->msgs, msg_message("changemail", "value", f->email));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int password_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
char pwbuf[32];
|
|
|
|
int i;
|
|
|
|
const char *s;
|
|
|
|
bool pwok = true;
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(pwbuf, sizeof(pwbuf));
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (!s || !*s) {
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
pwbuf[i] = (char)(97 + rng_int() % 26);
|
|
|
|
pwbuf[6] = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *c;
|
2014-12-22 16:28:17 +01:00
|
|
|
for (c = pwbuf; *c && pwok; ++c) {
|
|
|
|
if (!isalnum(*(unsigned char *)c)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
pwok = false;
|
2014-12-22 16:28:17 +01:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!pwok) {
|
|
|
|
cmistake(u, ord, 283, MSG_EVENT);
|
2016-01-12 06:46:51 +01:00
|
|
|
strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2016-02-12 08:31:42 +01:00
|
|
|
faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT));
|
2014-07-23 08:10:14 +02:00
|
|
|
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
2016-01-12 06:46:51 +01:00
|
|
|
"value", pwbuf));
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int send_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *s;
|
|
|
|
int option;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
option = findoption(s, u->faction->locale);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (option == -1) {
|
|
|
|
cmistake(u, ord, 135, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (getparam(u->faction->locale) == P_NOT) {
|
|
|
|
if (option == O_COMPRESS || option == O_BZIP2) {
|
|
|
|
cmistake(u, ord, 305, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u->faction->options = u->faction->options & ~(1 << option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u->faction->options = u->faction->options | (1 << option);
|
|
|
|
if (option == O_COMPRESS)
|
|
|
|
u->faction->options &= ~(1 << O_BZIP2);
|
|
|
|
if (option == O_BZIP2)
|
|
|
|
u->faction->options &= ~(1 << O_COMPRESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:24:33 +02:00
|
|
|
static void display_item(unit * u, const item_type * itype)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-06-06 23:24:33 +02:00
|
|
|
faction * f = u->faction;
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *name;
|
|
|
|
const char *key;
|
|
|
|
const char *info;
|
|
|
|
|
|
|
|
name = resourcename(itype->rtype, 0);
|
|
|
|
key = mkname("iteminfo", name);
|
|
|
|
info = locale_getstring(f->locale, key);
|
|
|
|
|
|
|
|
if (info == NULL) {
|
2015-01-08 20:55:29 +01:00
|
|
|
info = LOC(f->locale, mkname("iteminfo", "no_info"));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
ADDMSG(&f->msgs, msg_message("displayitem", "weight item description",
|
|
|
|
itype->weight, itype->rtype, info));
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:24:33 +02:00
|
|
|
static void display_potion(unit * u, const potion_type * ptype)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-06-06 23:24:33 +02:00
|
|
|
faction * f = u->faction;
|
2014-07-23 08:10:14 +02:00
|
|
|
attrib *a;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
a = a_find(f->attribs, &at_showitem);
|
|
|
|
while (a && a->data.v != ptype)
|
|
|
|
a = a->next;
|
|
|
|
if (!a) {
|
|
|
|
a = a_add(&f->attribs, a_new(&at_showitem));
|
|
|
|
a->data.v = (void *)ptype->itype;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:24:33 +02:00
|
|
|
static void display_race(unit * u, const race * rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-06-06 23:24:33 +02:00
|
|
|
faction * f = u->faction;
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *name, *key;
|
|
|
|
const char *info;
|
|
|
|
int a, at_count;
|
|
|
|
char buf[2048], *bufp = buf;
|
|
|
|
size_t size = sizeof(buf) - 1;
|
2015-05-15 19:08:44 +02:00
|
|
|
size_t bytes;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-12-09 07:20:36 +01:00
|
|
|
name = rc_name_s(rc, NAME_SINGULAR);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
bytes = slprintf(bufp, size, "%s: ", LOC(f->locale, name));
|
2015-08-17 20:17:02 +02:00
|
|
|
assert(bytes <= INT_MAX);
|
|
|
|
if (wrptr(&bufp, &size, (int)bytes) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
key = mkname("raceinfo", rc->_name);
|
2014-07-23 08:10:14 +02:00
|
|
|
info = locale_getstring(f->locale, key);
|
|
|
|
if (info == NULL) {
|
2015-01-08 20:55:29 +01:00
|
|
|
info = LOC(f->locale, mkname("raceinfo", "no_info"));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:24:33 +02:00
|
|
|
if (info) bufp = STRLCPY(bufp, info, size);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
/* hp_p : Trefferpunkte */
|
|
|
|
bytes =
|
|
|
|
slprintf(bufp, size, " %d %s", rc->hitpoints, LOC(f->locale,
|
2015-11-22 16:14:27 +01:00
|
|
|
"stat_hitpoints"));
|
2015-08-17 20:17:02 +02:00
|
|
|
assert(bytes <= INT_MAX);
|
|
|
|
if (wrptr(&bufp, &size, (int)bytes) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
|
|
|
|
/* b_attacke : Angriff */
|
|
|
|
bytes =
|
|
|
|
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_attack"),
|
2015-11-22 16:14:27 +01:00
|
|
|
(rc->at_default + rc->at_bonus));
|
2015-08-17 20:17:02 +02:00
|
|
|
assert(bytes <= INT_MAX);
|
|
|
|
if (wrptr(&bufp, &size, (int)bytes) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
|
|
|
|
/* b_defense : Verteidigung */
|
|
|
|
bytes =
|
|
|
|
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_defense"),
|
2015-11-22 16:14:27 +01:00
|
|
|
(rc->df_default + rc->df_bonus));
|
2015-08-17 20:17:02 +02:00
|
|
|
assert(bytes <= INT_MAX);
|
|
|
|
if (wrptr(&bufp, &size, (int)bytes) != 0)
|
2011-03-07 08:02:35 +01:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* b_armor : Rüstung */
|
2014-07-23 08:10:14 +02:00
|
|
|
if (rc->armor > 0) {
|
2011-03-08 08:44:20 +01:00
|
|
|
bytes =
|
2014-07-23 08:10:14 +02:00
|
|
|
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_armor"), rc->armor);
|
2015-08-17 20:17:02 +02:00
|
|
|
assert(bytes <= INT_MAX);
|
|
|
|
if (wrptr(&bufp, &size, (int)bytes) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > 1) {
|
|
|
|
*bufp++ = '.';
|
|
|
|
--size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
|
|
|
|
/* b_damage : Schaden */
|
|
|
|
at_count = 0;
|
2015-01-19 15:13:03 +01:00
|
|
|
for (a = 0; a < RACE_ATTACKS; a++) {
|
2014-07-23 08:10:14 +02:00
|
|
|
if (rc->attack[a].type != AT_NONE) {
|
|
|
|
at_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc->battle_flags & BF_EQUIPMENT) {
|
2015-08-17 20:17:02 +02:00
|
|
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"))) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
}
|
|
|
|
if (rc->battle_flags & BF_RES_PIERCE) {
|
2015-08-17 20:17:02 +02:00
|
|
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"))) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
}
|
|
|
|
if (rc->battle_flags & BF_RES_CUT) {
|
2015-08-17 20:17:02 +02:00
|
|
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"))) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
}
|
|
|
|
if (rc->battle_flags & BF_RES_BASH) {
|
2015-08-17 20:17:02 +02:00
|
|
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"))) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-08-17 20:17:02 +02:00
|
|
|
if (wrptr(&bufp, &size, _snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks"))) != 0)
|
2011-03-07 08:02:35 +01:00
|
|
|
WARN_STATIC_BUFFER();
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2015-01-19 15:13:03 +01:00
|
|
|
for (a = 0; a < RACE_ATTACKS; a++) {
|
2014-07-23 08:10:14 +02:00
|
|
|
if (rc->attack[a].type != AT_NONE) {
|
|
|
|
if (a != 0)
|
2015-08-17 22:48:21 +02:00
|
|
|
bufp = STRLCPY(bufp, ", ", size);
|
2014-07-23 08:10:14 +02:00
|
|
|
else
|
2015-08-17 22:48:21 +02:00
|
|
|
bufp = STRLCPY(bufp, ": ", size);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
switch (rc->attack[a].type) {
|
|
|
|
case AT_STANDARD:
|
|
|
|
bytes =
|
2015-05-15 19:08:44 +02:00
|
|
|
(size_t)_snprintf(bufp, size, "%s (%s)",
|
2015-11-22 16:14:27 +01:00
|
|
|
LOC(f->locale, "attack_standard"), rc->def_damage);
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
case AT_NATURAL:
|
|
|
|
bytes =
|
2015-05-15 19:08:44 +02:00
|
|
|
(size_t)_snprintf(bufp, size, "%s (%s)",
|
2015-11-22 16:14:27 +01:00
|
|
|
LOC(f->locale, "attack_natural"), rc->attack[a].data.dice);
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
case AT_SPELL:
|
|
|
|
case AT_COMBATSPELL:
|
|
|
|
case AT_DRAIN_ST:
|
|
|
|
case AT_DRAIN_EXP:
|
|
|
|
case AT_DAZZLE:
|
2015-05-15 19:08:44 +02:00
|
|
|
bytes = (size_t)_snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical"));
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
case AT_STRUCTURAL:
|
|
|
|
bytes =
|
2015-05-15 19:08:44 +02:00
|
|
|
(size_t)_snprintf(bufp, size, "%s (%s)",
|
2015-11-22 16:14:27 +01:00
|
|
|
LOC(f->locale, "attack_structural"), rc->attack[a].data.dice);
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bytes = 0;
|
|
|
|
}
|
|
|
|
|
2015-08-17 20:17:02 +02:00
|
|
|
assert(bytes <= INT_MAX);
|
|
|
|
if (bytes && wrptr(&bufp, &size, (int)bytes) != 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (size > 1) {
|
|
|
|
*bufp++ = '.';
|
|
|
|
--size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
*bufp = 0;
|
|
|
|
addmessage(0, f, buf, MSG_EVENT, ML_IMPORTANT);
|
2016-06-06 23:24:33 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-06-06 23:24:33 +02:00
|
|
|
static void reshow_other(unit * u, struct order *ord, const char *s) {
|
|
|
|
int err = 21;
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
const spell *sp = 0;
|
|
|
|
const item_type *itype;
|
|
|
|
const race *rc;
|
|
|
|
/* check if it's an item */
|
|
|
|
itype = finditemtype(s, u->faction->locale);
|
|
|
|
sp = unit_getspell(u, s, u->faction->locale);
|
|
|
|
rc = findrace(s, u->faction->locale);
|
|
|
|
|
|
|
|
if (itype) {
|
|
|
|
// if this is a potion, we need the right alchemy skill
|
|
|
|
int i = i_get(u->items, itype);
|
|
|
|
|
|
|
|
err = 36; // we do not have this item?
|
|
|
|
if (i <= 0) {
|
|
|
|
// we don't have the item, but it may be a potion that we know
|
|
|
|
const potion_type *ptype = resource2potion(item2resource(itype));
|
|
|
|
if (ptype) {
|
|
|
|
if (2 * ptype->level > effskill(u, SK_ALCHEMY, 0)) {
|
|
|
|
itype = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
itype = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itype) {
|
|
|
|
const potion_type *ptype = itype->rtype->ptype;
|
|
|
|
if (ptype) {
|
|
|
|
display_potion(u, ptype);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
display_item(u, itype);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp) {
|
|
|
|
attrib *a = a_find(u->faction->attribs, &at_seenspell);
|
|
|
|
while (a != NULL && a->type == &at_seenspell && a->data.v != sp) {
|
|
|
|
a = a->next;
|
|
|
|
}
|
|
|
|
if (a != NULL) {
|
|
|
|
a_remove(&u->faction->attribs, a);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc && u_race(u) == rc) {
|
|
|
|
display_race(u, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmistake(u, ord, err, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void reshow(unit * u, struct order *ord, const char *s, param_t p)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int skill, c;
|
|
|
|
const potion_type *ptype;
|
|
|
|
|
|
|
|
switch (p) {
|
|
|
|
case P_ZAUBER:
|
|
|
|
a_removeall(&u->faction->attribs, &at_seenspell);
|
|
|
|
break;
|
|
|
|
case P_POTIONS:
|
2015-08-27 16:16:55 +02:00
|
|
|
skill = effskill(u, SK_ALCHEMY, 0);
|
2014-07-23 08:10:14 +02:00
|
|
|
c = 0;
|
|
|
|
for (ptype = potiontypes; ptype != NULL; ptype = ptype->next) {
|
|
|
|
if (ptype->level * 2 <= skill) {
|
2016-06-06 23:24:33 +02:00
|
|
|
display_potion(u, ptype);
|
|
|
|
++c;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2012-05-26 20:29:27 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (c == 0)
|
|
|
|
cmistake(u, ord, 285, MSG_EVENT);
|
|
|
|
break;
|
|
|
|
case NOPARAM:
|
2016-06-06 23:24:33 +02:00
|
|
|
reshow_other(u, ord, s);
|
2012-05-26 20:29:27 +02:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
default:
|
|
|
|
cmistake(u, ord, 222, MSG_EVENT);
|
2012-05-26 20:29:27 +02:00
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-17 08:31:25 +02:00
|
|
|
int promotion_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-06-24 16:42:45 +02:00
|
|
|
const struct resource_type *rsilver = get_resourcetype(R_SILVER);
|
2014-07-23 08:10:14 +02:00
|
|
|
int money, people;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (fval(u, UFL_HERO)) {
|
|
|
|
/* TODO: message "is already a hero" */
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (maxheroes(u->faction) < countheroes(u->faction) + u->number) {
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, ord, "heroes_maxed", "max count",
|
2015-11-22 16:14:27 +01:00
|
|
|
maxheroes(u->faction), countheroes(u->faction)));
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!valid_race(u->faction, u_race(u))) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "heroes_race", "race",
|
|
|
|
u_race(u)));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
people = count_all(u->faction) * u->number;
|
|
|
|
money = get_pooled(u, rsilver, GET_ALL, people);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (people > money) {
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, ord, "heroes_cost", "cost have", people, money));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
use_pooled(u, rsilver, GET_ALL, people);
|
|
|
|
fset(u, UFL_HERO);
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("hero_promotion", "unit cost",
|
|
|
|
u, people));
|
2010-08-08 10:06:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int group_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
keyword_t kwd;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
kwd = init_order(ord);
|
|
|
|
assert(kwd == K_GROUP);
|
2014-12-22 16:28:17 +01:00
|
|
|
join_group(u, getstrtoken());
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
int origin_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
short px, py;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
px = (short)getint();
|
|
|
|
py = (short)getint();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-05-19 08:02:32 +02:00
|
|
|
faction_setorigin(u->faction, getplaneid(u->region), px, py);
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
int guard_off_cmd(unit * u, struct order *ord)
|
|
|
|
{
|
|
|
|
assert(getkeyword(ord) == K_GUARD);
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (getparam(u->faction->locale) == P_NOT) {
|
2016-10-31 07:45:06 +01:00
|
|
|
setguard(u, false);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
int reshow_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 14:21:24 +01:00
|
|
|
char lbuf[64];
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *s;
|
|
|
|
param_t p = NOPARAM;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(lbuf, sizeof(lbuf));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-18 21:36:46 +02:00
|
|
|
if (s && isparam(s, u->faction->locale, P_ANY)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
p = getparam(u->faction->locale);
|
|
|
|
s = NULL;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
reshow(u, ord, s, p);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
int status_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
|
|
|
const char *s;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
|
|
|
switch (findparam(s, u->faction->locale)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
case P_NOT:
|
|
|
|
setstatus(u, ST_AVOID);
|
|
|
|
break;
|
|
|
|
case P_BEHIND:
|
|
|
|
setstatus(u, ST_BEHIND);
|
|
|
|
break;
|
|
|
|
case P_FLEE:
|
|
|
|
setstatus(u, ST_FLEE);
|
|
|
|
break;
|
|
|
|
case P_CHICKEN:
|
|
|
|
setstatus(u, ST_CHICKEN);
|
|
|
|
break;
|
|
|
|
case P_AGGRO:
|
|
|
|
setstatus(u, ST_AGGRO);
|
|
|
|
break;
|
|
|
|
case P_VORNE:
|
|
|
|
setstatus(u, ST_FIGHT);
|
|
|
|
break;
|
|
|
|
case P_HELP:
|
|
|
|
if (getparam(u->faction->locale) == P_NOT) {
|
|
|
|
fset(u, UFL_NOAID);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
freset(u, UFL_NOAID);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-12-22 16:28:17 +01:00
|
|
|
if (s && s[0]) {
|
2014-07-23 08:10:14 +02:00
|
|
|
add_message(&u->faction->msgs,
|
|
|
|
msg_feedback(u, ord, "unknown_status", ""));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setstatus(u, ST_FIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-17 21:51:48 +02:00
|
|
|
int combatspell_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 14:21:24 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *s;
|
|
|
|
int level = 0;
|
|
|
|
spell *sp = 0;
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!s || *s == 0 || findparam(s, u->faction->locale) == P_NOT) {
|
|
|
|
unset_combatspell(u, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Optional: STUFE n */
|
|
|
|
if (findparam(s, u->faction->locale) == P_LEVEL) {
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Merken, setzen kommt erst später */
|
2014-07-23 08:10:14 +02:00
|
|
|
level = getint();
|
|
|
|
level = _max(0, level);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
sp = unit_getspell(u, s, u->faction->locale);
|
|
|
|
if (!sp) {
|
|
|
|
cmistake(u, ord, 173, MSG_MAGIC);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (findparam(s, u->faction->locale) == P_NOT) {
|
2015-07-06 19:53:09 +02:00
|
|
|
/* KAMPFZAUBER "<Spruchname>" NICHT löscht diesen speziellen
|
2014-07-23 08:10:14 +02:00
|
|
|
* Kampfzauber */
|
|
|
|
unset_combatspell(u, sp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* KAMPFZAUBER "<Spruchname>" setzt diesen Kampfzauber */
|
|
|
|
set_combatspell(u, sp, ord, level);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-18 08:13:58 +02:00
|
|
|
int guard_on_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
assert(getkeyword(ord) == K_GUARD);
|
2015-07-07 00:49:12 +02:00
|
|
|
assert(u);
|
|
|
|
assert(u->faction);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* GUARD NOT is handled in goard_off_cmd earlier in the turn */
|
2015-07-07 00:49:12 +02:00
|
|
|
if (getparam(u->faction->locale) == P_NOT) {
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2015-07-07 00:49:12 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (fval(u->region->terrain, SEA_REGION)) {
|
|
|
|
cmistake(u, ord, 2, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fval(u, UFL_MOVED)) {
|
|
|
|
cmistake(u, ord, 187, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (fval(u_race(u), RCF_ILLUSIONARY)
|
|
|
|
|| u_race(u) == get_race(RC_SPELL)) {
|
|
|
|
cmistake(u, ord, 95, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
2015-11-23 15:35:26 +01:00
|
|
|
int err = can_start_guarding(u);
|
|
|
|
if (err == E_GUARD_OK) {
|
2016-10-31 07:45:06 +01:00
|
|
|
setguard(u, true);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2015-11-23 15:35:26 +01:00
|
|
|
else if (err == E_GUARD_UNARMED) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", ""));
|
|
|
|
}
|
|
|
|
else if (err == E_GUARD_FLEEING) {
|
|
|
|
cmistake(u, ord, 320, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (err == E_GUARD_NEWBIE) {
|
|
|
|
cmistake(u, ord, 304, MSG_EVENT);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
void sinkships(struct region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
ship **shp = &r->ships;
|
|
|
|
|
|
|
|
while (*shp) {
|
|
|
|
ship *sh = *shp;
|
|
|
|
|
|
|
|
if (!sh->type->construction || sh->size >= sh->type->construction->maxsize) {
|
2015-08-07 09:03:19 +02:00
|
|
|
if (fval(r->terrain, SEA_REGION)) {
|
|
|
|
if (!enoughsailors(sh, crew_skill(sh))) {
|
|
|
|
// ship is at sea, but not enough people to control it
|
2015-11-22 10:44:46 +01:00
|
|
|
double dmg = config_get_flt("rules.ship.damage.nocrewocean", 0.3);
|
2015-08-07 09:03:19 +02:00
|
|
|
damage_ship(sh, dmg);
|
|
|
|
}
|
2015-11-22 16:14:27 +01:00
|
|
|
}
|
|
|
|
else if (!ship_owner(sh)) {
|
2015-08-07 09:03:19 +02:00
|
|
|
// any ship lying around without an owner slowly rots
|
2015-11-22 10:44:46 +01:00
|
|
|
double dmg = config_get_flt("rules.ship.damage.nocrew", 0.05);
|
2014-07-23 08:10:14 +02:00
|
|
|
damage_ship(sh, dmg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sh->damage >= sh->size * DAMAGE_SCALE) {
|
|
|
|
remove_ship(shp, sh);
|
|
|
|
}
|
|
|
|
if (*shp == sh)
|
|
|
|
shp = &sh->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-17 08:31:25 +02:00
|
|
|
void restack_units(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r;
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
unit **up = &r->units;
|
|
|
|
bool sorted = false;
|
|
|
|
while (*up) {
|
|
|
|
unit *u = *up;
|
|
|
|
if (!fval(u, UFL_MARK)) {
|
|
|
|
struct order *ord;
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
|
|
|
if (getkeyword(ord) == K_SORT) {
|
2014-12-22 14:30:04 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *s;
|
|
|
|
param_t p;
|
|
|
|
int id;
|
|
|
|
unit *v;
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
p = findparam(s, u->faction->locale);
|
|
|
|
id = getid();
|
|
|
|
v = findunit(id);
|
|
|
|
|
|
|
|
if (!v || v->faction != u->faction || v->region != r) {
|
|
|
|
cmistake(u, ord, 258, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (v->building != u->building || v->ship != u->ship) {
|
|
|
|
cmistake(u, ord, 259, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (u->building && building_owner(u->building) == u) {
|
|
|
|
cmistake(u, ord, 260, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (u->ship && ship_owner(u->ship) == u) {
|
|
|
|
cmistake(u, ord, 260, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (v == u) {
|
2015-05-18 11:34:52 +02:00
|
|
|
syntax_error(u, ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (p) {
|
|
|
|
case P_AFTER:
|
|
|
|
*up = u->next;
|
|
|
|
u->next = v->next;
|
|
|
|
v->next = u;
|
|
|
|
fset(u, UFL_MARK);
|
|
|
|
sorted = true;
|
|
|
|
break;
|
|
|
|
case P_BEFORE:
|
|
|
|
if (v->ship && ship_owner(v->ship) == v) {
|
|
|
|
cmistake(v, ord, 261, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else if (v->building && building_owner(v->building) == v) {
|
|
|
|
cmistake(v, ord, 261, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unit **vp = &r->units;
|
|
|
|
while (*vp != v)
|
|
|
|
vp = &(*vp)->next;
|
|
|
|
*vp = u;
|
|
|
|
*up = u->next;
|
|
|
|
u->next = v;
|
|
|
|
}
|
|
|
|
fset(u, UFL_MARK);
|
|
|
|
sorted = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* TODO: syntax error message? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (u == *up)
|
|
|
|
up = &u->next;
|
|
|
|
}
|
|
|
|
if (sorted) {
|
|
|
|
unit *u;
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
freset(u, UFL_MARK);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-31 13:47:18 +01:00
|
|
|
/* blesses stone circles create an astral protection in the astral region
|
|
|
|
* above the shield, which prevents chaos suction and other spells.
|
|
|
|
* The shield is created when a magician enters the blessed stone circle,
|
|
|
|
* and lasts for as long as his skill level / 2 is, at no mana cost.
|
|
|
|
*
|
|
|
|
* TODO: this would be nicer in a btype->age function, but we don't have it.
|
|
|
|
*/
|
|
|
|
static void age_stonecircle(building *b) {
|
2014-06-25 07:44:05 +02:00
|
|
|
const struct resource_type *rtype = get_resourcetype(R_UNICORN);
|
2016-01-31 13:47:18 +01:00
|
|
|
region *r = b->region;
|
|
|
|
unit *u, *mage = NULL;
|
2014-06-18 08:10:55 +02:00
|
|
|
|
2016-01-31 13:47:18 +01:00
|
|
|
/* step 1: give unicorns to people in the building,
|
|
|
|
* find out if there's a magician in there. */
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
if (b == u->building && inside_building(u)) {
|
|
|
|
if (!mage && is_mage(u)) {
|
|
|
|
mage = u;
|
|
|
|
}
|
|
|
|
if (rtype && (u_race(u)->ec_flags & ECF_KEEP_ITEM) == 0) {
|
|
|
|
int n, unicorns = 0;
|
|
|
|
for (n = 0; n != u->number; ++n) {
|
|
|
|
if (chance(0.02)) {
|
|
|
|
i_change(&u->items, rtype->itype, 1);
|
|
|
|
++unicorns;
|
|
|
|
}
|
|
|
|
if (unicorns) {
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("scunicorn",
|
|
|
|
"unit amount rtype",
|
|
|
|
u, unicorns, rtype));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-31 13:47:18 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-01-31 13:47:18 +01:00
|
|
|
/* step 2: if there's a magician, and a connection to astral space, create the
|
|
|
|
* curse. */
|
|
|
|
if (get_astralplane()) {
|
|
|
|
region *rt = r_standard_to_astral(r);
|
|
|
|
if (mage && rt && !fval(rt->terrain, FORBIDDEN_REGION)) {
|
|
|
|
const struct curse_type *ct_astralblock = ct_find("astralblock");
|
2014-07-23 08:10:14 +02:00
|
|
|
curse *c = get_curse(rt->attribs, ct_astralblock);
|
2016-01-31 13:47:18 +01:00
|
|
|
if (!c) {
|
|
|
|
int sk = effskill(mage, SK_MAGIC, 0);
|
|
|
|
float effect = 100;
|
|
|
|
/* the mage reactivates the circle */
|
|
|
|
c = create_curse(mage, &rt->attribs, ct_astralblock,
|
|
|
|
(float)_max(1, sk), _max(1, sk / 2), effect, 0);
|
|
|
|
ADDMSG(&r->msgs,
|
|
|
|
msg_message("astralshield_activate", "region unit", r, mage));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2016-01-31 13:47:18 +01:00
|
|
|
else {
|
2015-08-27 16:16:55 +02:00
|
|
|
int sk = effskill(mage, SK_MAGIC, 0);
|
2014-07-23 08:10:14 +02:00
|
|
|
c->duration = _max(c->duration, sk / 2);
|
2015-05-15 19:08:44 +02:00
|
|
|
c->vigour = _max(c->vigour, (float)sk);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-31 13:47:18 +01:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-01-31 13:47:18 +01:00
|
|
|
static building *age_building(building * b)
|
|
|
|
{
|
2016-08-30 10:19:19 +02:00
|
|
|
if (is_building_type(b->type, "blessedstonecircle")) {
|
2016-01-31 13:47:18 +01:00
|
|
|
age_stonecircle(b);
|
|
|
|
}
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&b->attribs, b);
|
2014-07-23 08:10:14 +02:00
|
|
|
handle_event(b->attribs, "timer", b);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (b->type->age) {
|
|
|
|
b->type->age(b);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
return b;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void age_region(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&r->attribs, r);
|
2014-07-23 08:10:14 +02:00
|
|
|
handle_event(r->attribs, "timer", r);
|
|
|
|
|
|
|
|
if (!r->land)
|
|
|
|
return;
|
|
|
|
|
2014-12-10 19:04:02 +01:00
|
|
|
morale_update(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void ageing(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
faction *f;
|
|
|
|
region *r;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* altern spezieller Attribute, die eine Sonderbehandlung brauchen? */
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
unit *u;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
/* Goliathwasser */
|
|
|
|
int i = get_effect(u, oldpotiontype[P_STRONG]);
|
|
|
|
if (i > 0) {
|
|
|
|
change_effect(u, oldpotiontype[P_STRONG], -1 * _min(u->number, i));
|
|
|
|
}
|
|
|
|
/* Berserkerblut */
|
|
|
|
i = get_effect(u, oldpotiontype[P_BERSERK]);
|
|
|
|
if (i > 0) {
|
|
|
|
change_effect(u, oldpotiontype[P_BERSERK], -1 * _min(u->number, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_cursed(u->attribs, C_OLDRACE, 0)) {
|
|
|
|
curse *c = get_curse(u->attribs, ct_find("oldrace"));
|
|
|
|
if (c->duration == 1 && !(c_flags(c) & CURSE_NOAGE)) {
|
|
|
|
u_setrace(u, get_race(curse_geteffect_int(c)));
|
|
|
|
u->irace = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Borders */
|
|
|
|
age_borders();
|
|
|
|
|
|
|
|
/* Factions */
|
|
|
|
for (f = factions; f; f = f->next) {
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&f->attribs, f);
|
2014-07-23 08:10:14 +02:00
|
|
|
handle_event(f->attribs, "timer", f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Regionen */
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
building **bp;
|
|
|
|
unit **up;
|
|
|
|
ship **sp;
|
|
|
|
|
|
|
|
age_region(r);
|
|
|
|
|
|
|
|
/* Einheiten */
|
|
|
|
for (up = &r->units; *up;) {
|
|
|
|
unit *u = *up;
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&u->attribs, u);
|
2016-11-23 18:56:40 +01:00
|
|
|
if (u == *up)
|
2014-07-23 08:10:14 +02:00
|
|
|
handle_event(u->attribs, "timer", u);
|
2016-11-23 18:56:40 +01:00
|
|
|
if (u == *up) //-V581
|
2014-07-23 08:10:14 +02:00
|
|
|
up = &(*up)->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Schiffe */
|
|
|
|
for (sp = &r->ships; *sp;) {
|
|
|
|
ship *s = *sp;
|
2015-12-16 22:18:44 +01:00
|
|
|
a_age(&s->attribs, s);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (s == *sp)
|
|
|
|
handle_event(s->attribs, "timer", s);
|
2016-11-23 18:56:40 +01:00
|
|
|
if (s == *sp) //-V581
|
2014-07-23 08:10:14 +02:00
|
|
|
sp = &(*sp)->next;
|
|
|
|
}
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* Gebäude */
|
2014-07-23 08:10:14 +02:00
|
|
|
for (bp = &r->buildings; *bp;) {
|
|
|
|
building *b = *bp;
|
|
|
|
age_building(b);
|
|
|
|
if (b == *bp)
|
|
|
|
bp = &b->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rule_region_owners()) {
|
|
|
|
update_owners(r);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int maxunits(const faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int flimit = rule_faction_limit();
|
|
|
|
int alimit = rule_alliance_limit();
|
|
|
|
if (alimit == 0) {
|
|
|
|
return flimit;
|
|
|
|
}
|
|
|
|
if (flimit == 0) {
|
|
|
|
return alimit;
|
|
|
|
}
|
|
|
|
return _min(alimit, flimit);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int checkunitnumber(const faction * f, int add)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-05-25 05:25:06 +02:00
|
|
|
int alimit, flimit;
|
2014-07-23 08:10:14 +02:00
|
|
|
int flags = COUNT_DEFAULT | COUNT_MIGRANTS | COUNT_UNITS;
|
2014-05-25 05:25:06 +02:00
|
|
|
int fno = count_faction(f, flags) + add;
|
|
|
|
flimit = rule_faction_limit();
|
|
|
|
if (flimit && fno > flimit) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
alimit = rule_alliance_limit();
|
|
|
|
if (alimit) {
|
|
|
|
/* if unitsperalliance is true, maxunits returns the
|
|
|
|
number of units allowed in an alliance */
|
|
|
|
faction *f2;
|
|
|
|
int unitsinalliance = fno;
|
2014-06-01 11:07:22 +02:00
|
|
|
if (unitsinalliance > alimit) {
|
|
|
|
return 1;
|
|
|
|
}
|
2014-05-25 05:25:06 +02:00
|
|
|
|
|
|
|
for (f2 = factions; f2; f2 = f2->next) {
|
|
|
|
if (f != f2 && f->alliance == f2->alliance) {
|
|
|
|
unitsinalliance += count_faction(f2, flags);
|
|
|
|
if (unitsinalliance > alimit) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-25 05:25:06 +02:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
void new_units(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r;
|
|
|
|
unit *u, *u2;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* neue einheiten werden gemacht und ihre befehle (bis zum "ende" zu
|
|
|
|
* ihnen rueberkopiert, damit diese einheiten genauso wie die alten
|
|
|
|
* einheiten verwendet werden koennen. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
order **ordp = &u->orders;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* this needs to happen very early in the game somewhere. since this is
|
|
|
|
** pretty much the first function called per turn, and I am lazy, I
|
|
|
|
** decree that it goes here */
|
|
|
|
if (u->flags & UFL_GUARD) {
|
|
|
|
fset(r, RF_GUARDED);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*ordp) {
|
2014-07-23 08:10:14 +02:00
|
|
|
order *makeord = *ordp;
|
2014-08-16 11:41:19 +02:00
|
|
|
if (getkeyword(makeord) == K_MAKETEMP) {
|
2014-12-22 14:30:04 +01:00
|
|
|
char token[128], *name = NULL;
|
|
|
|
const char *s;
|
2014-08-16 11:41:19 +02:00
|
|
|
int alias;
|
|
|
|
ship *sh;
|
|
|
|
order **newordersp;
|
|
|
|
int err = checkunitnumber(u->faction, 1);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
if (err == 1) {
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, makeord,
|
2015-11-22 16:14:27 +01:00
|
|
|
"too_many_units_in_alliance",
|
|
|
|
"allowed", maxunits(u->faction)));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2014-08-16 11:41:19 +02:00
|
|
|
else {
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
msg_feedback(u, makeord,
|
2015-11-22 16:14:27 +01:00
|
|
|
"too_many_units_in_faction",
|
|
|
|
"allowed", maxunits(u->faction)));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
ordp = &makeord->next;
|
2014-08-16 11:41:19 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
while (*ordp) {
|
|
|
|
order *ord = *ordp;
|
|
|
|
if (getkeyword(ord) == K_END)
|
|
|
|
break;
|
|
|
|
*ordp = ord->next;
|
|
|
|
ord->next = NULL;
|
2014-08-16 11:41:19 +02:00
|
|
|
free_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2014-08-16 11:41:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-08-23 06:45:20 +02:00
|
|
|
init_order(makeord);
|
2014-08-16 11:41:19 +02:00
|
|
|
alias = getid();
|
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-12-22 14:30:04 +01:00
|
|
|
if (s && s[0]) {
|
|
|
|
name = _strdup(s);
|
2014-08-16 11:41:19 +02:00
|
|
|
}
|
|
|
|
u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u);
|
|
|
|
if (name != NULL)
|
2015-06-19 13:17:01 +02:00
|
|
|
free(name); // TODO: use a buffer on the stack instead?
|
2014-08-16 11:41:19 +02:00
|
|
|
fset(u2, UFL_ISNEW);
|
|
|
|
|
|
|
|
a_add(&u2->attribs, a_new(&at_alias))->data.i = alias;
|
|
|
|
sh = leftship(u);
|
|
|
|
if (sh) {
|
|
|
|
set_leftship(u2, sh);
|
|
|
|
}
|
|
|
|
setstatus(u2, u->status);
|
|
|
|
|
|
|
|
ordp = &makeord->next;
|
|
|
|
newordersp = &u2->orders;
|
|
|
|
while (*ordp) {
|
|
|
|
order *ord = *ordp;
|
|
|
|
if (getkeyword(ord) == K_END)
|
|
|
|
break;
|
|
|
|
*ordp = ord->next;
|
|
|
|
ord->next = NULL;
|
|
|
|
*newordersp = ord;
|
|
|
|
newordersp = &ord->next;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*ordp == makeord)
|
|
|
|
ordp = &makeord->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
void update_long_order(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
order *ord;
|
2015-08-04 22:47:55 +02:00
|
|
|
bool exclusive = true;
|
|
|
|
keyword_t thiskwd = NOKEYWORD;
|
2014-07-23 08:10:14 +02:00
|
|
|
bool hunger = LongHunger(u);
|
|
|
|
|
|
|
|
freset(u, UFL_MOVED);
|
|
|
|
freset(u, UFL_LONGACTION);
|
2015-08-04 22:47:55 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* check all orders for a potential new long order this round: */
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
2015-08-04 22:47:55 +02:00
|
|
|
keyword_t kwd = getkeyword(ord);
|
|
|
|
if (kwd == NOKEYWORD) continue;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2015-08-04 22:47:55 +02:00
|
|
|
if (u->old_orders && is_repeated(kwd)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
/* this new order will replace the old defaults */
|
|
|
|
free_orders(&u->old_orders);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-08-04 22:47:55 +02:00
|
|
|
// hungry units do not get long orders:
|
2015-11-22 16:14:27 +01:00
|
|
|
if (hunger) {
|
2015-08-04 22:47:55 +02:00
|
|
|
if (u->old_orders) {
|
|
|
|
// keep looking for repeated orders that might clear the old_orders
|
|
|
|
continue;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2015-08-04 22:47:55 +02:00
|
|
|
if (is_long(kwd)) {
|
|
|
|
if (thiskwd == NOKEYWORD) {
|
|
|
|
// we have found the (first) long order
|
|
|
|
// some long orders can have multiple instances:
|
|
|
|
switch (kwd) {
|
|
|
|
/* Wenn gehandelt wird, darf kein langer Befehl ausgeführt
|
|
|
|
* werden. Da Handel erst nach anderen langen Befehlen kommt,
|
|
|
|
* muss das vorher abgefangen werden. Wir merken uns also
|
|
|
|
* hier, ob die Einheit handelt. */
|
|
|
|
case K_BUY:
|
|
|
|
case K_SELL:
|
|
|
|
case K_CAST:
|
|
|
|
// non-exclusive orders can be used with others. BUY can be paired with SELL,
|
|
|
|
// CAST with other CAST orders. compatibility is checked once the second
|
|
|
|
// long order is analyzed (below).
|
|
|
|
exclusive = false;
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2015-08-04 22:47:55 +02:00
|
|
|
default:
|
|
|
|
set_order(&u->thisorder, copy_order(ord));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
thiskwd = kwd;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we have found a second long order. this is okay for some, but not all commands.
|
|
|
|
// u->thisorder is already set, and should not have to be updated.
|
|
|
|
switch (kwd) {
|
|
|
|
case K_CAST:
|
|
|
|
if (thiskwd != K_CAST) {
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case K_SELL:
|
|
|
|
if (thiskwd != K_SELL && thiskwd != K_BUY) {
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case K_BUY:
|
|
|
|
if (thiskwd != K_SELL) {
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
thiskwd = K_BUY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-08-04 23:04:00 +02:00
|
|
|
// TODO: decide https://bugs.eressea.de/view.php?id=2080#c6011
|
|
|
|
if (kwd > thiskwd) {
|
|
|
|
// swap out thisorder for the new one
|
|
|
|
cmistake(u, u->thisorder, 52, MSG_EVENT);
|
|
|
|
set_order(&u->thisorder, copy_order(ord));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
2015-08-04 22:47:55 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
if (hunger) {
|
2015-08-04 22:47:55 +02:00
|
|
|
// Hungernde Einheiten führen NUR den default-Befehl aus
|
|
|
|
set_order(&u->thisorder, default_order(u->faction->locale));
|
2015-11-22 16:14:27 +01:00
|
|
|
}
|
|
|
|
else if (!exclusive) {
|
2015-08-04 22:47:55 +02:00
|
|
|
// Wenn die Einheit handelt oder zaubert, muss der Default-Befehl gelöscht werden.
|
2014-07-23 08:10:14 +02:00
|
|
|
set_order(&u->thisorder, NULL);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-24 07:43:11 +02:00
|
|
|
static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int i;
|
2015-11-27 15:23:48 +01:00
|
|
|
int target = -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-27 15:23:48 +01:00
|
|
|
if (itype->useonother) {
|
|
|
|
target = read_unitid(u->faction, u->region);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-27 15:23:48 +01:00
|
|
|
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (amount > i) {
|
2015-05-24 07:17:23 +02:00
|
|
|
/* TODO: message? eg. "not enough %, using only %" */
|
2014-07-23 08:10:14 +02:00
|
|
|
amount = i;
|
|
|
|
}
|
|
|
|
if (amount == 0) {
|
|
|
|
return ENOITEM;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (target == -1) {
|
2015-11-27 15:23:48 +01:00
|
|
|
if (itype->use) {
|
|
|
|
int result = itype->use(u, itype, amount, ord);
|
|
|
|
if (result > 0) {
|
|
|
|
use_pooled(u, itype->rtype, GET_DEFAULT, result);
|
|
|
|
}
|
|
|
|
return result;
|
2015-05-24 07:17:23 +02:00
|
|
|
}
|
2015-11-27 15:23:48 +01:00
|
|
|
return EUNUSABLE;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
else {
|
|
|
|
return itype->useonother(u, target, itype, amount, ord);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static double heal_factor(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-09-22 09:08:02 +02:00
|
|
|
const race * rc = u_race(u);
|
|
|
|
if (rc->healing>0) {
|
|
|
|
return rc->healing;
|
|
|
|
}
|
|
|
|
if (r_isforest(u->region)) {
|
|
|
|
static int rc_cache;
|
|
|
|
static const race *rc_elf;
|
2016-09-22 09:37:54 +02:00
|
|
|
if (rc_changed(&rc_cache)) {
|
|
|
|
rc_elf = get_race(RC_ELF);
|
|
|
|
}
|
2016-09-22 09:08:02 +02:00
|
|
|
if (rc==rc_elf) {
|
|
|
|
static int config;
|
|
|
|
static double elf_regen = 1.0;
|
|
|
|
if (config_changed(&config)) {
|
|
|
|
elf_regen = get_param_flt(u_race(u)->parameters, "regen.forest", 1.0F);
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return elf_regen;
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 09:08:02 +02:00
|
|
|
return 1.0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-18 07:31:30 +02:00
|
|
|
void monthly_healing(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r;
|
2016-08-29 21:02:39 +02:00
|
|
|
const curse_type *heal_ct = ct_find("healingzone");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
unit *u;
|
|
|
|
double healingcurse = 0;
|
|
|
|
|
2016-08-29 21:02:39 +02:00
|
|
|
if (r->attribs && heal_ct) {
|
2015-07-06 19:53:09 +02:00
|
|
|
/* bonus zurücksetzen */
|
2014-07-23 08:10:14 +02:00
|
|
|
curse *c = get_curse(r->attribs, heal_ct);
|
|
|
|
if (c != NULL) {
|
|
|
|
healingcurse = curse_geteffect(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
int umhp = unit_max_hp(u) * u->number;
|
|
|
|
double p = 1.0;
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* hp über Maximum bauen sich ab. Wird zb durch Elixier der Macht
|
|
|
|
* oder verändertes Ausdauertalent verursacht */
|
2014-07-23 08:10:14 +02:00
|
|
|
if (u->hp > umhp) {
|
|
|
|
u->hp -= (int)ceil((u->hp - umhp) / 2.0);
|
|
|
|
if (u->hp < umhp)
|
|
|
|
u->hp = umhp;
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (u_race(u)->flags & RCF_NOHEAL)
|
|
|
|
continue;
|
|
|
|
if (fval(u, UFL_HUNGER))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fval(r->terrain, SEA_REGION) && u->ship == NULL
|
|
|
|
&& !(canswim(u) || canfly(u))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
p *= heal_factor(u);
|
|
|
|
if (u->hp < umhp) {
|
|
|
|
double maxheal = _max(u->number, umhp / 20.0);
|
|
|
|
int addhp;
|
2015-11-16 02:13:48 +01:00
|
|
|
if (active_building(u, bt_find("inn"))) {
|
2014-07-23 08:10:14 +02:00
|
|
|
p *= 1.5;
|
|
|
|
}
|
2015-07-06 19:53:09 +02:00
|
|
|
/* pro punkt 5% höher */
|
2014-07-23 08:10:14 +02:00
|
|
|
p *= (1.0 + healingcurse * 0.05);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
maxheal = p * maxheal;
|
|
|
|
addhp = (int)maxheal;
|
|
|
|
maxheal -= addhp;
|
|
|
|
if (maxheal > 0.0 && chance(maxheal))
|
|
|
|
++addhp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
/* Aufaddieren der geheilten HP. */
|
|
|
|
u->hp = _min(u->hp + addhp, umhp);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* soll man an negativer regeneration sterben können? */
|
2014-07-23 08:10:14 +02:00
|
|
|
assert(u->hp > 0);
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void remove_exclusive(order ** ordp)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
while (*ordp) {
|
|
|
|
order *ord = *ordp;
|
|
|
|
if (is_exclusive(ord)) {
|
|
|
|
*ordp = ord->next;
|
|
|
|
ord->next = NULL;
|
|
|
|
free_order(ord);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ordp = &ord->next;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
void defaultorders(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
region *r;
|
2012-07-24 09:16:25 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
assert(!keyword_disabled(K_DEFAULT));
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
unit *u;
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
bool neworders = false;
|
|
|
|
order **ordp = &u->orders;
|
|
|
|
while (*ordp != NULL) {
|
|
|
|
order *ord = *ordp;
|
|
|
|
if (getkeyword(ord) == K_DEFAULT) {
|
|
|
|
char lbuf[8192];
|
2014-08-24 12:40:00 +02:00
|
|
|
order *new_order = 0;
|
|
|
|
const char *s;
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(lbuf, sizeof(lbuf));
|
2014-08-24 12:40:00 +02:00
|
|
|
if (s) {
|
2014-12-22 14:30:04 +01:00
|
|
|
new_order = parse_order(s, u->faction->locale);
|
2014-08-24 12:40:00 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
*ordp = ord->next;
|
|
|
|
ord->next = NULL;
|
|
|
|
free_order(ord);
|
|
|
|
if (!neworders) {
|
2015-07-06 19:53:09 +02:00
|
|
|
/* lange Befehle aus orders und old_orders löschen zu gunsten des neuen */
|
2015-08-04 22:47:55 +02:00
|
|
|
// TODO: why only is_exclusive, not is_long? what about CAST, BUY, SELL?
|
2014-07-23 08:10:14 +02:00
|
|
|
remove_exclusive(&u->orders);
|
|
|
|
remove_exclusive(&u->old_orders);
|
|
|
|
neworders = true;
|
|
|
|
ordp = &u->orders; /* we could have broken ordp */
|
|
|
|
}
|
|
|
|
if (new_order)
|
|
|
|
addlist(&u->old_orders, new_order);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ordp = &ord->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************ */
|
2013-05-02 03:42:20 +02:00
|
|
|
/* GANZ WICHTIG! ALLE GEAENDERTEN SPRUECHE NEU ANZEIGEN */
|
|
|
|
/* GANZ WICHTIG! FUEGT AUCH NEUE ZAUBER IN DIE LISTE DER BEKANNTEN EIN */
|
2010-08-08 10:06:34 +02:00
|
|
|
/* ************************************************************ */
|
2012-05-24 09:56:54 +02:00
|
|
|
#define COMMONSPELLS 1 /* number of new common spells per level */
|
2011-03-07 08:02:35 +01:00
|
|
|
#define MAXMAGES 128 /* should be enough */
|
2012-05-26 09:33:55 +02:00
|
|
|
|
|
|
|
static int faction_getmages(faction * f, unit ** results, int numresults)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
unit *u;
|
|
|
|
int maxlevel = 0, n = 0;
|
|
|
|
|
|
|
|
for (u = f->units; u; u = u->nextF) {
|
|
|
|
if (u->number > 0) {
|
|
|
|
sc_mage *mage = get_mage(u);
|
|
|
|
if (mage) {
|
2015-08-27 16:16:55 +02:00
|
|
|
int level = effskill(u, SK_MAGIC, 0);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (level > maxlevel) {
|
|
|
|
maxlevel = level;
|
|
|
|
}
|
|
|
|
if (n < numresults) {
|
|
|
|
results[n++] = u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n < numresults) {
|
|
|
|
results[n] = 0;
|
|
|
|
}
|
|
|
|
return maxlevel;
|
2012-05-26 09:33:55 +02:00
|
|
|
}
|
|
|
|
|
2012-05-26 19:16:39 +02:00
|
|
|
static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
assert(dst);
|
|
|
|
if (src && src->spells) {
|
|
|
|
quicklist *ql;
|
|
|
|
int qi;
|
|
|
|
for (qi = 0, ql = src->spells; ql; ql_advance(&ql, &qi, 1)) {
|
|
|
|
spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi);
|
|
|
|
if (sbe->level <= maxlevel) {
|
|
|
|
if (!spellbook_get(dst, sbe->sp)) {
|
|
|
|
spellbook_add(dst, sbe->sp, sbe->level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-26 19:16:39 +02:00
|
|
|
}
|
2012-05-26 23:19:35 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void update_spells(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
faction *f;
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
if (f->magiegebiet != M_NONE && !is_monsters(f)) {
|
|
|
|
unit *mages[MAXMAGES];
|
|
|
|
int i;
|
|
|
|
int maxlevel = faction_getmages(f, mages, MAXMAGES);
|
|
|
|
|
|
|
|
if (maxlevel && FactionSpells()) {
|
|
|
|
spellbook * book = get_spellbook(magic_school[f->magiegebiet]);
|
|
|
|
if (!f->spellbook) {
|
|
|
|
f->spellbook = create_spellbook(0);
|
|
|
|
}
|
|
|
|
copy_spells(book, f->spellbook, maxlevel);
|
|
|
|
if (maxlevel > f->max_spelllevel) {
|
|
|
|
spellbook * common_spells = get_spellbook(magic_school[M_COMMON]);
|
|
|
|
pick_random_spells(f, maxlevel, common_spells, COMMONSPELLS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
show_new_spells(f, maxlevel, faction_get_spellbook(f));
|
|
|
|
for (i = 0; i != MAXMAGES && mages[i]; ++i) {
|
|
|
|
unit * u = mages[i];
|
|
|
|
sc_mage *mage = get_mage(u);
|
|
|
|
if (mage && mage->spellbook) {
|
2015-08-27 16:16:55 +02:00
|
|
|
int level = effskill(u, SK_MAGIC, 0);
|
2014-07-23 08:10:14 +02:00
|
|
|
show_new_spells(f, level, mage->spellbook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-13 07:36:29 +02:00
|
|
|
int use_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 14:30:04 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *t;
|
|
|
|
int n, err = ENOITEM;
|
|
|
|
const item_type *itype;
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
t = gettoken(token, sizeof(token));
|
2015-07-02 13:42:15 +02:00
|
|
|
if (!t) {
|
|
|
|
cmistake(u, ord, 43, MSG_PRODUCE);
|
|
|
|
return err;
|
|
|
|
}
|
2016-11-14 22:27:44 +01:00
|
|
|
n = atoip((const char *)t);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (n == 0) {
|
|
|
|
if (isparam(t, u->faction->locale, P_ANY)) {
|
|
|
|
/* BENUTZE ALLES Yanxspirit */
|
|
|
|
n = INT_MAX;
|
2014-12-22 16:28:17 +01:00
|
|
|
t = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* BENUTZE Yanxspirit */
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* BENUTZE 42 Yanxspirit */
|
2014-12-22 16:28:17 +01:00
|
|
|
t = gettoken(token, sizeof(token));
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2014-12-14 12:56:36 +01:00
|
|
|
itype = t ? finditemtype(t, u->faction->locale) : NULL;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (itype != NULL) {
|
|
|
|
err = use_item(u, itype, n, ord);
|
|
|
|
}
|
|
|
|
switch (err) {
|
|
|
|
case ENOITEM:
|
|
|
|
cmistake(u, ord, 43, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
case EUNUSABLE:
|
|
|
|
cmistake(u, ord, 76, MSG_PRODUCE);
|
|
|
|
break;
|
|
|
|
case ENOSKILL:
|
|
|
|
cmistake(u, ord, 50, MSG_PRODUCE);
|
|
|
|
break;
|
2015-05-24 07:43:11 +02:00
|
|
|
default:
|
|
|
|
// no error
|
|
|
|
break;
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
return err;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
int pay_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!u->building) {
|
|
|
|
cmistake(u, ord, 6, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
param_t p;
|
2014-12-17 17:22:26 +01:00
|
|
|
int id;
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
p = getparam(u->faction->locale);
|
2014-12-17 17:22:26 +01:00
|
|
|
id = getid();
|
|
|
|
building *b = NULL;
|
2014-07-23 08:10:14 +02:00
|
|
|
if (p == P_NOT) {
|
|
|
|
unit *owner = building_owner(u->building);
|
2014-12-17 17:22:26 +01:00
|
|
|
/* If the unit is not the owner of the building: error */
|
2014-07-23 08:10:14 +02:00
|
|
|
if (owner->no != u->no) {
|
2014-12-17 17:22:26 +01:00
|
|
|
/* The building is not ours error */
|
2014-07-23 08:10:14 +02:00
|
|
|
cmistake(u, ord, 1222, MSG_EVENT);
|
|
|
|
}
|
|
|
|
else {
|
2014-12-17 17:22:26 +01:00
|
|
|
/* If no building id is given or it is the id of our building, just set the do-not-pay flag */
|
|
|
|
if (id == 0 || id == u->building->no)
|
|
|
|
{
|
|
|
|
u->building->flags |= BLD_DONTPAY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Find the building that matches to the given id*/
|
|
|
|
b = findbuilding(id);
|
|
|
|
/* If there is a building and it is in the same region as the unit continue, else: error */
|
|
|
|
if (b && b->region == u->region)
|
|
|
|
{
|
|
|
|
/* If the unit is also the building owner (this is true if rules.region_owner_pay_building */
|
|
|
|
/* is set and no one is in the building) set the do-not-pay flag for this building, else: error */
|
|
|
|
if (building_owner(b) == u) {
|
|
|
|
b->flags |= BLD_DONTPAY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The building is not ours error */
|
|
|
|
cmistake(u, ord, 1222, MSG_EVENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Building not found error */
|
|
|
|
cmistake(u, ord, 6, MSG_PRODUCE);
|
|
|
|
}
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 06:19:21 +02:00
|
|
|
static int reserve_i(unit * u, struct order *ord, int flags)
|
2012-07-24 09:16:25 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2016-11-20 19:08:39 +01:00
|
|
|
if (u->number > 0 && (u_race(u)->ec_flags & GETITEM)) {
|
2014-07-28 10:29:35 +02:00
|
|
|
int use, count, para;
|
2014-12-12 11:28:37 +01:00
|
|
|
const item_type *itype;
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *s;
|
2012-07-24 09:16:25 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-08-23 09:17:58 +02:00
|
|
|
count = s ? atoip(s) : 0;
|
2014-08-08 00:25:17 +02:00
|
|
|
para = findparam(s, u->faction->locale);
|
2012-07-24 09:16:25 +02:00
|
|
|
|
2014-07-28 10:29:35 +02:00
|
|
|
if (count == 0 && para == P_EACH) {
|
2014-07-23 08:10:14 +02:00
|
|
|
count = getint() * u->number;
|
|
|
|
}
|
2014-12-22 16:28:17 +01:00
|
|
|
s = gettoken(token, sizeof(token));
|
2014-12-12 11:28:37 +01:00
|
|
|
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
|
|
|
if (itype == NULL)
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2012-07-24 09:16:25 +02:00
|
|
|
|
2014-12-12 11:28:37 +01:00
|
|
|
set_resvalue(u, itype, 0); /* make sure the pool is empty */
|
2014-07-28 10:29:35 +02:00
|
|
|
|
2014-08-08 00:25:17 +02:00
|
|
|
if (count == 0 && para == P_ANY) {
|
2014-12-12 11:28:37 +01:00
|
|
|
count = get_resource(u, itype->rtype);
|
2014-08-08 00:25:17 +02:00
|
|
|
}
|
2014-12-12 11:28:37 +01:00
|
|
|
use = use_pooled(u, itype->rtype, flags, count);
|
2014-07-23 08:10:14 +02:00
|
|
|
if (use) {
|
2014-12-12 11:28:37 +01:00
|
|
|
set_resvalue(u, itype, use);
|
|
|
|
change_resource(u, itype->rtype, use);
|
2014-07-23 08:10:14 +02:00
|
|
|
return use;
|
|
|
|
}
|
2012-07-24 09:16:25 +02:00
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
return 0;
|
2012-07-24 09:16:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 06:19:21 +02:00
|
|
|
int reserve_cmd(unit * u, struct order *ord) {
|
|
|
|
return reserve_i(u, ord, GET_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int reserve_self(unit * u, struct order *ord) {
|
|
|
|
return reserve_i(u, ord, GET_RESERVE | GET_SLACK);
|
|
|
|
}
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
int claim_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
char token[128];
|
2014-07-23 08:10:14 +02:00
|
|
|
const char *t;
|
2015-04-09 12:33:23 +02:00
|
|
|
int n = 1;
|
|
|
|
const item_type *itype = 0;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-12-22 16:28:17 +01:00
|
|
|
t = gettoken(token, sizeof(token));
|
2015-04-09 12:33:23 +02:00
|
|
|
if (t) {
|
2016-11-14 22:27:44 +01:00
|
|
|
n = atoip((const char *)t);
|
2015-04-09 12:33:23 +02:00
|
|
|
if (n == 0) {
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
t = gettoken(token, sizeof(token));
|
|
|
|
}
|
|
|
|
if (t) {
|
|
|
|
itype = finditemtype(t, u->faction->locale);
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2015-04-09 12:33:23 +02:00
|
|
|
if (itype) {
|
2014-07-23 08:10:14 +02:00
|
|
|
item **iclaim = i_find(&u->faction->items, itype);
|
2015-04-09 12:33:23 +02:00
|
|
|
if (iclaim && *iclaim) {
|
2014-07-23 08:10:14 +02:00
|
|
|
n = _min(n, (*iclaim)->number);
|
|
|
|
i_change(iclaim, itype, -n);
|
|
|
|
i_change(&u->items, itype, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmistake(u, ord, 43, MSG_PRODUCE);
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2014-07-23 08:10:14 +02:00
|
|
|
PROC_THISORDER = 1 << 0,
|
|
|
|
PROC_LONGORDER = 1 << 1
|
2010-08-08 10:06:34 +02:00
|
|
|
};
|
2012-06-16 18:17:29 +02:00
|
|
|
|
|
|
|
typedef enum { PR_GLOBAL, PR_REGION_PRE, PR_UNIT, PR_ORDER, PR_REGION_POST } processor_t;
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
typedef struct processor {
|
2014-07-23 08:10:14 +02:00
|
|
|
struct processor *next;
|
|
|
|
int priority;
|
|
|
|
processor_t type;
|
|
|
|
unsigned int flags;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
keyword_t kword;
|
|
|
|
int(*process) (struct unit *, struct order *);
|
|
|
|
} per_order;
|
|
|
|
struct {
|
|
|
|
void(*process) (struct unit *);
|
|
|
|
} per_unit;
|
|
|
|
struct {
|
|
|
|
void(*process) (struct region *);
|
|
|
|
} per_region;
|
|
|
|
struct {
|
|
|
|
void(*process) (void);
|
|
|
|
} global;
|
|
|
|
} data;
|
|
|
|
const char *name;
|
2010-08-08 10:06:34 +02:00
|
|
|
} processor;
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static processor *processors;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2012-06-16 18:17:29 +02:00
|
|
|
static processor *add_proc(int priority, const char *name, processor_t type)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
processor **pproc = &processors;
|
|
|
|
processor *proc;
|
|
|
|
|
|
|
|
while (*pproc) {
|
|
|
|
proc = *pproc;
|
|
|
|
if (proc->priority > priority)
|
|
|
|
break;
|
|
|
|
else if (proc->priority == priority && proc->type >= type)
|
|
|
|
break;
|
|
|
|
pproc = &proc->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
proc = (processor *)malloc(sizeof(processor));
|
|
|
|
proc->priority = priority;
|
|
|
|
proc->type = type;
|
|
|
|
proc->name = name;
|
|
|
|
proc->next = *pproc;
|
|
|
|
*pproc = proc;
|
|
|
|
return proc;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-23 08:10:14 +02:00
|
|
|
add_proc_order(int priority, keyword_t kword, int(*parser) (struct unit *,
|
|
|
|
struct order *), unsigned int flags, const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!keyword_disabled(kword)) {
|
|
|
|
processor *proc = add_proc(priority, name, PR_ORDER);
|
|
|
|
if (proc) {
|
|
|
|
proc->data.per_order.process = parser;
|
|
|
|
proc->data.per_order.kword = kword;
|
|
|
|
proc->flags = flags;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
void add_proc_global(int priority, void(*process) (void), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
processor *proc = add_proc(priority, name, PR_GLOBAL);
|
|
|
|
if (proc) {
|
|
|
|
proc->data.global.process = process;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
void add_proc_region(int priority, void(*process) (region *), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
processor *proc = add_proc(priority, name, PR_REGION_PRE);
|
|
|
|
if (proc) {
|
|
|
|
proc->data.per_region.process = process;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-23 08:10:14 +02:00
|
|
|
add_proc_postregion(int priority, void(*process) (region *), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
processor *proc = add_proc(priority, name, PR_REGION_POST);
|
|
|
|
if (proc) {
|
|
|
|
proc->data.per_region.process = process;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
void add_proc_unit(int priority, void(*process) (unit *), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
processor *proc = add_proc(priority, name, PR_UNIT);
|
|
|
|
if (proc) {
|
|
|
|
proc->data.per_unit.process = process;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* per priority, execute processors in order from PR_GLOBAL down to PR_ORDER */
|
2011-03-07 08:02:35 +01:00
|
|
|
void process(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
processor *proc = processors;
|
|
|
|
faction *f;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
while (proc) {
|
|
|
|
int prio = proc->priority;
|
|
|
|
region *r;
|
|
|
|
processor *pglobal = proc;
|
|
|
|
|
2015-09-12 20:58:09 +02:00
|
|
|
log_debug("- Step %u", prio);
|
2014-07-23 08:10:14 +02:00
|
|
|
while (proc && proc->priority == prio) {
|
2015-09-12 20:58:09 +02:00
|
|
|
if (proc->name)
|
|
|
|
log_debug(" - %s", proc->name);
|
2014-07-23 08:10:14 +02:00
|
|
|
proc = proc->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
while (pglobal && pglobal->priority == prio && pglobal->type == PR_GLOBAL) {
|
|
|
|
pglobal->data.global.process();
|
|
|
|
pglobal = pglobal->next;
|
|
|
|
}
|
|
|
|
if (pglobal == NULL || pglobal->priority != prio)
|
2011-03-07 08:02:35 +01:00
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
unit *u;
|
|
|
|
processor *pregion = pglobal;
|
|
|
|
|
|
|
|
while (pregion && pregion->priority == prio
|
|
|
|
&& pregion->type == PR_REGION_PRE) {
|
|
|
|
pregion->data.per_region.process(r);
|
|
|
|
pregion = pregion->next;
|
|
|
|
}
|
|
|
|
if (pregion == NULL || pregion->priority != prio)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (r->units) {
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
processor *porder, *punit = pregion;
|
|
|
|
|
|
|
|
while (punit && punit->priority == prio && punit->type == PR_UNIT) {
|
|
|
|
punit->data.per_unit.process(u);
|
|
|
|
punit = punit->next;
|
|
|
|
}
|
|
|
|
if (punit == NULL || punit->priority != prio)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
porder = punit;
|
|
|
|
while (porder && porder->priority == prio && porder->type == PR_ORDER) {
|
|
|
|
order **ordp = &u->orders;
|
|
|
|
if (porder->flags & PROC_THISORDER)
|
|
|
|
ordp = &u->thisorder;
|
|
|
|
while (*ordp) {
|
|
|
|
order *ord = *ordp;
|
|
|
|
if (getkeyword(ord) == porder->data.per_order.kword) {
|
|
|
|
if (porder->flags & PROC_LONGORDER) {
|
|
|
|
if (u->number == 0) {
|
|
|
|
ord = NULL;
|
|
|
|
}
|
|
|
|
else if (u_race(u) == get_race(RC_INSECT)
|
|
|
|
&& r_insectstalled(r)
|
|
|
|
&& !is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) {
|
|
|
|
ord = NULL;
|
|
|
|
}
|
|
|
|
else if (LongHunger(u)) {
|
|
|
|
cmistake(u, ord, 224, MSG_MAGIC);
|
|
|
|
ord = NULL;
|
|
|
|
}
|
|
|
|
else if (fval(u, UFL_LONGACTION)) {
|
|
|
|
/* this message was already given in laws.update_long_order
|
|
|
|
cmistake(u, ord, 52, MSG_PRODUCE);
|
|
|
|
*/
|
|
|
|
ord = NULL;
|
|
|
|
}
|
|
|
|
else if (fval(r->terrain, SEA_REGION)
|
|
|
|
&& u_race(u) != get_race(RC_AQUARIAN)
|
|
|
|
&& !(u_race(u)->flags & RCF_SWIM)) {
|
|
|
|
/* error message disabled by popular demand */
|
|
|
|
ord = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ord) {
|
|
|
|
porder->data.per_order.process(u, ord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ord || *ordp == ord)
|
|
|
|
ordp = &(*ordp)->next;
|
|
|
|
}
|
|
|
|
porder = porder->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
while (pregion && pregion->priority == prio
|
|
|
|
&& pregion->type != PR_REGION_POST) {
|
|
|
|
pregion = pregion->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
while (pregion && pregion->priority == prio
|
|
|
|
&& pregion->type == PR_REGION_POST) {
|
|
|
|
pregion->data.per_region.process(r);
|
|
|
|
pregion = pregion->next;
|
|
|
|
}
|
|
|
|
if (pregion == NULL || pregion->priority != prio)
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-09-12 19:48:03 +02:00
|
|
|
log_debug("\n - Leere Gruppen loeschen...\n");
|
2014-07-23 08:10:14 +02:00
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
group **gp = &f->groups;
|
|
|
|
while (*gp) {
|
|
|
|
group *g = *gp;
|
|
|
|
if (g->members == 0) {
|
|
|
|
*gp = g->next;
|
|
|
|
free_group(g);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gp = &g->next;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-01 18:34:53 +01:00
|
|
|
int armedmen(const unit * u, bool siege_weapons)
|
|
|
|
{
|
|
|
|
item *itm;
|
|
|
|
int n = 0;
|
2016-11-20 19:08:39 +01:00
|
|
|
if (!(u_race(u)->flags & RCF_NOWEAPONS)) {
|
2015-08-27 16:16:55 +02:00
|
|
|
if (effskill(u, SK_WEAPONLESS, 0) >= 1) {
|
2014-11-01 18:34:53 +01:00
|
|
|
/* kann ohne waffen bewachen: fuer drachen */
|
|
|
|
n = u->number;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* alle Waffen werden gezaehlt, und dann wird auf die Anzahl
|
|
|
|
* Personen minimiert */
|
|
|
|
for (itm = u->items; itm; itm = itm->next) {
|
|
|
|
const weapon_type *wtype = resource2weapon(itm->type->rtype);
|
|
|
|
if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE)))
|
|
|
|
continue;
|
2015-08-27 16:16:55 +02:00
|
|
|
if (effskill(u, wtype->skill, 0) >= wtype->minskill)
|
2014-11-01 18:34:53 +01:00
|
|
|
n += itm->number;
|
|
|
|
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
2016-10-25 00:04:33 +02:00
|
|
|
if (n >= u->number)
|
2014-11-01 18:34:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
n = _min(n, u->number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-06-17 04:14:23 +02:00
|
|
|
int siege_cmd(unit * u, order * ord)
|
|
|
|
{
|
2014-06-24 16:42:45 +02:00
|
|
|
region *r = u->region;
|
|
|
|
building *b;
|
|
|
|
int d, pooled;
|
|
|
|
int bewaffnete, katapultiere = 0;
|
|
|
|
const curse_type *magicwalls_ct;
|
2014-06-25 07:44:05 +02:00
|
|
|
resource_type *rt_catapultammo = NULL;
|
|
|
|
resource_type *rt_catapult = NULL;
|
2012-06-17 04:14:23 +02:00
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
init_order(ord);
|
2014-06-24 16:42:45 +02:00
|
|
|
b = getbuilding(r);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
if (!b) {
|
|
|
|
cmistake(u, ord, 31, MSG_BATTLE);
|
|
|
|
return 31;
|
|
|
|
}
|
2012-06-17 04:14:23 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
if (!playerrace(u_race(u))) {
|
|
|
|
/* keine Drachen, Illusionen, Untote etc */
|
|
|
|
cmistake(u, ord, 166, MSG_BATTLE);
|
|
|
|
return 166;
|
|
|
|
}
|
|
|
|
/* schaden durch katapulte */
|
2012-06-17 04:14:23 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
magicwalls_ct = ct_find("magicwalls");
|
2014-06-25 07:44:05 +02:00
|
|
|
rt_catapultammo = rt_find("catapultammo");
|
|
|
|
rt_catapult = rt_find("catapult");
|
2012-06-17 04:14:23 +02:00
|
|
|
|
2014-06-25 07:44:05 +02:00
|
|
|
d = i_get(u->items, rt_catapult->itype);
|
2014-06-24 16:42:45 +02:00
|
|
|
d = _min(u->number, d);
|
2014-06-25 07:44:05 +02:00
|
|
|
pooled = get_pooled(u, rt_catapultammo, GET_DEFAULT, d);
|
2014-06-24 16:42:45 +02:00
|
|
|
d = _min(pooled, d);
|
2015-08-27 16:16:55 +02:00
|
|
|
if (effskill(u, SK_CATAPULT, 0) >= 1) {
|
2014-06-24 16:42:45 +02:00
|
|
|
katapultiere = d;
|
2015-08-27 16:16:55 +02:00
|
|
|
d *= effskill(u, SK_CATAPULT, 0);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-06-24 16:42:45 +02:00
|
|
|
d = 0;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
bewaffnete = armedmen(u, true);
|
|
|
|
if (d == 0 && bewaffnete == 0) {
|
|
|
|
/* abbruch, falls unbewaffnet oder unfaehig, katapulte zu benutzen */
|
|
|
|
cmistake(u, ord, 80, MSG_EVENT);
|
|
|
|
return 80;
|
|
|
|
}
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2016-10-31 07:45:06 +01:00
|
|
|
if (!is_guard(u)) {
|
2014-06-24 16:42:45 +02:00
|
|
|
/* abbruch, wenn die einheit nicht vorher die region bewacht - als
|
|
|
|
* warnung fuer alle anderen! */
|
|
|
|
cmistake(u, ord, 81, MSG_EVENT);
|
|
|
|
return 81;
|
|
|
|
}
|
|
|
|
/* einheit und burg markieren - spart zeit beim behandeln der einheiten
|
|
|
|
* in der burg, falls die burg auch markiert ist und nicht alle
|
|
|
|
* einheiten wieder abgesucht werden muessen! */
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
usetsiege(u, b);
|
|
|
|
b->besieged += _max(bewaffnete, katapultiere);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
/* definitiver schaden eingeschraenkt */
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
d = _min(d, b->size - 1);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2014-06-24 16:42:45 +02:00
|
|
|
/* meldung, schaden anrichten */
|
|
|
|
if (d && !curse_active(get_curse(b->attribs, magicwalls_ct))) {
|
|
|
|
b->size -= d;
|
2014-06-25 07:44:05 +02:00
|
|
|
use_pooled(u, rt_catapultammo,
|
2014-07-23 08:10:14 +02:00
|
|
|
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, d);
|
2014-06-24 16:42:45 +02:00
|
|
|
/* send message to the entire region */
|
|
|
|
ADDMSG(&r->msgs, msg_message("siege_catapults",
|
2014-07-23 08:10:14 +02:00
|
|
|
"unit building destruction", u, b, d));
|
|
|
|
}
|
|
|
|
else {
|
2014-06-24 16:42:45 +02:00
|
|
|
/* send message to the entire region */
|
|
|
|
ADDMSG(&r->msgs, msg_message("siege", "unit building", u, b));
|
|
|
|
}
|
|
|
|
return 0;
|
2012-06-17 04:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_siege(region * r)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
if (fval(r->terrain, LAND_REGION)) {
|
|
|
|
unit *u;
|
2012-06-17 04:14:23 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
if (getkeyword(u->thisorder) == K_BESIEGE) {
|
|
|
|
siege_cmd(u, u->thisorder);
|
|
|
|
}
|
|
|
|
}
|
2012-06-17 04:14:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void enter_1(region * r)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
do_enter(r, 0);
|
2011-03-07 08:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void enter_2(region * r)
|
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
do_enter(r, 1);
|
2011-03-07 08:02:35 +01:00
|
|
|
}
|
|
|
|
|
2015-06-20 14:28:16 +02:00
|
|
|
bool help_enter(unit *uo, unit *u) {
|
2015-01-05 18:14:55 +01:00
|
|
|
return uo->faction == u->faction || alliedunit(uo, u->faction, HELP_GUARD);
|
|
|
|
}
|
|
|
|
|
2015-06-20 14:28:16 +02:00
|
|
|
static void do_force_leave(region *r) {
|
2015-06-26 14:31:21 +02:00
|
|
|
force_leave(r, NULL);
|
2015-01-05 18:14:55 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 07:53:11 +02:00
|
|
|
bool rule_force_leave(int flags) {
|
2015-11-22 10:44:46 +01:00
|
|
|
int rules = config_get_int("rules.owners.force_leave", 0);
|
2015-06-19 07:53:11 +02:00
|
|
|
return (rules&flags) == flags;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void init_processor(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
int p;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-06-26 14:31:21 +02:00
|
|
|
while (processors) {
|
|
|
|
processor * next = processors->next;
|
|
|
|
free(processors);
|
|
|
|
processors = next;
|
|
|
|
}
|
2015-06-19 13:17:01 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p = 10;
|
2015-07-03 15:31:57 +02:00
|
|
|
add_proc_global(p, nmr_warnings, "NMR Warnings");
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_global(p, new_units, "Neue Einheiten erschaffen");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
|
|
|
add_proc_unit(p, update_long_order, "Langen Befehl aktualisieren");
|
|
|
|
add_proc_order(p, K_BANNER, banner_cmd, 0, NULL);
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_order(p, K_EMAIL, email_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_PASSWORD, password_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_SEND, send_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_GROUP, group_cmd, 0, NULL);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_QUIT, quit_cmd, 0, NULL);
|
2015-05-19 08:02:32 +02:00
|
|
|
add_proc_order(p, K_URSPRUNG, origin_cmd, 0, NULL);
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_ALLY, ally_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_PREFIX, prefix_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_SETSTEALTH, setstealth_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_STATUS, status_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_COMBATSPELL, combatspell_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_DISPLAY, display_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_NAME, name_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_GUARD, guard_off_cmd, 0, NULL);
|
|
|
|
add_proc_order(p, K_RESHOW, reshow_cmd, 0, NULL);
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("rules.alliances", 0) == 1) {
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_global(p, alliance_cmd, NULL);
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
|
|
|
add_proc_region(p, do_contact, "Kontaktieren");
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_order(p, K_MAIL, mail_cmd, 0, "Botschaften");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10; /* all claims must be done before we can USE */
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_region(p, enter_1, "Betreten (1. Versuch)"); /* for GIVE CONTROL */
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_order(p, K_USE, use_cmd, 0, "Benutzen");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10; /* in case it has any effects on alliance victories */
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_order(p, K_GIVE, give_control_cmd, 0, "GIB KOMMANDO");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10; /* in case it has any effects on alliance victories */
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_order(p, K_LEAVE, leave_cmd, 0, "Verlassen");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-08 00:34:55 +02:00
|
|
|
p += 10;
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_region(p, enter_1, "Betreten (2. Versuch)"); /* to allow a buildingowner to enter the castle pre combat */
|
2014-07-28 11:16:45 +02:00
|
|
|
|
2014-08-08 00:34:55 +02:00
|
|
|
p += 10;
|
2015-11-22 15:29:43 +01:00
|
|
|
add_proc_global(p, do_battles, "Attackieren");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!keyword_disabled(K_BESIEGE)) {
|
|
|
|
p += 10;
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_region(p, do_siege, "Belagern");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10; /* can't allow reserve before siege (weapons) */
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_region(p, enter_1, "Betreten (3. Versuch)"); /* to claim a castle after a victory and to be able to DESTROY it in the same turn */
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("rules.reserve.twophase", 0)) {
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_RESERVE, reserve_self, 0, "RESERVE (self)");
|
2014-08-08 00:25:17 +02:00
|
|
|
p += 10;
|
2014-08-01 13:12:18 +02:00
|
|
|
}
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_RESERVE, reserve_cmd, 0, "RESERVE (all)");
|
|
|
|
add_proc_order(p, K_CLAIM, claim_cmd, 0, NULL);
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_unit(p, follow_unit, "Folge auf Einheiten setzen");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10; /* rest rng again before economics */
|
2015-06-19 07:53:11 +02:00
|
|
|
if (rule_force_leave(FORCE_LEAVE_ALL)) {
|
2015-06-20 14:28:16 +02:00
|
|
|
add_proc_region(p, do_force_leave, "kick non-allies out of buildings/ships");
|
2015-02-01 12:57:54 +01:00
|
|
|
}
|
2015-01-05 18:14:55 +01:00
|
|
|
add_proc_region(p, economics, "Zerstoeren, Geben, Rekrutieren, Vergessen");
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_PROMOTION, promotion_cmd, 0, "Heldenbefoerderung");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
p += 10;
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!keyword_disabled(K_PAY)) {
|
2016-08-21 18:06:38 +02:00
|
|
|
add_proc_order(p, K_PAY, pay_cmd, 0, "Gebaeudeunterhalt (BEZAHLE NICHT)");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2016-08-21 18:06:38 +02:00
|
|
|
add_proc_postregion(p, maintain_buildings, "Gebaeudeunterhalt");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10; /* QUIT fuer sich alleine */
|
|
|
|
add_proc_global(p, quit, "Sterben");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!keyword_disabled(K_CAST)) {
|
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, magic, "Zaubern");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_TEACH, teach_cmd, PROC_THISORDER | PROC_LONGORDER,
|
2014-07-23 08:10:14 +02:00
|
|
|
"Lehren");
|
|
|
|
p += 10;
|
2015-07-09 13:24:21 +02:00
|
|
|
add_proc_order(p, K_STUDY, study_cmd, PROC_THISORDER | PROC_LONGORDER,
|
2014-07-23 08:10:14 +02:00
|
|
|
"Lernen");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_MAKE, make_cmd, PROC_THISORDER | PROC_LONGORDER,
|
2014-07-23 08:10:14 +02:00
|
|
|
"Produktion");
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_postregion(p, produce, "Arbeiten, Handel, Rekruten");
|
|
|
|
add_proc_postregion(p, split_allocations, "Produktion II");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_region(p, enter_2, "Betreten (4. Versuch)"); /* Once again after QUIT */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_region(p, sinkships, "Schiffe sinken");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2012-07-09 08:27:41 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, movement, "Bewegungen");
|
2012-07-09 08:27:41 +02:00
|
|
|
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("work.auto", 0)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_region(p, auto_work, "Arbeiten (auto)");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_GUARD, guard_on_cmd, 0, "Bewache (an)");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("rules.encounters", 0)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, encounters, "Zufallsbegegnungen");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_unit(p, monster_kills_peasants,
|
2014-07-23 08:10:14 +02:00
|
|
|
"Monster fressen und vertreiben Bauern");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, randomevents, "Zufallsereignisse");
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
p += 10;
|
2014-07-23 08:10:14 +02:00
|
|
|
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, monthly_healing, "Regeneration (HP)");
|
|
|
|
add_proc_global(p, regenerate_aura, "Regeneration (Aura)");
|
2014-07-23 08:10:14 +02:00
|
|
|
if (!keyword_disabled(K_DEFAULT)) {
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, defaultorders, "Defaults setzen");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, demographics, "Nahrung, Seuchen, Wachstum, Wanderung");
|
2014-07-23 08:10:14 +02:00
|
|
|
|
|
|
|
if (!keyword_disabled(K_SORT)) {
|
|
|
|
p += 10;
|
|
|
|
add_proc_global(p, restack_units, "Einheiten sortieren");
|
|
|
|
}
|
|
|
|
if (!keyword_disabled(K_NUMBER)) {
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_order(p, K_NUMBER, renumber_cmd, 0, "Neue Nummern (Einheiten)");
|
2014-07-23 08:10:14 +02:00
|
|
|
p += 10;
|
2015-05-18 08:42:35 +02:00
|
|
|
add_proc_global(p, renumber_factions, "Neue Nummern");
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void processorders(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-06-19 13:17:01 +02:00
|
|
|
init_processor();
|
2014-07-23 08:10:14 +02:00
|
|
|
process();
|
|
|
|
/*************************************************/
|
|
|
|
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("modules.markets", 0)) {
|
2014-07-23 08:10:14 +02:00
|
|
|
do_markets();
|
|
|
|
}
|
|
|
|
|
|
|
|
log_info(" - Attribute altern");
|
|
|
|
ageing();
|
|
|
|
remove_empty_units();
|
|
|
|
|
|
|
|
/* must happen AFTER age, because that would destroy them right away */
|
2015-11-22 10:44:46 +01:00
|
|
|
if (config_get_int("modules.wormholes", 0)) {
|
2014-12-13 16:43:35 +01:00
|
|
|
wormholes_update();
|
2014-07-23 08:10:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-06 19:53:09 +02:00
|
|
|
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
|
|
|
|
* Beschreibungen geändert haben */
|
2014-07-23 08:10:14 +02:00
|
|
|
update_spells();
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void update_subscriptions(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-07-23 08:10:14 +02:00
|
|
|
FILE *F;
|
|
|
|
char zText[MAX_PATH];
|
2015-10-30 11:16:09 +01:00
|
|
|
|
2016-02-05 23:10:05 +01:00
|
|
|
join_path(basepath(), "subscriptions", zText, sizeof(zText));
|
2014-07-23 08:10:14 +02:00
|
|
|
F = fopen(zText, "r");
|
|
|
|
if (F == NULL) {
|
|
|
|
log_warning(0, "could not open %s.\n", zText);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
char zFaction[5];
|
|
|
|
int subscription, fno;
|
2015-10-30 12:54:07 +01:00
|
|
|
faction *f;
|
|
|
|
|
2015-11-04 12:09:45 +01:00
|
|
|
if (fscanf(F, "%d %4s", &subscription, zFaction) <= 0)
|
2014-07-23 08:10:14 +02:00
|
|
|
break;
|
|
|
|
fno = atoi36(zFaction);
|
|
|
|
f = findfaction(fno);
|
|
|
|
if (f != NULL) {
|
|
|
|
f->subscription = subscription;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(F);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-11-01 12:09:56 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
cansee(const faction * f, const region * r, const unit * u, int modifier)
|
2015-11-22 16:14:27 +01:00
|
|
|
/* r kann != u->region sein, wenn es um Durchreisen geht,
|
2015-08-27 16:53:36 +02:00
|
|
|
* oder Zauber (sp_generous, sp_fetchastral).
|
|
|
|
* Es muss auch niemand aus f in der region sein, wenn sie vom Turm
|
|
|
|
* erblickt wird */
|
2014-11-01 12:09:56 +01:00
|
|
|
{
|
|
|
|
int stealth, rings;
|
|
|
|
unit *u2 = r->units;
|
|
|
|
|
|
|
|
if (u->faction == f || omniscient(f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (fval(u_race(u), RCF_INVISIBLE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (u->number == 0) {
|
|
|
|
attrib *a = a_find(u->attribs, &at_creator);
|
|
|
|
if (a) { /* u is an empty temporary unit. In this special case
|
|
|
|
we look at the creating unit. */
|
|
|
|
u = (unit *)a->data.v;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftship(u))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
while (u2 && u2->faction != f)
|
|
|
|
u2 = u2->next;
|
|
|
|
if (u2 == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* simple visibility, just gotta have a unit in the region to see 'em */
|
2016-10-31 07:45:06 +01:00
|
|
|
if (is_guard(u) || usiege(u) || u->building || u->ship) {
|
2014-11-01 12:09:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
rings = invisible(u, NULL);
|
|
|
|
stealth = eff_stealth(u, r) - modifier;
|
|
|
|
|
|
|
|
while (u2) {
|
|
|
|
if (rings < u->number || invisible(u, u2) < u->number) {
|
|
|
|
if (skill_enabled(SK_PERCEPTION)) {
|
2015-08-27 16:16:55 +02:00
|
|
|
int observation = effskill(u2, SK_PERCEPTION, 0);
|
2014-11-01 12:09:56 +01:00
|
|
|
|
|
|
|
if (observation >= stealth) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find next unit in our faction */
|
|
|
|
do {
|
|
|
|
u2 = u2->next;
|
|
|
|
} while (u2 && u2->faction != f);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cansee_unit(const unit * u, const unit * target, int modifier)
|
|
|
|
/* target->region kann != u->region sein, wenn es um durchreisen geht */
|
|
|
|
{
|
|
|
|
if (fval(u_race(target), RCF_INVISIBLE) || target->number == 0)
|
|
|
|
return false;
|
|
|
|
else if (target->faction == u->faction)
|
|
|
|
return true;
|
|
|
|
else {
|
|
|
|
int n, rings, o;
|
|
|
|
|
2016-10-31 07:45:06 +01:00
|
|
|
if (is_guard(target) || usiege(target) || target->building
|
2014-11-01 12:09:56 +01:00
|
|
|
|| target->ship) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = eff_stealth(target, target->region) - modifier;
|
|
|
|
rings = invisible(target, NULL);
|
|
|
|
if (rings == 0 && n <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rings && invisible(target, u) >= target->number) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (skill_enabled(SK_PERCEPTION)) {
|
2015-08-27 16:16:55 +02:00
|
|
|
o = effskill(u, SK_PERCEPTION, target->region);
|
2014-11-01 12:09:56 +01:00
|
|
|
if (o >= n) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
cansee_durchgezogen(const faction * f, const region * r, const unit * u,
|
2015-11-22 16:14:27 +01:00
|
|
|
int modifier)
|
|
|
|
/* r kann != u->region sein, wenn es um durchreisen geht */
|
|
|
|
/* und es muss niemand aus f in der region sein, wenn sie vom Turm
|
|
|
|
* erblickt wird */
|
2014-11-01 12:09:56 +01:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
unit *u2;
|
|
|
|
|
|
|
|
if (fval(u_race(u), RCF_INVISIBLE) || u->number == 0)
|
|
|
|
return false;
|
|
|
|
else if (u->faction == f)
|
|
|
|
return true;
|
|
|
|
else {
|
|
|
|
int rings;
|
|
|
|
|
2016-10-31 07:45:06 +01:00
|
|
|
if (is_guard(u) || usiege(u) || u->building || u->ship) {
|
2014-11-01 12:09:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = eff_stealth(u, r) - modifier;
|
|
|
|
rings = invisible(u, NULL);
|
|
|
|
if (rings == 0 && n <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
if (u2->faction == f) {
|
|
|
|
int o;
|
|
|
|
|
|
|
|
if (rings && invisible(u, u2) >= u->number)
|
|
|
|
continue;
|
|
|
|
|
2015-08-27 16:16:55 +02:00
|
|
|
o = effskill(u2, SK_PERCEPTION, 0);
|
2014-11-01 12:09:56 +01:00
|
|
|
|
|
|
|
if (o >= n) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
seefaction(const faction * f, const region * r, const unit * u, int modifier)
|
|
|
|
{
|
|
|
|
if (((f == u->faction) || !fval(u, UFL_ANON_FACTION))
|
|
|
|
&& cansee(f, r, u, modifier))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|