2010-08-08 10:06:34 +02:00
|
|
|
|
/*
|
|
|
|
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
#include "laws.h"
|
|
|
|
|
|
2014-03-22 21:49:18 +01:00
|
|
|
|
#include <modules/gmcmd.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <modules/wormhole.h>
|
|
|
|
|
|
|
|
|
|
#include "economy.h"
|
|
|
|
|
#include "monster.h"
|
|
|
|
|
#include "randenc.h"
|
|
|
|
|
#include "spy.h"
|
|
|
|
|
#include "study.h"
|
|
|
|
|
#include "market.h"
|
2014-06-16 03:34:39 +02:00
|
|
|
|
#include "keyword.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include <kernel/alchemy.h>
|
|
|
|
|
#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/battle.h>
|
|
|
|
|
#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/calendar.h>
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/group.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/magic.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/move.h>
|
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/resources.h>
|
|
|
|
|
#include <kernel/save.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/skill.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/teleport.h>
|
|
|
|
|
#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>
|
|
|
|
|
#include <attributes/object.h>
|
|
|
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
#include <util/parser.h>
|
2012-05-31 04:55:17 +02:00
|
|
|
|
#include <quicklist.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/rand.h>
|
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
#include <util/umlaut.h>
|
|
|
|
|
#include <util/message.h>
|
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
#include <util/xml.h>
|
|
|
|
|
|
|
|
|
|
#include <attributes/otherfaction.h>
|
|
|
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
|
|
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
|
|
/* chance that a peasant dies of starvation: */
|
|
|
|
|
#define PEASANT_STARVATION_CHANCE 0.9F
|
|
|
|
|
/* 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 ----------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int RemoveNMRNewbie(void)
|
|
|
|
|
{
|
2010-08-08 10:06:34 +02:00
|
|
|
|
static int value = -1;
|
2010-11-01 03:32:24 +01:00
|
|
|
|
static int gamecookie = -1;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (value < 0 || gamecookie != global.cookie) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
value = get_param_int(global.parameters, "nmr.removenewbie", 0);
|
2010-11-01 03:32:24 +01:00
|
|
|
|
gamecookie = global.cookie;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void checkorders(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
faction *f;
|
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
|
log_info(" - Warne spaete Spieler...");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (f = factions; f; f = f->next)
|
|
|
|
|
if (!is_monsters(f) && turn - f->lastorders == NMRTimeout() - 1)
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("turnreminder", ""));
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool help_money(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u)->ec_flags & GIVEITEM)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return true;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void help_feed(unit * donor, unit * u, int *need_p)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int need = *need_p;
|
|
|
|
|
int give = get_money(donor) - lifestyle(donor);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
give = _min(need, give);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (give > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
change_money(donor, -give);
|
|
|
|
|
change_money(u, give);
|
|
|
|
|
need -= give;
|
|
|
|
|
add_spende(donor->faction, u->faction, give, donor->region);
|
|
|
|
|
}
|
|
|
|
|
*need_p = need;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-09 08:39:16 +02:00
|
|
|
|
enum {
|
|
|
|
|
FOOD_FROM_PEASANTS = 1,
|
|
|
|
|
FOOD_FROM_OWNER = 2,
|
|
|
|
|
FOOD_IS_FREE = 4
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-09 06:16:47 +01:00
|
|
|
|
void get_food(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int peasantfood = rpeasants(r) * 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
static int food_rules = -1;
|
2010-10-09 08:39:16 +02:00
|
|
|
|
static int gamecookie = -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (food_rules < 0 || gamecookie != global.cookie) {
|
2010-10-09 08:39:16 +02:00
|
|
|
|
gamecookie = global.cookie;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
food_rules = get_param_int(global.parameters, "rules.economy.food", 0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (food_rules & FOOD_IS_FREE) {
|
2010-10-09 08:39:16 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber
|
|
|
|
|
* wird zun<EFBFBD>chst so auf die Einheiten aufgeteilt, dass idealerweise
|
|
|
|
|
* jede Einheit genug Silber f<EFBFBD>r ihren Unterhalt hat. */
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
int need = lifestyle(u);
|
|
|
|
|
|
|
|
|
|
/* Erstmal zur<75>cksetzen */
|
|
|
|
|
freset(u, UFL_HUNGER);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->ship && (u->ship->flags & SF_FISHING)) {
|
|
|
|
|
unit *v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int c = 2;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (v = u; c > 0 && v; v = v->next) {
|
|
|
|
|
if (v->ship == u->ship) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int get = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (v->number <= c) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
get = lifestyle(v);
|
|
|
|
|
} else {
|
|
|
|
|
get = lifestyle(v) * c / v->number;
|
|
|
|
|
}
|
|
|
|
|
if (get) {
|
|
|
|
|
change_money(v, get);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
c -= v->number;
|
|
|
|
|
}
|
|
|
|
|
u->ship->flags -= SF_FISHING;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (food_rules & FOOD_FROM_PEASANTS) {
|
|
|
|
|
faction *owner = region_get_owner(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* if the region is owned, and the owner is nice, then we'll get
|
|
|
|
|
* food from the peasants - should not be used with WORK */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (owner != NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int rm = rmoney(r);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
int use = _min(rm, need);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsetmoney(r, rm - use);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
need -= use;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
need -= get_money(u);
|
|
|
|
|
if (need > 0) {
|
|
|
|
|
unit *v;
|
|
|
|
|
|
|
|
|
|
for (v = r->units; need && v; v = v->next) {
|
|
|
|
|
if (v->faction == u->faction && help_money(v)) {
|
|
|
|
|
int give = get_money(v) - lifestyle(v);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
give = _min(need, give);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (give > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
change_money(v, -give);
|
|
|
|
|
change_money(u, give);
|
|
|
|
|
need -= give;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 2. Versorgung durch Fremde. Das Silber alliierter Einheiten wird
|
|
|
|
|
* entsprechend verteilt. */
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
int need = lifestyle(u);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f = u->faction;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
need -= _max(0, get_money(u));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (need > 0) {
|
|
|
|
|
unit *v;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (food_rules & FOOD_FROM_OWNER) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* the owner of the region is the first faction to help out when you're hungry */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *owner = region_get_owner(r);
|
|
|
|
|
if (owner && owner != u->faction) {
|
|
|
|
|
for (v = r->units; v; v = v->next) {
|
|
|
|
|
if (v->faction == owner && alliedunit(v, f, HELP_MONEY)
|
|
|
|
|
&& help_money(v)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
help_feed(v, u, &need);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (v = r->units; need && v; v = v->next) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (v->faction != f && alliedunit(v, f, HELP_MONEY)
|
|
|
|
|
&& help_money(v)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
help_feed(v, u, &need);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Die Einheit hat nicht genug Geld zusammengekratzt und
|
|
|
|
|
* nimmt Schaden: */
|
|
|
|
|
if (need > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int lspp = lifestyle(u) / u->number;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (lspp > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int number = (need + lspp - 1) / lspp;
|
|
|
|
|
if (hunger(number, u))
|
|
|
|
|
fset(u, UFL_HUNGER);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 3. bestimmen, wie viele Bauern gefressen werden.
|
|
|
|
|
* bei fehlenden Bauern den D<EFBFBD>mon hungern lassen
|
|
|
|
|
*/
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == new_race[RC_DAEMON]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int hungry = u->number;
|
|
|
|
|
|
2012-06-09 00:13:13 +02:00
|
|
|
|
/* use peasantblood before eating the peasants themselves */
|
|
|
|
|
static const struct potion_type *pt_blood;
|
|
|
|
|
if (pt_blood == NULL) {
|
|
|
|
|
const item_type *it_blood = it_find("peasantblood");
|
|
|
|
|
if (it_blood)
|
|
|
|
|
pt_blood = it_blood->rtype->ptype;
|
|
|
|
|
}
|
|
|
|
|
if (pt_blood != NULL) {
|
|
|
|
|
/* always start with the unit itself, then the first known unit that may have some blood */
|
|
|
|
|
unit *donor = u;
|
|
|
|
|
while (donor != NULL && hungry > 0) {
|
|
|
|
|
int blut = get_effect(donor, pt_blood);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
blut = _min(blut, hungry);
|
2014-06-01 11:07:22 +02:00
|
|
|
|
if (blut) {
|
|
|
|
|
change_effect(donor, pt_blood, -blut);
|
|
|
|
|
hungry -= blut;
|
|
|
|
|
}
|
2012-06-09 00:13:13 +02:00
|
|
|
|
if (donor == u)
|
|
|
|
|
donor = r->units;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (donor != NULL) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(donor) == new_race[RC_DAEMON] && donor!=u) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (get_effect(donor, pt_blood)) {
|
|
|
|
|
/* if he's in our faction, drain him: */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (donor->faction == u->faction)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
donor = donor->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-09 00:13:13 +02:00
|
|
|
|
/* remaining demons feed on peasants */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (pl == NULL || !fval(pl, PFL_NOFEED)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (peasantfood >= hungry) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
peasantfood -= hungry;
|
|
|
|
|
hungry = 0;
|
|
|
|
|
} else {
|
|
|
|
|
hungry -= peasantfood;
|
|
|
|
|
peasantfood = 0;
|
|
|
|
|
}
|
|
|
|
|
if (hungry > 0) {
|
|
|
|
|
static int demon_hunger = -1;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (demon_hunger < 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
demon_hunger = get_param_int(global.parameters, "hunger.demons", 0);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (demon_hunger == 0) {
|
2012-06-09 00:13:13 +02:00
|
|
|
|
/* demons who don't feed are hungry */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (hunger(hungry, u))
|
|
|
|
|
fset(u, UFL_HUNGER);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
|
|
|
|
/* no damage, but set the hungry-flag */
|
|
|
|
|
fset(u, UFL_HUNGER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsetpeasants(r, peasantfood / 10);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* 3. Von den <20>berlebenden das Geld abziehen: */
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
int need = _min(get_money(u), lifestyle(u));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
change_money(u, -need);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void age_unit(region * r, unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == new_race[RC_SPELL]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (--u->age <= 0) {
|
|
|
|
|
remove_unit(&r->units, u);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
++u->age;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u->number > 0 && u_race(u)->age) {
|
|
|
|
|
u_race(u)->age(u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#ifdef ASTRAL_ITEM_RESTRICTIONS
|
|
|
|
|
if (u->region && is_astral(u->region)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item **itemp = &u->items;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*itemp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
item *itm = *itemp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if ((itm->type->flags & ITF_NOTLOST) == 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itm->type->flags & (ITF_BIG | ITF_ANIMAL | ITF_CURSED)) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("itemcrumble",
|
2011-03-08 08:44:20 +01:00
|
|
|
|
"unit region item amount",
|
|
|
|
|
u, u->region, itm->type->rtype, itm->number));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i_free(i_remove(itemp, itm));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
itemp = &itm->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void live(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
unit **up = &r->units;
|
|
|
|
|
|
|
|
|
|
get_food(r);
|
|
|
|
|
|
|
|
|
|
while (*up) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = *up;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* IUW: age_unit() kann u loeschen, u->next ist dann
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* undefiniert, also muessen wir hier schon das n<EFBFBD>chste
|
|
|
|
|
* Element bestimmen */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
int effect = get_effect(u, oldpotiontype[P_FOOL]);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
sb = sv;
|
|
|
|
|
}
|
|
|
|
|
++sv;
|
|
|
|
|
}
|
|
|
|
|
/* bestes Talent raussuchen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (sb != NULL) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
int weeks = _min(effect, u->number);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
reduce_skill(u, sb, weeks);
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("dumbeffect",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"unit weeks skill", u, weeks, (skill_t) sb->id));
|
|
|
|
|
} /* sonst Gl<47>ck gehabt: wer nix wei<65>, kann nix vergessen... */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
change_effect(u, oldpotiontype[P_FOOL], -effect);
|
|
|
|
|
}
|
|
|
|
|
age_unit(r, u);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int maxp = maxworkingpeasants(r);
|
|
|
|
|
int rp = rpeasants(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int max_immigrants = MAX_IMMIGRATION(maxp - rp);
|
|
|
|
|
|
|
|
|
|
if (r->terrain == newterrain(T_VOLCANO)
|
|
|
|
|
|| r->terrain == newterrain(T_VOLCANO_SMOKING)) {
|
|
|
|
|
max_immigrants = max_immigrants / 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; max_immigrants > 0 && i != MAXDIRECTIONS; i++) {
|
|
|
|
|
int dir = (turn + i) % MAXDIRECTIONS;
|
|
|
|
|
region *rc = rconnect(r, (direction_t) dir);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (rc != NULL && fval(rc->terrain, LAND_REGION)) {
|
|
|
|
|
int rp2 = rpeasants(rc);
|
|
|
|
|
int maxp2 = maxworkingpeasants(rc);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int max_emigration = MAX_EMIGRATION(rp2 - maxp2);
|
|
|
|
|
|
|
|
|
|
if (max_emigration > 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
max_emigration = _min(max_emigration, max_immigrants);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
r->land->newpeasants += max_emigration;
|
|
|
|
|
rc->land->newpeasants -= max_emigration;
|
|
|
|
|
max_immigrants -= max_emigration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Bauern vermehren sich */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void peasants(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int peasants = rpeasants(r);
|
|
|
|
|
int money = rmoney(r);
|
|
|
|
|
int maxp = production(r) * MAXPEASANTS_PER_AREA;
|
|
|
|
|
int n, satiated;
|
|
|
|
|
int dead = 0;
|
|
|
|
|
|
|
|
|
|
/* Bis zu 1000 Bauern k<>nnen Zwillinge bekommen oder 1000 Bauern
|
|
|
|
|
* wollen nicht! */
|
|
|
|
|
|
2014-03-17 08:21:35 +01:00
|
|
|
|
if (peasants > 0 && get_param_int(global.parameters, "rules.peasants.growth", 1)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int glueck = 0;
|
|
|
|
|
double fraction = peasants * 0.0001F * PEASANTGROWTH;
|
|
|
|
|
int births = (int)fraction;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(r->attribs, &at_peasantluck);
|
|
|
|
|
|
|
|
|
|
if (rng_double() < (fraction - births)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* because we don't want regions that never grow pga. rounding. */
|
|
|
|
|
++births;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (a != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
glueck = a->data.i * 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (n = peasants; n; --n) {
|
|
|
|
|
int chances = 0;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (glueck > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
--glueck;
|
|
|
|
|
chances += PEASANTLUCK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (chances--) {
|
|
|
|
|
if (rng_int() % 10000 < PEASANTGROWTH) {
|
|
|
|
|
/* Only raise with 75% chance if peasants have
|
|
|
|
|
* reached 90% of maxpopulation */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
++births;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
peasants += births;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Alle werden satt, oder halt soviele f<>r die es auch Geld gibt */
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
satiated = _min(peasants, money / maintenance_cost(NULL));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rsetmoney(r, money - satiated * maintenance_cost(NULL));
|
|
|
|
|
|
|
|
|
|
/* Von denjenigen, die nicht satt geworden sind, verhungert der
|
|
|
|
|
* Gro<EFBFBD>teil. dead kann nie gr<EFBFBD><EFBFBD>er als rpeasants(r) - satiated werden,
|
|
|
|
|
* so dass rpeasants(r) >= 0 bleiben mu<EFBFBD>. */
|
|
|
|
|
|
|
|
|
|
/* Es verhungert maximal die unterern<72>hrten Bev<65>lkerung. */
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(peasants - satiated, rpeasants(r));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
dead += (int)(0.5F + n * PEASANT_STARVATION_CHANCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (dead > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
message *msg = add_message(&r->msgs, msg_message("phunger", "dead", dead));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
msg_release(msg);
|
|
|
|
|
peasants -= dead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rsetpeasants(r, peasants);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
typedef struct migration {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct migration *next;
|
|
|
|
|
region *r;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int horses;
|
|
|
|
|
int trees;
|
|
|
|
|
} 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
|
|
|
|
{
|
|
|
|
|
int key = reg_hashkey(r);
|
|
|
|
|
int index = key % MSIZE;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
migration *m = migrants[index];
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (m && m->r != r)
|
|
|
|
|
m = m->next;
|
|
|
|
|
if (m == NULL) {
|
|
|
|
|
/* Es gibt noch keine Migration. Also eine erzeugen
|
|
|
|
|
*/
|
|
|
|
|
m = free_migrants;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!m)
|
|
|
|
|
m = calloc(1, sizeof(migration));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
else {
|
|
|
|
|
free_migrants = free_migrants->next;
|
|
|
|
|
m->horses = 0;
|
|
|
|
|
m->trees = 0;
|
|
|
|
|
}
|
|
|
|
|
m->r = r;
|
|
|
|
|
m->next = migrants[index];
|
|
|
|
|
migrants[index] = m;
|
|
|
|
|
}
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void migrate(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int key = reg_hashkey(r);
|
|
|
|
|
int index = key % MSIZE;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
migration **hp = &migrants[index];
|
2010-08-08 10:06:34 +02:00
|
|
|
|
fset(r, RF_MIGRATION);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (*hp && (*hp)->r != r)
|
|
|
|
|
hp = &(*hp)->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (*hp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
migration *m = *hp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rsethorses(r, rhorses(r) + m->horses);
|
|
|
|
|
/* Was macht das denn hier?
|
|
|
|
|
* Baumwanderung wird in trees() gemacht.
|
|
|
|
|
* wer fragt das? Die Baumwanderung war abh<EFBFBD>ngig von der
|
|
|
|
|
* Auswertungsreihenfolge der regionen,
|
|
|
|
|
* das hatte ich ge<EFBFBD>ndert. jemand hat es wieder gel<EFBFBD>scht, toll.
|
|
|
|
|
* ich habe es wieder aktiviert, mu<EFBFBD> getestet werden.
|
|
|
|
|
*/
|
|
|
|
|
*hp = m->next;
|
|
|
|
|
m->next = free_migrants;
|
|
|
|
|
free_migrants = m;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void horses(region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int horses, maxhorses;
|
|
|
|
|
direction_t n;
|
|
|
|
|
|
|
|
|
|
/* Logistisches Wachstum, Optimum bei halbem Maximalbesatz. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
maxhorses = maxworkingpeasants(r) / 10;
|
2014-03-16 05:03:17 +01:00
|
|
|
|
maxhorses = _max(0, maxhorses);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
horses = rhorses(r);
|
|
|
|
|
if (horses > 0) {
|
|
|
|
|
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsethorses(r, (int)(horses * 0.9F));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else if (maxhorses) {
|
|
|
|
|
int i;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
double growth =
|
|
|
|
|
(RESOURCE_QUANTITY * HORSEGROWTH * 200 * (maxhorses -
|
|
|
|
|
horses)) / maxhorses;
|
|
|
|
|
|
|
|
|
|
if (growth > 0) {
|
|
|
|
|
if (a_find(r->attribs, &at_horseluck))
|
|
|
|
|
growth *= 2;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* printf("Horses: <%d> %d -> ", growth, horses); */
|
|
|
|
|
i = (int)(0.5F + (horses * 0.0001F) * growth);
|
|
|
|
|
/* printf("%d\n", horses); */
|
|
|
|
|
rsethorses(r, horses + i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Pferde wandern in Nachbarregionen.
|
|
|
|
|
* Falls die Nachbarregion noch berechnet
|
|
|
|
|
* werden mu<EFBFBD>, wird eine migration-Struktur gebildet,
|
|
|
|
|
* die dann erst in die Berechnung der Nachbarstruktur einflie<EFBFBD>t.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (n = 0; n != MAXDIRECTIONS; n++) {
|
|
|
|
|
region *r2 = rconnect(r, n);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (r2 && fval(r2->terrain, WALK_INTO)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int pt = (rhorses(r) * HORSEMOVE) / 100;
|
|
|
|
|
pt = (int)normalvariate(pt, pt / 4.0);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
pt = _max(0, pt);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (fval(r2, RF_MIGRATION))
|
|
|
|
|
rsethorses(r2, rhorses(r2) + pt);
|
|
|
|
|
else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
migration *nb;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* haben wir die Migration schonmal benutzt?
|
|
|
|
|
* wenn nicht, m<EFBFBD>ssen wir sie suchen.
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
unit *u;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next)
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u) == rc)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
c += u->number;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern struct attrib_type at_germs;
|
|
|
|
|
|
|
|
|
|
static void
|
2011-03-07 08:02:35 +01:00
|
|
|
|
growing_trees_e3(region * r, const int current_season,
|
|
|
|
|
const int last_weeks_season)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 17:26:50 +01:00
|
|
|
|
static const int transform[4][3] = {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
{-1, -1, 0},
|
|
|
|
|
{TREE_SEED, TREE_SAPLING, 2},
|
|
|
|
|
{TREE_SAPLING, TREE_TREE, 2},
|
|
|
|
|
{TREE_TREE, TREE_SEED, 2}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->land && current_season != last_weeks_season
|
|
|
|
|
&& transform[current_season][2]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
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);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rsettrees(r, dst_type, dst + grow);
|
|
|
|
|
|
|
|
|
|
if (dst_type == TREE_SEED && r->terrain->size) {
|
|
|
|
|
region *rn[MAXDIRECTIONS];
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int d;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
double fgrow = grow / (double)MAXDIRECTIONS;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
get_neighbours(r, rn);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
|
|
|
|
region *rx = rn[d];
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rx && rx->land) {
|
|
|
|
|
double scale = 1.0;
|
|
|
|
|
int g;
|
|
|
|
|
double fg, ch;
|
|
|
|
|
int seeds = rtrees(rx, dst_type);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->terrain->size > rx->terrain->size) {
|
|
|
|
|
scale = (scale * rx->terrain->size) / r->terrain->size;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
fg = scale * fgrow;
|
|
|
|
|
g = (int)fg;
|
|
|
|
|
ch = fg - g;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (chance(ch))
|
|
|
|
|
++g;
|
|
|
|
|
if (g > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rsettrees(rx, dst_type, seeds + g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
growing_trees(region * r, const int current_season, const int last_weeks_season)
|
|
|
|
|
{
|
|
|
|
|
int growth, grownup_trees, i, seeds, sprout;
|
|
|
|
|
direction_t d;
|
|
|
|
|
attrib *a;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
double seedchance = 0.01F * RESOURCE_QUANTITY;
|
|
|
|
|
int elves = count_race(r, new_race[RC_ELF]);
|
|
|
|
|
|
|
|
|
|
a = a_find(r->attribs, &at_germs);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (a && last_weeks_season == SEASON_SPRING) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ungekeimte Samen bleiben erhalten, Spr<70><72>linge wachsen */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
sprout = _min(a->data.sa[1], rtrees(r, 1));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* aus dem gesamt Spr<70><72>lingepool abziehen */
|
|
|
|
|
rsettrees(r, 1, rtrees(r, 1) - sprout);
|
|
|
|
|
/* zu den B<>umen hinzuf<75>gen */
|
|
|
|
|
rsettrees(r, 2, rtrees(r, 2) + sprout);
|
|
|
|
|
|
|
|
|
|
a_removeall(&r->attribs, &at_germs);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
rsettrees(r, 1, (int)(rtrees(r, 1) * 0.9));
|
|
|
|
|
rsettrees(r, 2, (int)(rtrees(r, 2) * 0.9));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (production(r) <= 0)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* Grundchance 1.0% */
|
|
|
|
|
/* Jeder Elf in der Region erh<72>ht die Chance marginal */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
elves = _min(elves, (production(r) * MAXPEASANTS_PER_AREA) / 8);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (elves) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
grownup_trees = rtrees(r, 2);
|
|
|
|
|
seeds = 0;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (grownup_trees > 0) {
|
|
|
|
|
double remainder = seedchance * grownup_trees;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
seeds = (int)(remainder);
|
|
|
|
|
remainder -= seeds;
|
|
|
|
|
if (chance(remainder)) {
|
|
|
|
|
++seeds;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (seeds > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
seeds += rtrees(r, 0);
|
|
|
|
|
rsettrees(r, 0, seeds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* B<>ume breiten sich in Nachbarregionen aus. */
|
|
|
|
|
|
|
|
|
|
/* Gesamtzahl der Samen:
|
|
|
|
|
* bis zu 6% (FORESTGROWTH*3) der B<EFBFBD>ume samen in die Nachbarregionen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000;
|
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
|
|
|
|
region *r2 = rconnect(r, d);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (r2 && fval(r2->terrain, LAND_REGION) && r2->terrain->size) {
|
|
|
|
|
/* Eine Landregion, wir versuchen Samen zu verteilen:
|
|
|
|
|
* Die Chance, das Samen ein St<EFBFBD>ck Boden finden, in dem sie
|
|
|
|
|
* keimen k<EFBFBD>nnen, h<EFBFBD>ngt von der Bewuchsdichte und der
|
|
|
|
|
* verf<EFBFBD>gbaren Fl<EFBFBD>che ab. In Gletschern gibt es weniger
|
|
|
|
|
* M<EFBFBD>glichkeiten als in Ebenen. */
|
|
|
|
|
sprout = 0;
|
|
|
|
|
seedchance = (1000 * maxworkingpeasants(r2)) / r2->terrain->size;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; i < seeds / MAXDIRECTIONS; i++) {
|
|
|
|
|
if (rng_int() % 10000 < seedchance)
|
|
|
|
|
sprout++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
rsettrees(r2, 0, rtrees(r2, 0) + sprout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (current_season == SEASON_SPRING) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0))
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* in at_germs merken uns die Zahl der Samen und Spr<70><72>linge, die
|
|
|
|
|
* dieses Jahr <EFBFBD>lter werden d<EFBFBD>rfen, damit nicht ein Same im selben
|
|
|
|
|
* Zyklus zum Baum werden kann */
|
|
|
|
|
a = a_find(r->attribs, &at_germs);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!a) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
/* wir haben 6 Wochen zum wachsen, jeder Same/Spro<72> hat 18% Chance
|
|
|
|
|
* zu wachsen, damit sollten nach 5-6 Wochen alle gewachsen sein */
|
|
|
|
|
growth = 1800;
|
|
|
|
|
|
|
|
|
|
/* Samenwachstum */
|
|
|
|
|
|
|
|
|
|
/* Raubbau abfangen, es d<>rfen nie mehr Samen wachsen, als aktuell
|
|
|
|
|
* in der Region sind */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
seeds = _min(a->data.sa[0], rtrees(r, 0));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
sprout = 0;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; i < seeds; i++) {
|
|
|
|
|
if (rng_int() % 10000 < growth)
|
|
|
|
|
sprout++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
/* 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);
|
|
|
|
|
/* zu den Spr<70><72>linge hinzuf<75>gen */
|
|
|
|
|
rsettrees(r, 1, rtrees(r, 1) + sprout);
|
|
|
|
|
|
|
|
|
|
/* Baumwachstum */
|
|
|
|
|
|
|
|
|
|
/* hier gehen wir davon aus, das Jungb<67>ume nicht ohne weiteres aus
|
|
|
|
|
* der Region entfernt werden k<EFBFBD>nnen, da Jungb<EFBFBD>ume in der gleichen
|
|
|
|
|
* Runde nachwachsen, wir also nicht mehr zwischen diesj<EFBFBD>hrigen und
|
|
|
|
|
* 'alten' Jungb<EFBFBD>umen unterscheiden k<EFBFBD>nnten */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
sprout = _min(a->data.sa[1], rtrees(r, 1));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
grownup_trees = 0;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; i < sprout; i++) {
|
|
|
|
|
if (rng_int() % 10000 < growth)
|
|
|
|
|
grownup_trees++;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
/* aus dem Spr<70><72>lingepool dieses Jahres abziehen */
|
|
|
|
|
a->data.sa[1] = (short)(sprout - grownup_trees);
|
|
|
|
|
/* aus dem gesamt Spr<70><72>lingepool abziehen */
|
|
|
|
|
rsettrees(r, 1, rtrees(r, 1) - grownup_trees);
|
|
|
|
|
/* zu den B<>umen hinzuf<75>gen */
|
|
|
|
|
rsettrees(r, 2, rtrees(r, 2) + grownup_trees);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
growing_herbs(region * r, const int current_season, const int last_weeks_season)
|
|
|
|
|
{
|
|
|
|
|
/* Jetzt die Kr<4B>utervermehrung. Vermehrt wird logistisch:
|
|
|
|
|
*
|
|
|
|
|
* Jedes Kraut hat eine Wahrscheinlichkeit von (100-(vorhandene
|
|
|
|
|
* Kr<EFBFBD>uter))% sich zu vermehren. */
|
|
|
|
|
if (current_season != SEASON_WINTER) {
|
|
|
|
|
int i;
|
|
|
|
|
for (i = rherbs(r); i > 0; i--) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rng_int() % 100 < (100 - rherbs(r)))
|
|
|
|
|
rsetherbs(r, (short)(rherbs(r) + 1));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void demographics(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
region *r;
|
|
|
|
|
static int last_weeks_season = -1;
|
|
|
|
|
static int current_season = -1;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (current_season < 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
gamedate date;
|
|
|
|
|
get_gamedate(turn, &date);
|
|
|
|
|
current_season = date.season;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
get_gamedate(turn - 1, &date);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
last_weeks_season = date.season;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
++r->age; /* also oceans. no idea why we didn't always do that */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
live(r);
|
|
|
|
|
/* check_split_dragons(); */
|
|
|
|
|
|
|
|
|
|
if (!fval(r->terrain, SEA_REGION)) {
|
|
|
|
|
/* die Nachfrage nach Produkten steigt. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct demand *dmd;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (r->land) {
|
|
|
|
|
static int plant_rules = -1;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (plant_rules < 0) {
|
|
|
|
|
plant_rules =
|
|
|
|
|
get_param_int(global.parameters, "rules.economy.grow", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (dmd = r->land->demands; dmd; dmd = dmd->next) {
|
|
|
|
|
if (dmd->value > 0 && dmd->value < MAXDEMAND) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
float rise = DMRISE;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (buildingtype_exists(r, bt_find("harbour"), true))
|
|
|
|
|
rise = DMRISEHAFEN;
|
|
|
|
|
if (rng_double() < rise)
|
|
|
|
|
++dmd->value;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Seuchen erst nachdem die Bauern sich vermehrt haben
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* und gewandert sind */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
calculate_emigration(r);
|
2014-03-17 08:21:35 +01:00
|
|
|
|
peasants(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->age > 20) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
plagues(r, false);
|
|
|
|
|
}
|
|
|
|
|
horses(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (plant_rules == 0) { /* E1 */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
growing_trees(r, current_season, last_weeks_season);
|
|
|
|
|
growing_herbs(r, current_season, last_weeks_season);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else { /* E3 */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
growing_trees_e3(r, current_season, last_weeks_season);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_resources(r);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->land)
|
|
|
|
|
migrate(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (free_migrants) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
migration *m = free_migrants->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
free(free_migrants);
|
|
|
|
|
free_migrants = m;
|
|
|
|
|
};
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (verbosity >= 1)
|
|
|
|
|
putchar('\n');
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
remove_empty_units();
|
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
|
log_info(" - Einwanderung...");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
if (r->land && r->land->newpeasants) {
|
|
|
|
|
int rp = rpeasants(r) + r->land->newpeasants;
|
2014-03-16 05:03:17 +01:00
|
|
|
|
rsetpeasants(r, _max(0, rp));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkorders();
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int modify(int i)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
c = i * 2 / 3;
|
|
|
|
|
|
|
|
|
|
if (c >= 1) {
|
|
|
|
|
return (c + rng_int() % c);
|
|
|
|
|
} else {
|
|
|
|
|
return (i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void inactivefaction(faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
FILE *inactiveFILE;
|
|
|
|
|
char zText[128];
|
|
|
|
|
|
|
|
|
|
sprintf(zText, "%s/%s", datapath(), "inactive");
|
|
|
|
|
inactiveFILE = fopen(zText, "a");
|
|
|
|
|
|
|
|
|
|
if (inactiveFILE) {
|
|
|
|
|
fprintf(inactiveFILE, "%s:%s:%d:%d\n",
|
|
|
|
|
factionid(f),
|
|
|
|
|
LOC(default_locale, rc_name(f->race, 1)),
|
2011-03-07 08:02:35 +01:00
|
|
|
|
modify(count_all(f)), turn - f->lastorders);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
fclose(inactiveFILE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void transfer_faction(faction * f, faction * f2)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
unit *u, *un;
|
|
|
|
|
|
|
|
|
|
for (u = f->units; u;) {
|
|
|
|
|
un = u->nextF;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!unit_has_cursed_item(u)
|
2011-03-08 08:44:20 +01:00
|
|
|
|
&& !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
u_setfaction(u, f2);
|
|
|
|
|
}
|
|
|
|
|
u = un;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
unit *u2;
|
|
|
|
|
int n, o;
|
|
|
|
|
|
|
|
|
|
/* b ist die burg, in die man hinein oder aus der man heraus will. */
|
|
|
|
|
if (b == NULL || b->besieged < b->size * SIEGEFACTOR) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* u wird am hinein- oder herausschluepfen gehindert, wenn STEALTH <=
|
|
|
|
|
* OBSERVATION +2 der belagerer u2 ist */
|
|
|
|
|
n = eff_skill(u, SK_STEALTH, r);
|
|
|
|
|
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (usiege(u2) == b) {
|
|
|
|
|
|
|
|
|
|
if (invisible(u, u2) >= u->number)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
o = eff_skill(u2, SK_PERCEPTION, r);
|
|
|
|
|
|
|
|
|
|
if (o + 2 >= n) {
|
|
|
|
|
return 0; /* entdeckt! */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int can_contact(const region * r, const unit * u, const unit * u2) {
|
|
|
|
|
|
|
|
|
|
/* hier geht es nur um die belagerung von burgen */
|
|
|
|
|
|
|
|
|
|
if (u->building == u2->building) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
|
|
if (slipthru(u->region, u, u->building) && slipthru(u->region, u2, u2->building)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (alliedunit(u, u2->faction, HELP_GIVE));
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
|
int contact_cmd(unit * u, order * ord)
|
2012-06-14 08:25:20 +02:00
|
|
|
|
{
|
|
|
|
|
/* unit u kontaktiert unit u2. Dies setzt den contact einfach auf 1 -
|
|
|
|
|
* ein richtiger toggle ist (noch?) nicht noetig. die region als
|
|
|
|
|
* parameter ist nur deswegen wichtig, weil er an getunit ()
|
|
|
|
|
* weitergegeben wird. dies wird fuer das auffinden von tempunits in
|
|
|
|
|
* getnewunit () verwendet! */
|
|
|
|
|
unit *u2;
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
u2 = getunitg(r, u->faction);
|
|
|
|
|
|
|
|
|
|
if (u2 != NULL) {
|
|
|
|
|
if (!can_contact(r, u, u2)) {
|
2012-06-18 02:24:23 +02:00
|
|
|
|
cmistake(u, u->thisorder, 23, MSG_EVENT);
|
|
|
|
|
return -1;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
}
|
|
|
|
|
usetcontact(u, u2);
|
|
|
|
|
}
|
2012-06-18 02:24:23 +02:00
|
|
|
|
return 0;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int leave_cmd(unit * u, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
|
|
|
|
|
if (fval(u, UFL_ENTER)) {
|
|
|
|
|
/* if we just entered this round, then we don't leave again */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fval(r->terrain, SEA_REGION) && u->ship) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!fval(u_race(u), RCF_SWIM)) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool EnhancedQuit(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
static int value = -1;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (value < 0) {
|
|
|
|
|
const char *str = get_param(global.parameters, "alliance.transferquit");
|
|
|
|
|
value = (str != 0 && strcmp(str, "true") == 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
|
int quit_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f = u->faction;
|
|
|
|
|
const char *passwd;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
skip_token(); /* skip keyword */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
passwd = getstrtoken();
|
|
|
|
|
if (checkpasswd(f, (const char *)passwd, false)) {
|
|
|
|
|
if (EnhancedQuit()) {
|
|
|
|
|
int f2_id = getid();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f2_id > 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
faction *f2 = findfaction(f2_id);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f2 == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 66, MSG_EVENT);
|
|
|
|
|
return 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (!u->faction->alliance
|
|
|
|
|
|| u->faction->alliance != f2->alliance) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 315, MSG_EVENT);
|
|
|
|
|
return 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (!alliedfaction(NULL, f, f2, HELP_MONEY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 316, MSG_EVENT);
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
variant var;
|
|
|
|
|
var.i = f2_id;
|
|
|
|
|
a_add(&f->attribs, object_create("quit", TINTEGER, var));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fset(f, FFL_QUIT);
|
|
|
|
|
} else {
|
|
|
|
|
char buffer[64];
|
|
|
|
|
write_order(ord, buffer, sizeof(buffer));
|
|
|
|
|
cmistake(u, ord, 86, MSG_EVENT);
|
2012-05-17 00:52:37 +02:00
|
|
|
|
log_warning("QUIT with illegal password for faction %s: %s\n", factionid(f), buffer);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
unit *u2;
|
|
|
|
|
if (fval(b, BLD_UNGUARDED))
|
|
|
|
|
return true;
|
|
|
|
|
u2 = building_owner(b);
|
|
|
|
|
|
|
|
|
|
if (u2 == NULL || ucontact(u2, u)
|
|
|
|
|
|| alliedunit(u2, u->faction, HELP_GUARD))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int mayboard(const unit * u, ship * sh)
|
|
|
|
|
{
|
|
|
|
|
unit *u2 = ship_owner(sh);
|
|
|
|
|
|
|
|
|
|
return (!u2 || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD));
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool CheckOverload(void)
|
2012-06-14 08:25:20 +02:00
|
|
|
|
{
|
|
|
|
|
static int value = -1;
|
|
|
|
|
if (value < 0) {
|
|
|
|
|
value = get_param_int(global.parameters, "rules.check_overload", 0);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int enter_ship(unit * u, struct order *ord, int id, int report)
|
|
|
|
|
{
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
ship *sh;
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
/* Muss abgefangen werden, sonst koennten Schwimmer an
|
2012-06-14 08:25:20 +02:00
|
|
|
|
* Bord von Schiffen an Land gelangen. */
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!fval(u_race(u), RCF_CANSAIL) || (!fval(u_race(u), RCF_WALK)
|
|
|
|
|
&& !fval(u_race(u), RCF_FLY))) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
cmistake(u, ord, 233, MSG_MOVE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sh = findship(id);
|
|
|
|
|
if (sh == NULL || sh->region != r) {
|
|
|
|
|
if (report)
|
|
|
|
|
cmistake(u, ord, 20, MSG_MOVE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (sh == u->ship) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (!mayboard(u, sh)) {
|
|
|
|
|
if (report)
|
|
|
|
|
cmistake(u, ord, 34, MSG_MOVE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
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) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
int pweight = u->number * u_race(u)->weight;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
/* weight goes into number of cabins, not cargo */
|
|
|
|
|
scabins += pweight;
|
|
|
|
|
sweight -= pweight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sweight > mweight || (mcabins && (scabins > mcabins))) {
|
|
|
|
|
if (report)
|
|
|
|
|
cmistake(u, ord, 34, MSG_MOVE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 23:07:30 +02:00
|
|
|
|
if (leave(u, false)) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
u_set_ship(u, sh);
|
|
|
|
|
fset(u, UFL_ENTER);
|
2012-07-25 23:07:30 +02:00
|
|
|
|
} else if (report) {
|
|
|
|
|
cmistake(u, ord, 150, MSG_MOVE);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int enter_building(unit * u, order * ord, int id, int report)
|
|
|
|
|
{
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
building *b;
|
|
|
|
|
|
|
|
|
|
/* Schwimmer k<>nnen keine Geb<65>ude betreten, au<61>er diese sind
|
|
|
|
|
* auf dem Ozean */
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!fval(u_race(u), RCF_WALK) && !fval(u_race(u), RCF_FLY)) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
if (!fval(r->terrain, SEA_REGION)) {
|
|
|
|
|
if (report) {
|
|
|
|
|
cmistake(u, ord, 232, MSG_MOVE);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b = findbuilding(id);
|
|
|
|
|
if (b == NULL || b->region != r) {
|
|
|
|
|
if (report) {
|
|
|
|
|
cmistake(u, ord, 6, MSG_MOVE);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!mayenter(r, u, b)) {
|
|
|
|
|
if (report) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_denied",
|
|
|
|
|
"building", b));
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!slipthru(r, u, b)) {
|
|
|
|
|
if (report) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "entrance_besieged",
|
|
|
|
|
"building", b));
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (leave(u, 0)) {
|
|
|
|
|
fset(u, UFL_ENTER);
|
|
|
|
|
u_set_building(u, b);
|
|
|
|
|
return 1;
|
2012-07-25 23:07:30 +02:00
|
|
|
|
} else if (report) {
|
|
|
|
|
cmistake(u, ord, 150, MSG_MOVE);
|
2012-06-14 08:25:20 +02:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
|
static void do_contact(region * r)
|
2012-06-14 08:25:20 +02:00
|
|
|
|
{
|
2012-06-18 02:24:23 +02:00
|
|
|
|
unit * u;
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
order *ord;
|
2012-06-18 02:24:23 +02:00
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
2012-06-14 08:25:20 +02:00
|
|
|
|
keyword_t kwd = get_keyword(ord);
|
|
|
|
|
if (kwd == K_CONTACT) {
|
2012-06-18 02:24:23 +02:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
unit **uptr;
|
2012-06-14 08:25:20 +02:00
|
|
|
|
|
|
|
|
|
for (uptr = &r->units; *uptr;) {
|
|
|
|
|
unit *u = *uptr;
|
|
|
|
|
order **ordp = &u->orders;
|
|
|
|
|
|
|
|
|
|
while (*ordp) {
|
|
|
|
|
order *ord = *ordp;
|
|
|
|
|
if (get_keyword(ord) == K_ENTER) {
|
|
|
|
|
param_t p;
|
|
|
|
|
int id;
|
|
|
|
|
unit *ulast = NULL;
|
|
|
|
|
const char * s;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
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
|
|
|
|
|
* erfolgreich und wir l<EFBFBD>schen ihn, damit er im
|
|
|
|
|
* zweiten Versuch nicht nochmal ausgef<EFBFBD>hrt wird. */
|
|
|
|
|
*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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (*ordp == ord)
|
|
|
|
|
ordp = &ord->next;
|
|
|
|
|
}
|
|
|
|
|
if (*uptr == u)
|
|
|
|
|
uptr = &u->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
static int rule = -1;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rule < 0)
|
|
|
|
|
rule = get_param_int(global.parameters, "rules.nmr.destroy", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (rule) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
for (u = f->units; u; u = u->nextF) {
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (u->building && building_owner(u->building)==u) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
remove_building(&u->region->buildings, u->building);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
|
static void remove_idle_players(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
faction *f;
|
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
|
log_info(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
2012-06-17 07:38:44 +02:00
|
|
|
|
if (fval(f, FFL_NOIDLEOUT)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
f->lastorders = turn;
|
2012-06-17 07:38:44 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (NMRTimeout() > 0 && turn - f->lastorders >= NMRTimeout()) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
nmr_death(f);
|
|
|
|
|
destroyfaction(f);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (turn != f->lastorders) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
char info[256];
|
|
|
|
|
sprintf(info, "%d Einheiten, %d Personen, %d Silber",
|
|
|
|
|
f->no_units, f->num_total, f->money);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (NMRTimeout() > 0 && turn - f->lastorders >= (NMRTimeout() - 1)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
inactivefaction(f);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-17 07:38:44 +02:00
|
|
|
|
log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben...");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
age = calloc(_max(4, turn + 1), sizeof(int));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (f = factions; f; f = f->next)
|
|
|
|
|
if (!is_monsters(f)) {
|
|
|
|
|
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) {
|
|
|
|
|
destroyfaction(f);
|
|
|
|
|
++dropouts[f->age - 2];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
faction **fptr = &factions;
|
|
|
|
|
while (*fptr) {
|
|
|
|
|
faction *f = *fptr;
|
|
|
|
|
if (f->flags & FFL_QUIT) {
|
|
|
|
|
if (EnhancedQuit()) {
|
|
|
|
|
/* this doesn't work well (use object_name()) */
|
|
|
|
|
attrib *a = a_find(f->attribs, &at_object);
|
|
|
|
|
if (a) {
|
|
|
|
|
variant var;
|
|
|
|
|
object_type type;
|
|
|
|
|
var.i = 0;
|
|
|
|
|
object_get(a, &type, &var);
|
|
|
|
|
assert(var.i && type == TINTEGER);
|
|
|
|
|
if (var.i) {
|
|
|
|
|
int f2_id = var.i;
|
|
|
|
|
faction *f2 = findfaction(f2_id);
|
|
|
|
|
|
|
|
|
|
assert(f2_id > 0);
|
|
|
|
|
assert(f2 != NULL);
|
|
|
|
|
transfer_faction(f, f2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
destroyfaction(f);
|
2012-06-18 07:31:30 +02:00
|
|
|
|
} else {
|
|
|
|
|
++f->age;
|
|
|
|
|
if (f->age + 1 < NewbieImmunity()) {
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns",
|
|
|
|
|
NewbieImmunity() - f->age - 1));
|
|
|
|
|
}
|
2012-06-18 02:24:23 +02:00
|
|
|
|
}
|
2012-06-18 07:31:30 +02:00
|
|
|
|
if (*fptr == f) {
|
2012-06-18 02:24:23 +02:00
|
|
|
|
fptr = &f->next;
|
2012-06-18 07:31:30 +02:00
|
|
|
|
}
|
2012-06-18 02:24:23 +02:00
|
|
|
|
}
|
|
|
|
|
remove_idle_players();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
remove_empty_units();
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ally *sf, **sfp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
faction *f;
|
|
|
|
|
int keyword, not_kw;
|
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
f = getfaction();
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f == NULL || is_monsters(f)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 66, MSG_EVENT);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f == u->faction)
|
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if (!s[0])
|
|
|
|
|
keyword = P_ANY;
|
|
|
|
|
else
|
|
|
|
|
keyword = findparam(s, u->faction->locale);
|
|
|
|
|
|
|
|
|
|
sfp = &u->faction->allies;
|
|
|
|
|
if (fval(u, UFL_GROUP)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->attribs, &at_group);
|
|
|
|
|
if (a)
|
|
|
|
|
sfp = &((group *) a->data.v)->allies;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (sf = *sfp; sf; sf = sf->next)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (sf->faction == f)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
break; /* Gleich die passende raussuchen, wenn vorhanden */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
not_kw = getparam(u->faction->locale); /* HELFE partei [modus] NICHT */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (!sf) {
|
|
|
|
|
if (keyword == P_NOT || not_kw == P_NOT) {
|
|
|
|
|
/* Wir helfen der Partei gar nicht... */
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
sf = calloc(1, sizeof(ally));
|
|
|
|
|
sf->faction = f;
|
|
|
|
|
sf->status = 0;
|
|
|
|
|
addlist(sfp, sf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch (keyword) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_NOT:
|
|
|
|
|
sf->status = 0;
|
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case NOPARAM:
|
|
|
|
|
cmistake(u, ord, 137, MSG_EVENT);
|
|
|
|
|
return 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_ANY:
|
|
|
|
|
if (not_kw == P_NOT)
|
|
|
|
|
sf->status = 0;
|
|
|
|
|
else
|
|
|
|
|
sf->status = HELP_ALL;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sf->status &= HelpMask();
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (sf->status == 0) { /* Alle HELPs geloescht */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
removelist(sfp, sf);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
int i;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; localenames[i]; ++i) {
|
|
|
|
|
const struct locale *lang = find_locale(localenames[i]);
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool exist = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct local_names *in = pnames;
|
|
|
|
|
|
|
|
|
|
while (in != NULL) {
|
|
|
|
|
if (in->lang == lang) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
exist = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
in = in->next;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (in == NULL)
|
|
|
|
|
in = calloc(sizeof(local_names), 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
in->next = pnames;
|
|
|
|
|
in->lang = lang;
|
|
|
|
|
|
|
|
|
|
if (!exist) {
|
|
|
|
|
int key;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (key = 0; race_prefixes[key]; ++key) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
variant var;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *pname =
|
|
|
|
|
locale_string(lang, mkname("prefix", race_prefixes[key]));
|
2012-05-16 00:04:23 +02:00
|
|
|
|
if (findtoken(in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
var.i = key;
|
|
|
|
|
addtoken(&in->names, pname, var);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
addtoken(&in->names, locale_string(lang, mkname("prefix",
|
|
|
|
|
race_prefixes[key])), var);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pnames = in;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
|
int prefix_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
attrib **ap;
|
|
|
|
|
const char *s;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
local_names *in = pnames;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
variant var;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const struct locale *lang = u->faction->locale;
|
|
|
|
|
|
|
|
|
|
while (in != NULL) {
|
|
|
|
|
if (in->lang == lang)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
in = in->next;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (in == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
init_prefixnames();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (in = pnames; in->lang != lang; in = in->next) ;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if (!*s) {
|
|
|
|
|
attrib *a = NULL;
|
|
|
|
|
if (fval(u, UFL_GROUP)) {
|
|
|
|
|
a = a_find(u->attribs, &at_group);
|
|
|
|
|
}
|
|
|
|
|
if (a) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
group *g = (group *) a->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
a_removeall(&g->attribs, &at_raceprefix);
|
|
|
|
|
} else {
|
|
|
|
|
a_removeall(&u->faction->attribs, &at_raceprefix);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 00:04:23 +02:00
|
|
|
|
if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) {
|
2010-08-08 10:06:34 +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)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->attribs, &at_group);
|
|
|
|
|
group *g = (group *) a->data.v;
|
|
|
|
|
if (a)
|
|
|
|
|
ap = &g->attribs;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
set_prefix(ap, race_prefixes[var.i]);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
if (rule_region_owners()) {
|
|
|
|
|
return &cmp_current_owner;
|
|
|
|
|
} else {
|
|
|
|
|
return &cmp_wage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
|
int display_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
char **s = NULL;
|
2012-05-16 21:06:44 +02:00
|
|
|
|
const char *str;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
2012-05-16 21:06:44 +02:00
|
|
|
|
str = getstrtoken();
|
|
|
|
|
switch (findparam_ex(str, u->faction->locale)) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_BUILDING:
|
|
|
|
|
case P_GEBAEUDE:
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (!u->building) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 145, MSG_PRODUCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (building_owner(u->building)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 5, MSG_PRODUCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (!fval(u->building->type, BTF_NAMECHANGE) && u->building->display && u->building->display[0]) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 278, MSG_EVENT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
s = &u->building->display;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_SHIP:
|
|
|
|
|
if (!u->ship) {
|
|
|
|
|
cmistake(u, ord, 144, MSG_PRODUCE);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (ship_owner(u->ship)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 12, MSG_PRODUCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
s = &u->ship->display;
|
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_UNIT:
|
|
|
|
|
s = &u->display;
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_PRIVAT:
|
|
|
|
|
{
|
|
|
|
|
const char *d = getstrtoken();
|
|
|
|
|
if (d == NULL || *d == 0) {
|
|
|
|
|
usetprivate(u, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
usetprivate(u, d);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case P_REGION:
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (!u->building) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 145, MSG_EVENT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (building_owner(u->building)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 148, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (u->building != largestbuilding(r, get_cmp_region_owner(), false)) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 147, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
s = &r->display;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
cmistake(u, ord, 110, MSG_EVENT);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (s != NULL) {
|
|
|
|
|
const char *s2 = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
free(*s);
|
2013-12-29 14:38:58 +01:00
|
|
|
|
*s = _strdup(s2);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (strlen(s2) >= DISPLAYSIZE) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
(*s)[DISPLAYSIZE] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool renamed_building(const building * b)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const struct locale *lang = locales;
|
2012-05-17 09:13:30 +02:00
|
|
|
|
size_t len = strlen(b->name);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (; lang; lang = nextlocale(lang)) {
|
|
|
|
|
const char *bdname = LOC(lang, b->type->_name);
|
2012-05-17 09:13:30 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
if (!s2[0]) {
|
|
|
|
|
cmistake(u, ord, 84, MSG_EVENT);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: Validate to make sure people don't have illegal characters in
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* names, phishing-style? () come to mind. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
free(*s);
|
2013-12-29 14:38:58 +01:00
|
|
|
|
*s = _strdup(s2);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (strlen(s2) >= NAMESIZE) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
(*s)[NAMESIZE] = 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 06:16:47 +01:00
|
|
|
|
int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
rename_building(unit * u, order * ord, building * b, const char *name)
|
|
|
|
|
{
|
|
|
|
|
unit *owner = b ? building_owner(b) : 0;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool foreign = !(owner && owner->faction == u->faction);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (!b) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
cmistake(u, ord, u->building ? 6 : 145, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fval(b->type, BTF_NAMECHANGE) && renamed_building(b)) {
|
|
|
|
|
cmistake(u, ord, 278, MSG_EVENT);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (foreign) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (renamed_building(b)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 246, MSG_EVENT);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 08:33:38 +02:00
|
|
|
|
if (owner) {
|
|
|
|
|
if (cansee(owner->faction, u->region, u, 0)) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&owner->faction->msgs,
|
|
|
|
|
msg_message("renamed_building_seen",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"building renamer region", b, u, u->region));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&owner->faction->msgs,
|
|
|
|
|
msg_message("renamed_building_notseen",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"building region", b, u->region));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (owner!=u) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 148, MSG_PRODUCE);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 08:33:38 +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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
building *b = u->building;
|
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
char **s = NULL;
|
|
|
|
|
param_t p;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool foreign = false;
|
2012-05-16 21:06:44 +02:00
|
|
|
|
const char *str;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
2012-05-16 21:06:44 +02:00
|
|
|
|
str = getstrtoken();
|
|
|
|
|
p = findparam_ex(str, u->faction->locale);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (p == P_FOREIGN) {
|
2012-05-16 21:06:44 +02:00
|
|
|
|
str = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
foreign = true;
|
2012-05-16 21:06:44 +02:00
|
|
|
|
p = findparam_ex(str, u->faction->locale);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (p) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_ALLIANCE:
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (!foreign && f_get_alliance(u->faction)) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
alliance *al = u->faction->alliance;
|
|
|
|
|
faction *lead = alliance_get_leader(al);
|
|
|
|
|
if (lead == u->faction) {
|
|
|
|
|
s = &al->name;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case P_BUILDING:
|
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
|
if (foreign) {
|
|
|
|
|
b = getbuilding(u->region);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
return rename_building(u, ord, b, getstrtoken());
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_FACTION:
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (foreign) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
faction *f;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
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;
|
|
|
|
|
for (; lang; lang = nextlocale(lang)) {
|
|
|
|
|
const char *fdname = LOC(lang, "factiondefault");
|
|
|
|
|
size_t fdlen = strlen(fdname);
|
|
|
|
|
if (strlen(f->name) >= fdlen && strncmp(f->name, fdname, fdlen) == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (lang == NULL) {
|
|
|
|
|
cmistake(u, ord, 247, MSG_EVENT);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
if (cansee(f, r, u, 0)) {
|
|
|
|
|
ADDMSG(&f->msgs,
|
|
|
|
|
msg_message("renamed_faction_seen", "unit region", u, r));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&f->msgs, msg_message("renamed_faction_notseen", "", r));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = &f->name;
|
|
|
|
|
} else {
|
|
|
|
|
s = &u->faction->name;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_SHIP:
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (foreign) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ship *sh = getship(r);
|
|
|
|
|
unit *uo;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (!sh) {
|
|
|
|
|
cmistake(u, ord, 20, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
const struct locale *lang = locales;
|
|
|
|
|
for (; lang; lang = nextlocale(lang)) {
|
2014-06-13 07:14:07 +02:00
|
|
|
|
const char *sdname = LOC(lang, sh->type->_name);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
size_t sdlen = strlen(sdname);
|
|
|
|
|
if (strlen(sh->name) >= sdlen
|
|
|
|
|
&& strncmp(sh->name, sdname, sdlen) == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
|
|
|
|
|
sdname = LOC(lang, parameters[P_SHIP]);
|
|
|
|
|
sdlen = strlen(sdname);
|
|
|
|
|
if (strlen(sh->name) >= sdlen
|
|
|
|
|
&& strncmp(sh->name, sdname, sdlen) == 0) {
|
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (lang == NULL) {
|
|
|
|
|
cmistake(u, ord, 245, MSG_EVENT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-05-17 21:23:25 +02:00
|
|
|
|
uo = ship_owner(sh);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (uo) {
|
|
|
|
|
if (cansee(uo->faction, r, u, 0)) {
|
|
|
|
|
ADDMSG(&uo->faction->msgs,
|
|
|
|
|
msg_message("renamed_ship_seen", "ship renamer region", sh, u, r));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&uo->faction->msgs,
|
|
|
|
|
msg_message("renamed_ship_notseen", "ship region", sh, r));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = &sh->name;
|
|
|
|
|
} else {
|
|
|
|
|
if (!u->ship) {
|
|
|
|
|
cmistake(u, ord, 144, MSG_PRODUCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (ship_owner(u->ship)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 12, MSG_PRODUCE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = &u->ship->name;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_UNIT:
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (foreign) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
unit *u2 = getunit(r, u->faction);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (!u2 || !cansee(u->faction, r, u2, 0)) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
|
"feedback_unit_not_found", ""));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
} else {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
const char *udefault = LOC(u2->faction->locale, "unitdefault");
|
|
|
|
|
size_t udlen = strlen(udefault);
|
|
|
|
|
size_t unlen = strlen(u2->name);
|
|
|
|
|
if (unlen >= udlen && strncmp(u2->name, udefault, udlen) != 0) {
|
|
|
|
|
cmistake(u2, ord, 244, MSG_EVENT);
|
|
|
|
|
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));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = &u2->name;
|
|
|
|
|
} else {
|
|
|
|
|
s = &u->name;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case P_REGION:
|
|
|
|
|
if (!b) {
|
|
|
|
|
cmistake(u, ord, 145, MSG_EVENT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (building_owner(b)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 148, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b != largestbuilding(r, get_cmp_region_owner(), false)) {
|
|
|
|
|
cmistake(u, ord, 147, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
s = &r->land->name;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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 {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
cmistake(u, ord, 109, MSG_EVENT);
|
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
cmistake(u, ord, 109, MSG_EVENT);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (s != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return rename_cmd(u, ord, s, getstrtoken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (!cansee(f, r, u, 0)) {
|
|
|
|
|
u = NULL;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!receiver) { /* BOTSCHAFT an PARTEI */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&f->msgs,
|
|
|
|
|
msg_message("regionmessage", "region sender string", r, u, s));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else { /* BOTSCHAFT an EINHEIT */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&f->msgs,
|
|
|
|
|
msg_message("unitmessage", "region unit sender string", r,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
receiver, u, s));
|
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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u2 = findunitr(r, n);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (u2 && cansee(u->faction, r, u2, 0)) {
|
|
|
|
|
deliverMail(u2->faction, r, u, s, u2);
|
|
|
|
|
/* now done in prepare_mail_cmd */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
/* Immer eine Meldung - sonst koennte man so getarnte EHs enttarnen:
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* keine Meldung -> EH hier. */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
|
|
f = findfaction(n);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f && n > 0)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
deliverMail(f, u->region, u, s, NULL);
|
|
|
|
|
else
|
|
|
|
|
cmistake(u, ord, 66, MSG_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
|
int mail_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r = u->region;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u2;
|
|
|
|
|
const char *s;
|
|
|
|
|
int n, cont;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
skip_token(); /* skip the keyword */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
/* Falls kein Parameter, ist das eine Einheitsnummer;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* das F<EFBFBD>llwort "AN" mu<EFBFBD> wegfallen, da g<EFBFBD>ltige Nummer! */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
cont = 0;
|
2012-05-16 21:06:44 +02:00
|
|
|
|
switch (findparam_ex(s, u->faction->locale)) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_REGION:
|
|
|
|
|
/* k<>nnen alle Einheiten in der Region sehen */
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (!s[0]) {
|
|
|
|
|
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
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_FACTION:
|
|
|
|
|
{
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool see = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
n = getfactionid();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) {
|
|
|
|
|
see = true;
|
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
|
|
|
|
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (!see) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 66, MSG_MESSAGE);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (!s[0]) {
|
|
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
mailfaction(u, n, ord, s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_UNIT:
|
|
|
|
|
{
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool see = false;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
n = getid();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u2->no == n && cansee(u->faction, r, u2, 0)) {
|
|
|
|
|
see = true;
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (!see) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
|
|
|
|
"feedback_unit_not_found", ""));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (!s[0]) {
|
|
|
|
|
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);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
|
|
|
|
|
mailunit(r, u, n, ord, s);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_BUILDING:
|
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
|
{
|
|
|
|
|
building *b = getbuilding(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (!b) {
|
|
|
|
|
cmistake(u, ord, 6, MSG_MESSAGE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (!s[0]) {
|
|
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next)
|
|
|
|
|
freset(u2->faction, FFL_SELECT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01: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);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_SHIP:
|
|
|
|
|
{
|
|
|
|
|
ship *sh = getship(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (!sh) {
|
|
|
|
|
cmistake(u, ord, 20, MSG_MESSAGE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = getstrtoken();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (!s[0]) {
|
|
|
|
|
cmistake(u, ord, 30, MSG_MESSAGE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next)
|
|
|
|
|
freset(u2->faction, FFL_SELECT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01: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);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
default:
|
|
|
|
|
/* possibly filler token? */
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (s && *s)
|
|
|
|
|
cont = 1;
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
while (cont);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 149, MSG_MESSAGE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
free(u->faction->banner);
|
2013-12-29 14:38:58 +01:00
|
|
|
|
u->faction->banner = _strdup(getstrtoken());
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_message(&u->faction->msgs, msg_message("changebanner", "value",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->faction->banner));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
|
int email_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if (!s[0]) {
|
|
|
|
|
cmistake(u, ord, 85, MSG_EVENT);
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f = u->faction;
|
|
|
|
|
if (set_email(&f->email, (const char *)s) != 0) {
|
2012-05-17 01:52:01 +02:00
|
|
|
|
log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), s);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s));
|
|
|
|
|
} else {
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("changemail", "value", f->email));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
|
int password_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
char pwbuf[32];
|
|
|
|
|
int i;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool pwok = true;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if (!s || !*s) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
|
pwbuf[i] = (char)(97 + rng_int() % 26);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pwbuf[6] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
char *c;
|
|
|
|
|
|
|
|
|
|
strlcpy(pwbuf, (const char *)s, 31);
|
|
|
|
|
pwbuf[31] = 0;
|
|
|
|
|
c = pwbuf;
|
|
|
|
|
while (*c && pwok) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!isalnum(*(unsigned char *)c))
|
|
|
|
|
pwok = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(u->faction->passw);
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (!pwok) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 283, MSG_EVENT);
|
2013-12-29 14:38:58 +01:00
|
|
|
|
u->faction->passw = _strdup(itoa36(rng_int()));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2013-12-29 14:38:58 +01:00
|
|
|
|
u->faction->passw = _strdup(pwbuf);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"value", u->faction->passw));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
|
int send_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int option;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
option = findoption(s, u->faction->locale);
|
|
|
|
|
|
|
|
|
|
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 {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->faction->options = u->faction->options & ~(1 << option);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool display_item(faction * f, unit * u, const item_type * itype)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *key;
|
|
|
|
|
const char *info;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int i = i_get(u->items, itype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i == 0) {
|
|
|
|
|
if (u->region->land != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i = i_get(u->region->land->items, itype);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i = i_get(u->faction->items, itype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i == 0)
|
|
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name = resourcename(itype->rtype, 0);
|
|
|
|
|
key = mkname("iteminfo", name);
|
|
|
|
|
info = locale_getstring(f->locale, key);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (info == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
info = locale_string(f->locale, mkname("iteminfo", "no_info"));
|
|
|
|
|
}
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("displayitem", "weight item description",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
itype->weight, itype->rtype, info));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool display_potion(faction * f, unit * u, const potion_type * ptype)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
attrib *a;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ptype == NULL)
|
|
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
else {
|
|
|
|
|
int i = i_get(u->items, ptype->itype);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i == 0 && 2 * ptype->level > effskill(u, SK_ALCHEMY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a = a_find(f->attribs, &at_showitem);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (a && a->data.v != ptype)
|
|
|
|
|
a = a->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!a) {
|
|
|
|
|
a = a_add(&f->attribs, a_new(&at_showitem));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
a->data.v = (void *)ptype->itype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool display_race(faction * f, unit * u, const race * rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
const char *name, *key;
|
|
|
|
|
const char *info;
|
|
|
|
|
int a, at_count;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
char buf[2048], *bufp = buf;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
size_t size = sizeof(buf) - 1;
|
|
|
|
|
int bytes;
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u && u_race(u) != rc)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
name = rc_name(rc, 0);
|
|
|
|
|
|
|
|
|
|
bytes = slprintf(bufp, size, "%s: ", LOC(f->locale, name));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
key = mkname("raceinfo", rc->_name[0]);
|
|
|
|
|
info = locale_getstring(f->locale, key);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (info == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
info = locale_string(f->locale, mkname("raceinfo", "no_info"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytes = (int)strlcpy(bufp, info, size);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* hp_p : Trefferpunkte */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
bytes =
|
2012-05-29 21:17:25 +02:00
|
|
|
|
slprintf(bufp, size, " %d %s", rc->hitpoints, LOC(f->locale,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"stat_hitpoints"));
|
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* b_attacke : Angriff */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
bytes =
|
2012-05-29 21:17:25 +02:00
|
|
|
|
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_attack"),
|
2011-03-07 08:02:35 +01:00
|
|
|
|
(rc->at_default + rc->at_bonus));
|
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* b_defense : Verteidigung */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
bytes =
|
2012-05-29 21:17:25 +02:00
|
|
|
|
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_defense"),
|
2011-03-07 08:02:35 +01:00
|
|
|
|
(rc->df_default + rc->df_bonus));
|
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* b_armor : R<>stung */
|
|
|
|
|
if (rc->armor > 0) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
bytes =
|
2012-05-29 21:17:25 +02:00
|
|
|
|
slprintf(bufp, size, ", %s: %d", LOC(f->locale, "stat_armor"), rc->armor);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (size > 1) {
|
|
|
|
|
*bufp++ = '.';
|
2010-08-08 10:06:34 +02:00
|
|
|
|
--size;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* b_damage : Schaden */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
at_count = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
for (a = 0; a < 6; a++) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rc->attack[a].type != AT_NONE) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
at_count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rc->battle_flags & BF_EQUIPMENT) {
|
2014-03-15 20:35:20 +01:00
|
|
|
|
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment"));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (rc->battle_flags & BF_RES_PIERCE) {
|
2014-03-15 20:35:20 +01:00
|
|
|
|
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce"));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (rc->battle_flags & BF_RES_CUT) {
|
2014-03-15 20:35:20 +01:00
|
|
|
|
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut"));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (rc->battle_flags & BF_RES_BASH) {
|
2014-03-15 20:35:20 +01:00
|
|
|
|
bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash"));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
bytes =
|
2014-03-15 20:35:20 +01:00
|
|
|
|
_snprintf(bufp, size, " %d %s", at_count, LOC(f->locale,
|
2011-03-07 08:02:35 +01:00
|
|
|
|
(at_count == 1) ? "stat_attack" : "stat_attacks"));
|
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (a = 0; a < 6; a++) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (rc->attack[a].type != AT_NONE) {
|
|
|
|
|
if (a != 0)
|
|
|
|
|
bytes = (int)strlcpy(bufp, ", ", size);
|
|
|
|
|
else
|
|
|
|
|
bytes = (int)strlcpy(bufp, ": ", size);
|
|
|
|
|
if (wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
|
|
|
|
|
|
|
|
|
switch (rc->attack[a].type) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case AT_STANDARD:
|
|
|
|
|
bytes =
|
2014-03-15 20:35:20 +01:00
|
|
|
|
_snprintf(bufp, size, "%s (%s)",
|
2011-03-08 08:44:20 +01:00
|
|
|
|
LOC(f->locale, "attack_standard"), rc->def_damage);
|
|
|
|
|
break;
|
|
|
|
|
case AT_NATURAL:
|
|
|
|
|
bytes =
|
2014-03-15 20:35:20 +01:00
|
|
|
|
_snprintf(bufp, size, "%s (%s)",
|
2011-03-08 08:44:20 +01:00
|
|
|
|
LOC(f->locale, "attack_natural"), rc->attack[a].data.dice);
|
|
|
|
|
break;
|
|
|
|
|
case AT_SPELL:
|
|
|
|
|
case AT_COMBATSPELL:
|
|
|
|
|
case AT_DRAIN_ST:
|
2014-02-16 04:12:31 +01:00
|
|
|
|
case AT_DRAIN_EXP:
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case AT_DAZZLE:
|
2014-03-15 20:35:20 +01:00
|
|
|
|
bytes = _snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical"));
|
2011-03-08 08:44:20 +01:00
|
|
|
|
break;
|
|
|
|
|
case AT_STRUCTURAL:
|
|
|
|
|
bytes =
|
2014-03-15 20:35:20 +01:00
|
|
|
|
_snprintf(bufp, size, "%s (%s)",
|
2011-03-08 08:44:20 +01:00
|
|
|
|
LOC(f->locale, "attack_structural"), rc->attack[a].data.dice);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
bytes = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (size > 1) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
*bufp++ = '.';
|
|
|
|
|
--size;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else
|
|
|
|
|
WARN_STATIC_BUFFER();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
*bufp = 0;
|
|
|
|
|
addmessage(0, f, buf, MSG_EVENT, ML_IMPORTANT);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
int skill, c;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const potion_type *ptype;
|
|
|
|
|
const item_type *itype;
|
2012-05-09 22:06:16 +02:00
|
|
|
|
const spell *sp = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const race *rc;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
switch (p) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_ZAUBER:
|
|
|
|
|
a_removeall(&u->faction->attribs, &at_seenspell);
|
|
|
|
|
break;
|
|
|
|
|
case P_POTIONS:
|
|
|
|
|
skill = effskill(u, SK_ALCHEMY);
|
|
|
|
|
c = 0;
|
|
|
|
|
for (ptype = potiontypes; ptype != NULL; ptype = ptype->next) {
|
|
|
|
|
if (ptype->level * 2 <= skill) {
|
|
|
|
|
c += display_potion(u->faction, u, ptype);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (c == 0)
|
|
|
|
|
cmistake(u, ord, 285, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
case NOPARAM:
|
2012-05-26 20:29:27 +02:00
|
|
|
|
if (s) {
|
|
|
|
|
/* check if it's an item */
|
|
|
|
|
itype = finditemtype(s, u->faction->locale);
|
|
|
|
|
if (itype != NULL) {
|
|
|
|
|
ptype = resource2potion(item2resource(itype));
|
|
|
|
|
if (ptype != NULL) {
|
|
|
|
|
if (display_potion(u->faction, u, ptype))
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
if (display_item(u->faction, u, itype))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-05-26 20:29:27 +02:00
|
|
|
|
/* try for a spell */
|
|
|
|
|
sp = unit_getspell(u, s, u->faction->locale);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-05-09 22:06:16 +02:00
|
|
|
|
}
|
2012-05-26 20:29:27 +02:00
|
|
|
|
/* last, check if it's a race. */
|
|
|
|
|
rc = findrace(s, u->faction->locale);
|
|
|
|
|
if (rc != NULL && display_race(u->faction, u, rc)) {
|
|
|
|
|
break;
|
2012-05-09 22:06:16 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
cmistake(u, ord, 21, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
cmistake(u, ord, 222, MSG_EVENT);
|
|
|
|
|
break;
|
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
|
|
|
|
{
|
|
|
|
|
int money, people;
|
|
|
|
|
|
|
|
|
|
if (fval(u, UFL_HERO)) {
|
|
|
|
|
/* TODO: message "is already a hero" */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (maxheroes(u->faction) < countheroes(u->faction) + u->number) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, ord, "heroes_maxed", "max count",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
maxheroes(u->faction), countheroes(u->faction)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!valid_race(u->faction, u_race(u))) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "heroes_race", "race",
|
2013-05-02 03:42:20 +02:00
|
|
|
|
u_race(u)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
people = count_all(u->faction) * u->number;
|
|
|
|
|
money = get_pooled(u, i_silver->rtype, GET_ALL, people);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (people > money) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, ord, "heroes_cost", "cost have", people, money));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
use_pooled(u, i_silver->rtype, GET_ALL, people);
|
|
|
|
|
fset(u, UFL_HERO);
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("hero_promotion", "unit cost",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
join_group(u, s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-07 18:47:02 +02:00
|
|
|
|
int origin_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
short px, py;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
px = (short)getint();
|
|
|
|
|
py = (short)getint();
|
|
|
|
|
|
|
|
|
|
set_ursprung(u->faction, getplaneid(u->region), px, py);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-18 08:13:58 +02:00
|
|
|
|
int guard_off_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(get_keyword(ord) == K_GUARD);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
if (getparam(u->faction->locale) == P_NOT) {
|
|
|
|
|
setguard(u, GUARD_NONE);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
|
int reshow_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
param_t p = NOPARAM;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
2012-05-20 04:54:14 +02:00
|
|
|
|
if (isparam(s, u->faction->locale, P_ANY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
p = getparam(u->faction->locale);
|
|
|
|
|
s = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reshow(u, ord, s, p);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
|
int status_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *param;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
param = getstrtoken();
|
|
|
|
|
switch (findparam(param, u->faction->locale)) {
|
2011-03-08 08:44:20 +01: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:
|
|
|
|
|
if (param[0]) {
|
|
|
|
|
add_message(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, ord, "unknown_status", ""));
|
|
|
|
|
} else {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
setstatus(u, ST_FIGHT);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-17 21:51:48 +02:00
|
|
|
|
int combatspell_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int level = 0;
|
2012-05-09 22:06:16 +02:00
|
|
|
|
spell *sp = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
/* KAMPFZAUBER [NICHT] l<>scht alle gesetzten Kampfzauber */
|
|
|
|
|
if (!s || *s == 0 || findparam(s, u->faction->locale) == P_NOT) {
|
|
|
|
|
unset_combatspell(u, 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Optional: STUFE n */
|
|
|
|
|
if (findparam(s, u->faction->locale) == P_LEVEL) {
|
|
|
|
|
/* Merken, setzen kommt erst sp<73>ter */
|
|
|
|
|
level = getint();
|
2014-03-16 05:03:17 +01:00
|
|
|
|
level = _max(0, level);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
s = getstrtoken();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 07:25:23 +02:00
|
|
|
|
sp = unit_getspell(u, s, u->faction->locale);
|
2012-05-09 22:06:16 +02:00
|
|
|
|
if (!sp) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 173, MSG_MAGIC);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
|
|
|
|
|
if (findparam(s, u->faction->locale) == P_NOT) {
|
|
|
|
|
/* KAMPFZAUBER "<Spruchname>" NICHT l<>scht diesen speziellen
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* Kampfzauber */
|
2012-05-09 22:06:16 +02:00
|
|
|
|
unset_combatspell(u, sp);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
/* KAMPFZAUBER "<Spruchname>" setzt diesen Kampfzauber */
|
2012-05-09 22:06:16 +02:00
|
|
|
|
set_combatspell(u, sp, ord, level);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
/* Beachten: einige Monster sollen auch unbewaffent die Region bewachen
|
|
|
|
|
* k<EFBFBD>nnen */
|
|
|
|
|
|
|
|
|
|
enum { E_GUARD_OK, E_GUARD_UNARMED, E_GUARD_NEWBIE, E_GUARD_FLEEING };
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int can_start_guarding(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->status >= ST_FLEE)
|
|
|
|
|
return E_GUARD_FLEEING;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (fval(u_race(u), RCF_UNARMEDGUARD))
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return E_GUARD_OK;
|
|
|
|
|
if (!armedmen(u, true))
|
|
|
|
|
return E_GUARD_UNARMED;
|
|
|
|
|
if (IsImmune(u->faction))
|
|
|
|
|
return E_GUARD_NEWBIE;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return E_GUARD_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void update_guards(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
const region *r;
|
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit *u;
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (fval(u, UFL_GUARD)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (can_start_guarding(u) != E_GUARD_OK) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
setguard(u, GUARD_NONE);
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
attrib *a = a_find(u->attribs, &at_guard);
|
|
|
|
|
if (a && a->data.i == (int)guard_flags(u)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* this is really rather not necessary */
|
|
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
assert(get_keyword(ord) == K_GUARD);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
/* GUARD NOT is handled in goard_off_cmd earlier in the turn */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (getparam(u->faction->locale) == P_NOT)
|
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +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);
|
2013-05-02 03:42:20 +02:00
|
|
|
|
} else if (fval(u_race(u), RCF_ILLUSIONARY)
|
|
|
|
|
|| u_race(u) == new_race[RC_SPELL]) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 95, MSG_EVENT);
|
|
|
|
|
} else {
|
|
|
|
|
/* Monster der Monsterpartei d<>rfen immer bewachen */
|
|
|
|
|
if (is_monsters(u->faction)) {
|
|
|
|
|
guard(u, GUARD_ALL);
|
|
|
|
|
} else {
|
|
|
|
|
int err = can_start_guarding(u);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (err == E_GUARD_OK) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
guard(u, GUARD_ALL);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (err == E_GUARD_UNARMED) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", ""));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (err == E_GUARD_FLEEING) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 320, MSG_EVENT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (err == E_GUARD_NEWBIE) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 304, MSG_EVENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
|
void sinkships(struct region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
ship **shp = &r->ships;
|
|
|
|
|
|
|
|
|
|
while (*shp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ship *sh = *shp;
|
2010-09-03 08:25:25 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!sh->type->construction || sh->size >= sh->type->construction->maxsize) {
|
|
|
|
|
if (fval(r->terrain, SEA_REGION) && (!enoughsailors(sh, r)
|
|
|
|
|
|| get_captain(sh) == NULL)) {
|
2010-09-03 08:25:25 +02:00
|
|
|
|
/* Schiff nicht seet<65>chtig */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
float dmg = get_param_flt(global.parameters,
|
|
|
|
|
"rules.ship.damage.nocrewocean",
|
2011-03-07 08:02:35 +01:00
|
|
|
|
0.30F);
|
2011-03-06 12:11:57 +01:00
|
|
|
|
damage_ship(sh, dmg);
|
2010-09-03 08:25:25 +02:00
|
|
|
|
}
|
2012-05-17 21:23:25 +02:00
|
|
|
|
if (ship_owner(sh) == NULL) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
float dmg = get_param_flt(global.parameters, "rules.ship.damage.nocrew",
|
|
|
|
|
0.05F);
|
2011-03-06 12:11:57 +01:00
|
|
|
|
damage_ship(sh, dmg);
|
2010-09-03 08:25:25 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (sh->damage >= sh->size * DAMAGE_SCALE) {
|
|
|
|
|
remove_ship(shp, sh);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (*shp == sh)
|
|
|
|
|
shp = &sh->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The following functions do not really belong here: */
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
#include <kernel/build.h>
|
|
|
|
|
|
|
|
|
|
static attrib_type at_number = {
|
|
|
|
|
"faction_renum",
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL,
|
|
|
|
|
ATF_UNIQUE
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-17 08:31:25 +02:00
|
|
|
|
void renumber_factions(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* gibt parteien neue nummern */
|
|
|
|
|
{
|
|
|
|
|
struct renum {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct renum *next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int want;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *faction;
|
|
|
|
|
attrib *attrib;
|
|
|
|
|
} *renum = NULL, *rp;
|
|
|
|
|
faction *f;
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
|
attrib *a = a_find(f->attribs, &at_number);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int want;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct renum **rn;
|
|
|
|
|
faction *old;
|
|
|
|
|
|
|
|
|
|
if (!a)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
want = a->data.i;
|
|
|
|
|
if (fval(f, FFL_NEWID)) {
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("renumber_twice", "id", want));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
old = findfaction(want);
|
|
|
|
|
if (old) {
|
|
|
|
|
a_remove(&f->attribs, a);
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("renumber_inuse", "id", want));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!faction_id_is_unused(want)) {
|
|
|
|
|
a_remove(&f->attribs, a);
|
|
|
|
|
ADDMSG(&f->msgs, msg_message("renumber_inuse", "id", want));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (rn = &renum; *rn; rn = &(*rn)->next) {
|
|
|
|
|
if ((*rn)->want >= want)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (*rn && (*rn)->want == want) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&f->msgs, msg_message("renumber_inuse", "id", want));
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct renum *r = calloc(sizeof(struct renum), 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
r->next = *rn;
|
|
|
|
|
r->attrib = a;
|
|
|
|
|
r->faction = f;
|
|
|
|
|
r->want = want;
|
|
|
|
|
*rn = r;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (rp = renum; rp; rp = rp->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
f = rp->faction;
|
|
|
|
|
a_remove(&f->attribs, rp->attrib);
|
|
|
|
|
renumber_faction(f, rp->want);
|
|
|
|
|
}
|
|
|
|
|
while (renum) {
|
|
|
|
|
rp = renum->next;
|
|
|
|
|
free(renum);
|
|
|
|
|
renum = rp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-17 08:31:25 +02:00
|
|
|
|
void restack_units(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
region *r;
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit **up = &r->units;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool sorted = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*up) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = *up;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!fval(u, UFL_MARK)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct order *ord;
|
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
|
|
|
|
if (get_keyword(ord) == K_SORT) {
|
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
param_t p;
|
|
|
|
|
int id;
|
|
|
|
|
unit *v;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
p = findparam(s, u->faction->locale);
|
|
|
|
|
id = getid();
|
|
|
|
|
v = findunit(id);
|
|
|
|
|
|
2012-05-19 07:34:04 +02:00
|
|
|
|
if (!v || v->faction != u->faction || v->region != r) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 258, MSG_EVENT);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (v->building != u->building || v->ship != u->ship) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 259, MSG_EVENT);
|
2012-05-18 01:40:50 +02:00
|
|
|
|
} else if (u->building && building_owner(u->building)==u) {
|
|
|
|
|
cmistake(u, ord, 260, MSG_EVENT);
|
|
|
|
|
} else if (u->ship && ship_owner(u->ship)==u) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 260, MSG_EVENT);
|
|
|
|
|
} else if (v == u) {
|
|
|
|
|
cmistake(u, ord, 10, MSG_EVENT);
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
switch (p) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_AFTER:
|
|
|
|
|
*up = u->next;
|
|
|
|
|
u->next = v->next;
|
|
|
|
|
v->next = u;
|
|
|
|
|
fset(u, UFL_MARK);
|
|
|
|
|
sorted = true;
|
|
|
|
|
break;
|
|
|
|
|
case P_BEFORE:
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (v->ship && ship_owner(v->ship)==v) {
|
|
|
|
|
cmistake(v, ord, 261, MSG_EVENT);
|
|
|
|
|
} else if (v->building && building_owner(v->building)==v) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(v, ord, 261, MSG_EVENT);
|
|
|
|
|
} else {
|
|
|
|
|
unit **vp = &r->units;
|
|
|
|
|
while (*vp != v)
|
|
|
|
|
vp = &(*vp)->next;
|
|
|
|
|
*vp = u;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
*up = u->next;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
u->next = v;
|
|
|
|
|
}
|
|
|
|
|
fset(u, UFL_MARK);
|
|
|
|
|
sorted = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* TODO: syntax error message? */
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u == *up)
|
|
|
|
|
up = &u->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (sorted) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
freset(u, UFL_MARK);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-17 08:31:25 +02:00
|
|
|
|
int renumber_cmd(unit * u, order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *s;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int i;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f = u->faction;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
2012-05-16 21:06:44 +02:00
|
|
|
|
switch (findparam_ex(s, u->faction->locale)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_FACTION:
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (s && *s) {
|
|
|
|
|
int id = atoi36((const char *)s);
|
|
|
|
|
attrib *a = a_find(f->attribs, &at_number);
|
|
|
|
|
if (!a)
|
|
|
|
|
a = a_add(&f->attribs, a_new(&at_number));
|
|
|
|
|
a->data.i = id;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case P_UNIT:
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (s == NULL || *s == 0) {
|
|
|
|
|
i = newunitid();
|
|
|
|
|
} else {
|
|
|
|
|
i = atoi36((const char *)s);
|
|
|
|
|
if (i <= 0 || i > MAX_UNIT_NR) {
|
|
|
|
|
cmistake(u, ord, 114, MSG_EVENT);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (forbiddenid(i)) {
|
|
|
|
|
cmistake(u, ord, 116, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
|
|
|
|
|
if (findunitg(i, u->region)) {
|
|
|
|
|
cmistake(u, ord, 115, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
uunhash(u);
|
|
|
|
|
if (!ualias(u)) {
|
|
|
|
|
attrib *a = a_add(&u->attribs, a_new(&at_alias));
|
|
|
|
|
a->data.i = -u->no;
|
|
|
|
|
}
|
|
|
|
|
u->no = i;
|
|
|
|
|
uhash(u);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case P_SHIP:
|
|
|
|
|
if (!u->ship) {
|
|
|
|
|
cmistake(u, ord, 144, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (ship_owner(u->ship)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 146, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-19 06:46:41 +02:00
|
|
|
|
if (u->ship->coast != NODIRECTION) {
|
|
|
|
|
cmistake(u, ord, 116, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (s == NULL || *s == 0) {
|
|
|
|
|
i = newcontainerid();
|
|
|
|
|
} else {
|
|
|
|
|
i = atoi36((const char *)s);
|
|
|
|
|
if (i <= 0 || i > MAX_CONTAINER_NR) {
|
|
|
|
|
cmistake(u, ord, 114, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (findship(i) || findbuilding(i)) {
|
|
|
|
|
cmistake(u, ord, 115, MSG_EVENT);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
sunhash(u->ship);
|
|
|
|
|
u->ship->no = i;
|
|
|
|
|
shash(u->ship);
|
|
|
|
|
break;
|
|
|
|
|
case P_BUILDING:
|
|
|
|
|
case P_GEBAEUDE:
|
|
|
|
|
if (!u->building) {
|
|
|
|
|
cmistake(u, ord, 145, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2012-05-18 01:40:50 +02:00
|
|
|
|
if (building_owner(u->building)!=u) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
cmistake(u, ord, 148, MSG_EVENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
if (*s == 0) {
|
|
|
|
|
i = newcontainerid();
|
|
|
|
|
} else {
|
|
|
|
|
i = atoi36((const char *)s);
|
|
|
|
|
if (i <= 0 || i > MAX_CONTAINER_NR) {
|
|
|
|
|
cmistake(u, ord, 114, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (findship(i) || findbuilding(i)) {
|
|
|
|
|
cmistake(u, ord, 115, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
bunhash(u->building);
|
|
|
|
|
u->building->no = i;
|
|
|
|
|
bhash(u->building);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
default:
|
|
|
|
|
cmistake(u, ord, 239, MSG_EVENT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static building *age_building(building * b)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool init = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const building_type *bt_blessed;
|
|
|
|
|
static const curse_type *ct_astralblock;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (!init) {
|
|
|
|
|
init = true;
|
|
|
|
|
bt_blessed = bt_find("blessedstonecircle");
|
|
|
|
|
ct_astralblock = ct_find("astralblock");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (ct_astralblock && bt_blessed && b->type == bt_blessed) {
|
|
|
|
|
region *r = b->region;
|
|
|
|
|
region *rt = r_standard_to_astral(r);
|
|
|
|
|
unit *u, *mage = NULL;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* step 1: give unicorns to people in the building,
|
|
|
|
|
* find out if there's a magician in there. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (b == u->building && inside_building(u)) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!(u_race(u)->ec_flags & GIVEITEM) == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int n, unicorns = 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (n = 0; n != u->number; ++n) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (chance(0.02)) {
|
|
|
|
|
i_change(&u->items, olditemtype[I_ELVENHORSE], 1);
|
|
|
|
|
++unicorns;
|
|
|
|
|
}
|
|
|
|
|
if (unicorns) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("scunicorn",
|
2011-03-08 08:44:20 +01:00
|
|
|
|
"unit amount rtype",
|
|
|
|
|
u, unicorns, olditemtype[I_ELVENHORSE]->rtype));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (mage == NULL && is_mage(u)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
mage = u;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if there's a magician, and a connection to astral space, create the
|
|
|
|
|
* curse. */
|
2013-12-29 00:15:50 +01:00
|
|
|
|
if (rt && !fval(rt->terrain, FORBIDDEN_REGION) && mage != NULL) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
curse *c = get_curse(rt->attribs, ct_astralblock);
|
|
|
|
|
if (c == NULL) {
|
|
|
|
|
if (mage != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int sk = effskill(mage, SK_MAGIC);
|
2013-12-31 10:06:28 +01:00
|
|
|
|
float effect = 100;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* the mage reactivates the circle */
|
|
|
|
|
c = create_curse(mage, &rt->attribs, ct_astralblock,
|
2014-03-16 05:03:17 +01:00
|
|
|
|
(float)_max(1, sk), _max(1, sk / 2), effect, 0);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&r->msgs,
|
|
|
|
|
msg_message("astralshield_activate", "region unit", r, mage));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (mage != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int sk = effskill(mage, SK_MAGIC);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
c->duration = _max(c->duration, sk / 2);
|
|
|
|
|
c->vigour = _max(c->vigour, sk);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a_age(&b->attribs);
|
|
|
|
|
handle_event(b->attribs, "timer", b);
|
|
|
|
|
|
|
|
|
|
if (b->type->age) {
|
|
|
|
|
b->type->age(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static double rc_popularity(const struct race *rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int pop = get_param_int(rc->parameters, "morale", MORALE_AVERAGE);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return 1.0 / (pop - MORALE_COOLDOWN); /* 10 turns average */
|
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
|
|
|
|
{
|
|
|
|
|
a_age(&r->attribs);
|
|
|
|
|
handle_event(r->attribs, "timer", r);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!r->land)
|
|
|
|
|
return;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (r->land->ownership && r->land->ownership->owner) {
|
|
|
|
|
int stability = turn - r->land->ownership->morale_turn;
|
|
|
|
|
int maxmorale = MORALE_DEFAULT;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
building *b = largestbuilding(r, &cmp_taxes, false);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (b) {
|
|
|
|
|
int bsize = buildingeffsize(b, false);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
maxmorale = (int)(0.5 + b->type->taxes(b, bsize + 1) / MORALE_TAX_FACTOR);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (r->land->morale < maxmorale) {
|
|
|
|
|
if (stability > MORALE_COOLDOWN && r->land->ownership->owner
|
|
|
|
|
&& r->land->morale < MORALE_MAX) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
double ch = rc_popularity(r->land->ownership->owner->race);
|
|
|
|
|
if (is_cursed(r->attribs, C_GENEROUS, 0)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ch *= 1.2; /* 20% improvement */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (stability >= MORALE_AVERAGE * 2 || chance(ch)) {
|
|
|
|
|
region_set_morale(r, r->land->morale + 1, turn);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (r->land->morale > maxmorale) {
|
|
|
|
|
region_set_morale(r, r->land->morale - 1, turn);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (r->land->morale > MORALE_DEFAULT) {
|
|
|
|
|
region_set_morale(r, r->land->morale - 1, turn);
|
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
|
|
|
|
{
|
|
|
|
|
faction *f;
|
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
|
|
/* altern spezieller Attribute, die eine Sonderbehandlung brauchen? */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Goliathwasser */
|
|
|
|
|
int i = get_effect(u, oldpotiontype[P_STRONG]);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i > 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
change_effect(u, oldpotiontype[P_STRONG], -1 * _min(u->number, i));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
/* Berserkerblut */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i = get_effect(u, oldpotiontype[P_BERSERK]);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (i > 0) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
change_effect(u, oldpotiontype[P_BERSERK], -1 * _min(u->number, i));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (is_cursed(u->attribs, C_OLDRACE, 0)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
curse *c = get_curse(u->attribs, ct_find("oldrace"));
|
|
|
|
|
if (c->duration == 1 && !(c_flags(c) & CURSE_NOAGE)) {
|
2013-05-02 03:42:20 +02:00
|
|
|
|
u_setrace(u, new_race[curse_geteffect_int(c)]);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
u->irace = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Borders */
|
|
|
|
|
age_borders();
|
|
|
|
|
|
|
|
|
|
/* Factions */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (f = factions; f; f = f->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
a_age(&f->attribs);
|
|
|
|
|
handle_event(f->attribs, "timer", f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Regionen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
building **bp;
|
|
|
|
|
unit **up;
|
|
|
|
|
ship **sp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
age_region(r);
|
|
|
|
|
|
|
|
|
|
/* Einheiten */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (up = &r->units; *up;) {
|
|
|
|
|
unit *u = *up;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
a_age(&u->attribs);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u == *up)
|
|
|
|
|
handle_event(u->attribs, "timer", u);
|
|
|
|
|
if (u == *up)
|
|
|
|
|
up = &(*up)->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Schiffe */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (sp = &r->ships; *sp;) {
|
|
|
|
|
ship *s = *sp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
a_age(&s->attribs);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (s == *sp)
|
|
|
|
|
handle_event(s->attribs, "timer", s);
|
|
|
|
|
if (s == *sp)
|
|
|
|
|
sp = &(*sp)->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Geb<65>ude */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (bp = &r->buildings; *bp;) {
|
|
|
|
|
building *b = *bp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
age_building(b);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (b == *bp)
|
|
|
|
|
bp = &b->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rule_region_owners()) {
|
|
|
|
|
update_owners(r);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int maxunits(const faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int flimit = rule_faction_limit();
|
|
|
|
|
int alimit = rule_alliance_limit();
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (alimit == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return flimit;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (flimit == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return alimit;
|
|
|
|
|
}
|
2014-03-16 05:03:17 +01:00
|
|
|
|
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;
|
|
|
|
|
int flags = COUNT_DEFAULT|COUNT_MIGRANTS|COUNT_UNITS;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
region *r;
|
|
|
|
|
unit *u, *u2;
|
|
|
|
|
|
|
|
|
|
/* neue einheiten werden gemacht und ihre befehle (bis zum "ende" zu
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* ihnen rueberkopiert, damit diese einheiten genauso wie die alten
|
|
|
|
|
* einheiten verwendet werden koennen. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order **ordp = &u->orders;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* this needs to happen very early in the game somewhere. since this is
|
2011-03-07 08:02:35 +01:00
|
|
|
|
** pretty much the first function called per turn, and I am lazy, I
|
|
|
|
|
** decree that it goes here */
|
|
|
|
|
if (u->flags & UFL_GUARD) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
fset(r, RF_GUARDED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (*ordp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *makeord = *ordp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (get_keyword(makeord) == K_MAKE) {
|
|
|
|
|
init_tokens(makeord);
|
|
|
|
|
skip_token();
|
2012-05-16 21:06:44 +02:00
|
|
|
|
if (isparam(getstrtoken(), u->faction->locale, P_TEMP)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *token;
|
|
|
|
|
char *name = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int alias;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ship *sh;
|
|
|
|
|
order **newordersp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int err = checkunitnumber(u->faction, 1);
|
|
|
|
|
|
|
|
|
|
if (err) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (err == 1) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, makeord,
|
|
|
|
|
"too_many_units_in_alliance",
|
|
|
|
|
"allowed", maxunits(u->faction)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} else {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs,
|
|
|
|
|
msg_feedback(u, makeord,
|
|
|
|
|
"too_many_units_in_faction",
|
|
|
|
|
"allowed", maxunits(u->faction)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
ordp = &makeord->next;
|
|
|
|
|
|
|
|
|
|
while (*ordp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord = *ordp;
|
|
|
|
|
if (get_keyword(ord) == K_END)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
*ordp = ord->next;
|
|
|
|
|
ord->next = NULL;
|
|
|
|
|
free_order(ord);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
alias = getid();
|
|
|
|
|
|
|
|
|
|
token = getstrtoken();
|
|
|
|
|
if (token && token[0]) {
|
2013-12-29 14:38:58 +01:00
|
|
|
|
name = _strdup(token);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-05-19 06:26:41 +02:00
|
|
|
|
u2 = create_unit(r, u->faction, 0, u->faction->race, alias, name, u);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (name != NULL)
|
|
|
|
|
free(name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
fset(u2, UFL_ISNEW);
|
|
|
|
|
|
|
|
|
|
a_add(&u2->attribs, a_new(&at_alias))->data.i = alias;
|
|
|
|
|
sh = leftship(u);
|
2012-05-17 09:13:30 +02:00
|
|
|
|
if (sh) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
set_leftship(u2, sh);
|
2012-05-17 09:13:30 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
setstatus(u2, u->status);
|
|
|
|
|
|
|
|
|
|
ordp = &makeord->next;
|
|
|
|
|
newordersp = &u2->orders;
|
|
|
|
|
while (*ordp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord = *ordp;
|
|
|
|
|
if (get_keyword(ord) == K_END)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
*ordp = ord->next;
|
|
|
|
|
ord->next = NULL;
|
|
|
|
|
*newordersp = ord;
|
|
|
|
|
newordersp = &ord->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (*ordp == makeord)
|
|
|
|
|
ordp = &makeord->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-12 05:11:19 +01:00
|
|
|
|
/** Checks for two long orders and issues a warning if necessary.
|
|
|
|
|
*/
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void check_long_orders(unit * u)
|
|
|
|
|
{
|
2010-11-12 05:11:19 +01:00
|
|
|
|
order *ord;
|
|
|
|
|
keyword_t otherorder = MAXKEYWORDS;
|
|
|
|
|
|
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
|
|
|
|
if (get_keyword(ord) == NOKEYWORD) {
|
|
|
|
|
cmistake(u, ord, 22, MSG_EVENT);
|
|
|
|
|
} else if (is_long(ord)) {
|
|
|
|
|
keyword_t longorder = get_keyword(ord);
|
|
|
|
|
if (otherorder != MAXKEYWORDS) {
|
|
|
|
|
switch (longorder) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_CAST:
|
|
|
|
|
if (otherorder != longorder) {
|
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case K_BUY:
|
|
|
|
|
if (otherorder == K_SELL) {
|
|
|
|
|
otherorder = K_BUY;
|
|
|
|
|
} else {
|
2010-11-12 05:11:19 +01:00
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case K_SELL:
|
|
|
|
|
if (otherorder != K_SELL && otherorder != K_BUY) {
|
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
cmistake(u, ord, 52, MSG_EVENT);
|
2010-11-12 05:11:19 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
otherorder = longorder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 14:28:19 +02:00
|
|
|
|
void update_long_order(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
order *ord;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool trade = false;
|
|
|
|
|
bool hunger = LongHunger(u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-06-18 00:55:23 +02:00
|
|
|
|
freset(u, UFL_MOVED);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
freset(u, UFL_LONGACTION);
|
|
|
|
|
if (hunger) {
|
|
|
|
|
/* Hungernde Einheiten f<>hren NUR den default-Befehl aus */
|
|
|
|
|
set_order(&u->thisorder, default_order(u->faction->locale));
|
2010-11-12 05:11:19 +01:00
|
|
|
|
} else {
|
|
|
|
|
check_long_orders(u);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
/* check all orders for a potential new long order this round: */
|
|
|
|
|
for (ord = u->orders; ord; ord = ord->next) {
|
2010-11-12 05:11:19 +01:00
|
|
|
|
if (get_keyword(ord) == NOKEYWORD)
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (u->old_orders && is_repeated(ord)) {
|
|
|
|
|
/* this new order will replace the old defaults */
|
|
|
|
|
free_orders(&u->old_orders);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (hunger)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (hunger)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (is_exclusive(ord)) {
|
|
|
|
|
/* <20>ber dieser Zeile nur Befehle, die auch eine idle Faction machen darf */
|
|
|
|
|
if (idle(u->faction)) {
|
|
|
|
|
set_order(&u->thisorder, default_order(u->faction->locale));
|
|
|
|
|
} else {
|
|
|
|
|
set_order(&u->thisorder, copy_order(ord));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
keyword_t keyword = get_keyword(ord);
|
|
|
|
|
switch (keyword) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
/* Wenn gehandelt wird, darf kein langer Befehl ausgef<65>hrt
|
|
|
|
|
* werden. Da Handel erst nach anderen langen Befehlen kommt,
|
|
|
|
|
* mu<EFBFBD> das vorher abgefangen werden. Wir merken uns also
|
|
|
|
|
* hier, ob die Einheit handelt. */
|
|
|
|
|
case K_BUY:
|
|
|
|
|
case K_SELL:
|
|
|
|
|
/* Wenn die Einheit handelt, mu<6D> der Default-Befehl gel<65>scht
|
2012-06-17 20:08:48 +02:00
|
|
|
|
* werden.
|
|
|
|
|
* Wird je diese Ausschliesslichkeit aufgehoben, muss man aufpassen
|
|
|
|
|
* mit der Reihenfolge von Kaufen, Verkaufen etc., damit es Spielern
|
|
|
|
|
* nicht moeglich ist, Schulden zu machen. */
|
2011-03-08 08:44:20 +01:00
|
|
|
|
trade = true;
|
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case K_CAST:
|
|
|
|
|
/* dient dazu, das neben Zaubern kein weiterer Befehl
|
|
|
|
|
* ausgef<EFBFBD>hrt werden kann, Zaubern ist ein kurzer Befehl */
|
2012-07-25 22:35:30 +02:00
|
|
|
|
set_order(&u->thisorder, copy_order(ord));
|
2011-03-08 08:44:20 +01:00
|
|
|
|
break;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (hunger) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return;
|
2011-03-08 08:44:20 +01:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* Wenn die Einheit handelt, mu<6D> der Default-Befehl gel<65>scht
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* werden. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-05-23 09:09:19 +02:00
|
|
|
|
if (trade) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* fset(u, UFL_LONGACTION|UFL_NOTMOVING); */
|
|
|
|
|
set_order(&u->thisorder, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int target = read_unitid(u->faction, u->region);
|
|
|
|
|
|
|
|
|
|
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (amount > i) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
amount = i;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (amount == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return ENOITEM;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (target == -1) {
|
|
|
|
|
if (itype->use == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return EUNUSABLE;
|
|
|
|
|
}
|
|
|
|
|
return itype->use(u, itype, amount, ord);
|
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itype->useonother == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return EUNUSABLE;
|
|
|
|
|
}
|
|
|
|
|
return itype->useonother(u, target, itype, amount, ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static double heal_factor(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
static float elf_regen = -1;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
switch (old_race(u_race(u))) {
|
2011-03-08 08:44:20 +01:00
|
|
|
|
case RC_TROLL:
|
|
|
|
|
case RC_DAEMON:
|
|
|
|
|
return 1.5;
|
|
|
|
|
case RC_GOBLIN:
|
|
|
|
|
return 2.0;
|
|
|
|
|
case RC_ELF:
|
|
|
|
|
if (elf_regen < 0)
|
2013-05-02 03:42:20 +02:00
|
|
|
|
elf_regen = get_param_flt(u_race(u)->parameters, "regen.forest", 1.0F);
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (elf_regen != 1.0 && r_isforest(u->region)) {
|
|
|
|
|
return elf_regen;
|
|
|
|
|
}
|
|
|
|
|
return 1.0;
|
|
|
|
|
default:
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
region *r;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const curse_type *heal_ct = NULL;
|
|
|
|
|
if (heal_ct == NULL)
|
|
|
|
|
heal_ct = ct_find("healingzone");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit *u;
|
|
|
|
|
double healingcurse = 0;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (heal_ct != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* bonus zur<75>cksetzen */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
curse *c = get_curse(r->attribs, heal_ct);
|
|
|
|
|
if (c != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
healingcurse = curse_geteffect(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
int umhp = unit_max_hp(u) * u->number;
|
|
|
|
|
double p = 1.0;
|
|
|
|
|
|
|
|
|
|
/* hp <20>ber Maximum bauen sich ab. Wird zb durch Elixier der Macht
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* oder ver<EFBFBD>ndertes Ausdauertalent verursacht */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (u->hp > umhp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->hp -= (int)ceil((u->hp - umhp) / 2.0);
|
|
|
|
|
if (u->hp < umhp)
|
|
|
|
|
u->hp = umhp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (u_race(u)->flags & RCF_NOHEAL)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
continue;
|
|
|
|
|
if (fval(u, UFL_HUNGER))
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-08 08:44:20 +01:00
|
|
|
|
if (fval(r->terrain, SEA_REGION) && u->ship == NULL
|
|
|
|
|
&& !(canswim(u) || canfly(u))) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p *= heal_factor(u);
|
|
|
|
|
if (u->hp < umhp) {
|
|
|
|
|
#ifdef NEW_DAEMONHUNGER_RULE
|
2014-03-16 05:03:17 +01:00
|
|
|
|
double maxheal = _max(u->number, umhp / 20.0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#else
|
2014-03-16 05:03:17 +01:00
|
|
|
|
double maxheal = _max(u->number, umhp / 10.0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#endif
|
|
|
|
|
int addhp;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct building *b = inside_building(u);
|
|
|
|
|
const struct building_type *btype = b ? b->type : NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (btype == bt_find("inn")) {
|
|
|
|
|
p *= 1.5;
|
|
|
|
|
}
|
|
|
|
|
/* pro punkt 5% h<>her */
|
|
|
|
|
p *= (1.0 + healingcurse * 0.05);
|
|
|
|
|
|
|
|
|
|
maxheal = p * maxheal;
|
|
|
|
|
addhp = (int)maxheal;
|
|
|
|
|
maxheal -= addhp;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (maxheal > 0.0 && chance(maxheal))
|
|
|
|
|
++addhp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* Aufaddieren der geheilten HP. */
|
2014-03-16 05:03:17 +01:00
|
|
|
|
u->hp = _min(u->hp + addhp, umhp);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* soll man an negativer regeneration sterben k<>nnen? */
|
|
|
|
|
assert(u->hp > 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void remove_exclusive(order ** ordp)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
while (*ordp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord = *ordp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (is_exclusive(ord)) {
|
|
|
|
|
*ordp = ord->next;
|
|
|
|
|
ord->next = NULL;
|
|
|
|
|
free_order(ord);
|
|
|
|
|
} else {
|
|
|
|
|
ordp = &ord->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
|
void defaultorders(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
region *r;
|
2012-07-24 09:16:25 +02:00
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
|
assert(!keyword_disabled(K_DEFAULT));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unit *u;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool neworders = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order **ordp = &u->orders;
|
|
|
|
|
while (*ordp != NULL) {
|
|
|
|
|
order *ord = *ordp;
|
|
|
|
|
if (get_keyword(ord) == K_DEFAULT) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
char lbuf[8192];
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *new_order;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
init_tokens(ord);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
skip_token(); /* skip the keyword */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
strcpy(lbuf, getstrtoken());
|
|
|
|
|
new_order = parse_order(lbuf, u->faction->locale);
|
|
|
|
|
*ordp = ord->next;
|
|
|
|
|
ord->next = NULL;
|
|
|
|
|
free_order(ord);
|
|
|
|
|
if (!neworders) {
|
|
|
|
|
/* lange Befehle aus orders und old_orders l<>schen zu gunsten des neuen */
|
|
|
|
|
remove_exclusive(&u->orders);
|
|
|
|
|
remove_exclusive(&u->old_orders);
|
|
|
|
|
neworders = true;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ordp = &u->orders; /* we could have broken ordp */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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) {
|
|
|
|
|
int level = eff_skill(u, SK_MAGIC, u->region);
|
|
|
|
|
if (level > maxlevel) {
|
|
|
|
|
maxlevel = level;
|
|
|
|
|
}
|
|
|
|
|
if (n<numresults) {
|
|
|
|
|
results[n++] = u;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (n<numresults) {
|
|
|
|
|
results[n] = 0;
|
|
|
|
|
}
|
|
|
|
|
return maxlevel;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 19:16:39 +02:00
|
|
|
|
static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel)
|
|
|
|
|
{
|
|
|
|
|
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) {
|
2012-05-27 00:15:18 +02:00
|
|
|
|
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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
|
if (f->magiegebiet != M_NONE && !is_monsters(f)) {
|
|
|
|
|
unit *mages[MAXMAGES];
|
2012-05-26 09:33:55 +02:00
|
|
|
|
int i;
|
|
|
|
|
int maxlevel = faction_getmages(f, mages, MAXMAGES);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-05-26 19:16:39 +02:00
|
|
|
|
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) {
|
2012-05-26 23:19:35 +02:00
|
|
|
|
spellbook * common_spells = get_spellbook(magic_school[M_COMMON]);
|
2012-05-26 19:16:39 +02:00
|
|
|
|
pick_random_spells(f, maxlevel, common_spells, COMMONSPELLS);
|
2012-05-24 09:56:54 +02:00
|
|
|
|
}
|
2012-05-26 09:33:55 +02:00
|
|
|
|
}
|
|
|
|
|
show_new_spells(f, maxlevel, faction_get_spellbook(f));
|
|
|
|
|
for (i=0; i!=MAXMAGES && mages[i]; ++i) {
|
2012-05-26 17:20:26 +02:00
|
|
|
|
unit * u = mages[i];
|
|
|
|
|
sc_mage *mage = get_mage(u);
|
|
|
|
|
if (mage && mage->spellbook) {
|
|
|
|
|
int level = effskill(u, SK_MAGIC);
|
2012-05-26 09:33:55 +02:00
|
|
|
|
show_new_spells(f, level, mage->spellbook);
|
2012-05-24 09:56:54 +02:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *t;
|
2012-05-20 06:01:25 +02:00
|
|
|
|
int n, err = ENOITEM;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
t = getstrtoken();
|
|
|
|
|
n = atoi((const char *)t);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0) {
|
2012-05-20 05:00:54 +02:00
|
|
|
|
if (isparam(t, u->faction->locale, P_ANY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* BENUTZE ALLES Yanxspirit */
|
|
|
|
|
n = INT_MAX;
|
|
|
|
|
t = getstrtoken();
|
|
|
|
|
} else {
|
|
|
|
|
/* BENUTZE Yanxspirit */
|
|
|
|
|
n = 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* BENUTZE 42 Yanxspirit */
|
|
|
|
|
t = getstrtoken();
|
|
|
|
|
}
|
|
|
|
|
itype = finditemtype(t, u->faction->locale);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itype != NULL) {
|
2012-05-20 06:01:25 +02:00
|
|
|
|
err = use_item(u, itype, n, ord);
|
|
|
|
|
assert(err <= 0 || !"use_item should not return positive values.");
|
|
|
|
|
if (err > 0) {
|
2012-05-17 01:52:01 +02:00
|
|
|
|
log_error("use_item returned a value>0 for %s\n", resourcename(itype->rtype, 0));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2012-05-20 06:01:25 +02:00
|
|
|
|
}
|
|
|
|
|
switch (err) {
|
|
|
|
|
case ENOITEM:
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 43, MSG_PRODUCE);
|
2012-05-20 06:01:25 +02:00
|
|
|
|
break;
|
|
|
|
|
case EUNUSABLE:
|
|
|
|
|
cmistake(u, ord, 76, MSG_PRODUCE);
|
|
|
|
|
break;
|
|
|
|
|
case ENOSKILL:
|
|
|
|
|
cmistake(u, ord, 50, MSG_PRODUCE);
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2012-05-20 06:01:25 +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
|
|
|
|
{
|
|
|
|
|
if (!u->building) {
|
|
|
|
|
cmistake(u, ord, 6, MSG_EVENT);
|
|
|
|
|
} else {
|
|
|
|
|
param_t p;
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
p = getparam(u->faction->locale);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (p == P_NOT) {
|
|
|
|
|
unit *owner = building_owner(u->building);
|
|
|
|
|
if (owner->faction != u->faction) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
cmistake(u, ord, 1222, MSG_EVENT);
|
|
|
|
|
} else {
|
|
|
|
|
u->building->flags |= BLD_DONTPAY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-24 09:16:25 +02:00
|
|
|
|
|
|
|
|
|
int reserve_cmd(unit * u, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
|
|
|
|
|
int use, count;
|
|
|
|
|
const resource_type *rtype;
|
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
s = getstrtoken();
|
|
|
|
|
count = atoip((const char *)s);
|
|
|
|
|
|
|
|
|
|
if (count == 0 && findparam(s, u->faction->locale) == P_EACH) {
|
|
|
|
|
count = getint() * u->number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtype = findresourcetype(getstrtoken(), u->faction->locale);
|
|
|
|
|
if (rtype == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
set_resvalue(u, rtype, 0); /* make sure the pool is empty */
|
|
|
|
|
use = use_pooled(u, rtype, GET_DEFAULT, count);
|
|
|
|
|
if (use) {
|
|
|
|
|
set_resvalue(u, rtype, use);
|
|
|
|
|
change_resource(u, rtype, use);
|
|
|
|
|
return use;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int claim_cmd(unit * u, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *t;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int n;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const item_type *itype;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
|
|
|
|
|
t = getstrtoken();
|
|
|
|
|
n = atoi((const char *)t);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (n == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
n = 1;
|
|
|
|
|
} else {
|
|
|
|
|
t = getstrtoken();
|
|
|
|
|
}
|
|
|
|
|
itype = finditemtype(t, u->faction->locale);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (itype != NULL) {
|
|
|
|
|
item **iclaim = i_find(&u->faction->items, itype);
|
|
|
|
|
if (iclaim != NULL && *iclaim != NULL) {
|
2014-03-16 05:03:17 +01:00
|
|
|
|
n = _min(n, (*iclaim)->number);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
i_change(iclaim, itype, -n);
|
|
|
|
|
i_change(&u->items, itype, n);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cmistake(u, ord, 43, MSG_PRODUCE);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum {
|
2011-03-07 08:02:35 +01: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 {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
struct processor *next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
int priority;
|
2012-06-16 18:17:29 +02:00
|
|
|
|
processor_t type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
unsigned int flags;
|
|
|
|
|
union {
|
|
|
|
|
struct {
|
|
|
|
|
keyword_t kword;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int (*process) (struct unit *, struct order *);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} per_order;
|
|
|
|
|
struct {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void (*process) (struct unit *);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} per_unit;
|
|
|
|
|
struct {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void (*process) (struct region *);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} per_region;
|
|
|
|
|
struct {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void (*process) (void);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} global;
|
|
|
|
|
} data;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
processor **pproc = &processors;
|
|
|
|
|
processor *proc;
|
|
|
|
|
|
|
|
|
|
while (*pproc) {
|
|
|
|
|
proc = *pproc;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (proc->priority > priority)
|
|
|
|
|
break;
|
|
|
|
|
else if (proc->priority == priority && proc->type >= type)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pproc = &proc->next;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-16 18:17:29 +02:00
|
|
|
|
proc = (processor *)malloc(sizeof(processor));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
proc->priority = priority;
|
|
|
|
|
proc->type = type;
|
|
|
|
|
proc->name = name;
|
|
|
|
|
proc->next = *pproc;
|
|
|
|
|
*pproc = proc;
|
|
|
|
|
return proc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-07 08:02:35 +01: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-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(kword)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
processor *proc = add_proc(priority, name, PR_ORDER);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (proc) {
|
|
|
|
|
proc->data.per_order.process = parser;
|
|
|
|
|
proc->data.per_order.kword = kword;
|
|
|
|
|
proc->flags = flags;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void add_proc_global(int priority, void (*process) (void), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
processor *proc = add_proc(priority, name, PR_GLOBAL);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (proc) {
|
|
|
|
|
proc->data.global.process = process;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void add_proc_region(int priority, void (*process) (region *), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
processor *proc = add_proc(priority, name, PR_REGION_PRE);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (proc) {
|
|
|
|
|
proc->data.per_region.process = process;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-07 08:02:35 +01:00
|
|
|
|
add_proc_postregion(int priority, void (*process) (region *), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
processor *proc = add_proc(priority, name, PR_REGION_POST);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (proc) {
|
|
|
|
|
proc->data.per_region.process = process;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void add_proc_unit(int priority, void (*process) (unit *), const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
processor *proc = add_proc(priority, name, PR_UNIT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (proc) {
|
|
|
|
|
proc->data.per_unit.process = process;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
{
|
|
|
|
|
processor *proc = processors;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
while (proc) {
|
|
|
|
|
int prio = proc->priority;
|
|
|
|
|
region *r;
|
|
|
|
|
processor *pglobal = proc;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (verbosity >= 3)
|
|
|
|
|
printf("- Step %u\n", prio);
|
|
|
|
|
while (proc && proc->priority == prio) {
|
|
|
|
|
if (proc->name && verbosity >= 1)
|
2012-05-16 07:21:59 +02:00
|
|
|
|
log_printf(stdout, " - %s\n", proc->name);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
proc = proc->next;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (pglobal && pglobal->priority == prio && pglobal->type == PR_GLOBAL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pglobal->data.global.process();
|
|
|
|
|
pglobal = pglobal->next;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (pglobal == NULL || pglobal->priority != prio)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit *u;
|
|
|
|
|
processor *pregion = pglobal;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (pregion && pregion->priority == prio
|
|
|
|
|
&& pregion->type == PR_REGION_PRE) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pregion->data.per_region.process(r);
|
|
|
|
|
pregion = pregion->next;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (pregion == NULL || pregion->priority != prio)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
if (r->units) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
processor *porder, *punit = pregion;
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (punit && punit->priority == prio && punit->type == PR_UNIT) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
punit->data.per_unit.process(u);
|
|
|
|
|
punit = punit->next;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (punit == NULL || punit->priority != prio)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
porder = punit;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (porder && porder->priority == prio && porder->type == PR_ORDER) {
|
|
|
|
|
order **ordp = &u->orders;
|
2010-11-12 05:11:19 +01:00
|
|
|
|
if (porder->flags & PROC_THISORDER)
|
2011-03-07 08:02:35 +01:00
|
|
|
|
ordp = &u->thisorder;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*ordp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *ord = *ordp;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (get_keyword(ord) == porder->data.per_order.kword) {
|
|
|
|
|
if (porder->flags & PROC_LONGORDER) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->number == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ord = NULL;
|
2013-05-02 03:42:20 +02:00
|
|
|
|
} else if (u_race(u) == new_race[RC_INSECT]
|
2011-03-07 08:02:35 +01:00
|
|
|
|
&& r_insectstalled(r)
|
|
|
|
|
&& !is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ord = NULL;
|
|
|
|
|
} else if (LongHunger(u)) {
|
|
|
|
|
cmistake(u, ord, 224, MSG_MAGIC);
|
|
|
|
|
ord = NULL;
|
|
|
|
|
} else if (fval(u, UFL_LONGACTION)) {
|
2012-06-10 14:28:19 +02:00
|
|
|
|
/* this message was already given in laws.update_long_order
|
2011-03-07 08:02:35 +01:00
|
|
|
|
cmistake(u, ord, 52, MSG_PRODUCE);
|
|
|
|
|
*/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ord = NULL;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
} else if (fval(r->terrain, SEA_REGION)
|
2013-05-02 03:42:20 +02:00
|
|
|
|
&& u_race(u) != new_race[RC_AQUARIAN]
|
|
|
|
|
&& !(u_race(u)->flags & RCF_SWIM)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* error message disabled by popular demand */
|
|
|
|
|
ord = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ord) {
|
|
|
|
|
porder->data.per_order.process(u, ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!ord || *ordp == ord)
|
|
|
|
|
ordp = &(*ordp)->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
porder = porder->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (pregion && pregion->priority == prio
|
|
|
|
|
&& pregion->type != PR_REGION_POST) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pregion = pregion->next;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
while (pregion && pregion->priority == prio
|
|
|
|
|
&& pregion->type == PR_REGION_POST) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
pregion->data.per_region.process(r);
|
|
|
|
|
pregion = pregion->next;
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (pregion == NULL || pregion->priority != prio)
|
|
|
|
|
continue;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (verbosity >= 3)
|
|
|
|
|
printf("\n - Leere Gruppen loeschen...\n");
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
|
group **gp = &f->groups;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*gp) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
group *g = *gp;
|
|
|
|
|
if (g->members == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
*gp = g->next;
|
|
|
|
|
free_group(g);
|
|
|
|
|
} else
|
|
|
|
|
gp = &g->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-17 04:14:23 +02:00
|
|
|
|
int siege_cmd(unit * u, order * ord)
|
|
|
|
|
{
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
building *b;
|
|
|
|
|
int d, pooled;
|
|
|
|
|
int bewaffnete, katapultiere = 0;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
static bool init = false;
|
2012-06-17 04:14:23 +02:00
|
|
|
|
static const curse_type *magicwalls_ct;
|
|
|
|
|
static item_type *it_catapultammo = NULL;
|
|
|
|
|
static item_type *it_catapult = NULL;
|
|
|
|
|
if (!init) {
|
|
|
|
|
init = true;
|
|
|
|
|
magicwalls_ct = ct_find("magicwalls");
|
|
|
|
|
it_catapultammo = it_find("catapultammo");
|
|
|
|
|
it_catapult = it_find("catapult");
|
|
|
|
|
}
|
|
|
|
|
/* gibt es ueberhaupt Burgen? */
|
|
|
|
|
|
|
|
|
|
init_tokens(ord);
|
|
|
|
|
skip_token();
|
|
|
|
|
b = getbuilding(r);
|
|
|
|
|
|
|
|
|
|
if (!b) {
|
|
|
|
|
cmistake(u, ord, 31, MSG_BATTLE);
|
|
|
|
|
return 31;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 03:42:20 +02:00
|
|
|
|
if (!playerrace(u_race(u))) {
|
2012-06-17 04:14:23 +02:00
|
|
|
|
/* keine Drachen, Illusionen, Untote etc */
|
|
|
|
|
cmistake(u, ord, 166, MSG_BATTLE);
|
|
|
|
|
return 166;
|
|
|
|
|
}
|
|
|
|
|
/* schaden durch katapulte */
|
|
|
|
|
|
|
|
|
|
d = i_get(u->items, it_catapult);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
d = _min(u->number, d);
|
2012-06-17 04:14:23 +02:00
|
|
|
|
pooled = get_pooled(u, it_catapultammo->rtype, GET_DEFAULT, d);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
d = _min(pooled, d);
|
2012-06-17 04:14:23 +02:00
|
|
|
|
if (eff_skill(u, SK_CATAPULT, r) >= 1) {
|
|
|
|
|
katapultiere = d;
|
|
|
|
|
d *= eff_skill(u, SK_CATAPULT, r);
|
|
|
|
|
} else {
|
|
|
|
|
d = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_guard(u, GUARD_TRAVELTHRU)) {
|
|
|
|
|
/* 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! */
|
|
|
|
|
|
|
|
|
|
usetsiege(u, b);
|
2014-03-16 05:03:17 +01:00
|
|
|
|
b->besieged += _max(bewaffnete, katapultiere);
|
2012-06-17 04:14:23 +02:00
|
|
|
|
|
|
|
|
|
/* definitiver schaden eingeschraenkt */
|
|
|
|
|
|
2014-03-16 05:03:17 +01:00
|
|
|
|
d = _min(d, b->size - 1);
|
2012-06-17 04:14:23 +02:00
|
|
|
|
|
|
|
|
|
/* meldung, schaden anrichten */
|
|
|
|
|
if (d && !curse_active(get_curse(b->attribs, magicwalls_ct))) {
|
|
|
|
|
b->size -= d;
|
|
|
|
|
use_pooled(u, it_catapultammo->rtype,
|
|
|
|
|
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, d);
|
|
|
|
|
/* send message to the entire region */
|
|
|
|
|
ADDMSG(&r->msgs, msg_message("siege_catapults",
|
|
|
|
|
"unit building destruction", u, b, d));
|
|
|
|
|
} else {
|
|
|
|
|
/* send message to the entire region */
|
|
|
|
|
ADDMSG(&r->msgs, msg_message("siege", "unit building", u, b));
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void do_siege(region * r)
|
|
|
|
|
{
|
|
|
|
|
if (fval(r->terrain, LAND_REGION)) {
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (get_keyword(u->thisorder) == K_BESIEGE) {
|
|
|
|
|
siege_cmd(u, u->thisorder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void enter_1(region * r)
|
|
|
|
|
{
|
2012-06-18 02:24:23 +02:00
|
|
|
|
do_enter(r, 0);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void enter_2(region * r)
|
|
|
|
|
{
|
2012-06-18 02:24:23 +02:00
|
|
|
|
do_enter(r, 1);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void maintain_buildings_1(region * r)
|
|
|
|
|
{
|
|
|
|
|
maintain_buildings(r, false);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/** warn about passwords that are not US ASCII.
|
|
|
|
|
* even though passwords are technically UTF8 strings, the server receives
|
|
|
|
|
* them as part of the Subject of an email when reports are requested.
|
|
|
|
|
* This means that we need to limit them to ASCII characters until that
|
|
|
|
|
* mechanism has been changed.
|
|
|
|
|
*/
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int warn_password(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f = factions;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (f) {
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool pwok = true;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *c = f->passw;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (*c && pwok) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (!isalnum((unsigned char)*c))
|
|
|
|
|
pwok = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
if (!pwok) {
|
|
|
|
|
free(f->passw);
|
2013-12-29 14:38:58 +01:00
|
|
|
|
f->passw = _strdup(itoa36(rng_int()));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&f->msgs, msg_message("illegal_password", "newpass", f->passw));
|
|
|
|
|
}
|
|
|
|
|
f = f->next;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void init_processor(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int p;
|
|
|
|
|
|
|
|
|
|
p = 10;
|
|
|
|
|
add_proc_global(p, &new_units, "Neue Einheiten erschaffen");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2012-06-10 14:28:19 +02:00
|
|
|
|
add_proc_unit(p, update_long_order, "Langen Befehl aktualisieren");
|
2012-06-07 18:47:02 +02:00
|
|
|
|
add_proc_order(p, K_BANNER, banner_cmd, 0, NULL);
|
2010-08-08 10:06:34 +02: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);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_QUIT, &quit_cmd, 0, NULL);
|
|
|
|
|
add_proc_order(p, K_URSPRUNG, &origin_cmd, 0, NULL);
|
|
|
|
|
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);
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (get_param_int(global.parameters, "rules.alliances", 0) == 1) {
|
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_global(p, &alliance_cmd, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2012-06-24 05:09:13 +02:00
|
|
|
|
add_proc_region(p, do_contact, "Kontaktieren");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_MAIL, &mail_cmd, 0, "Botschaften");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10; /* all claims must be done before we can USE */
|
2012-06-18 02:24:23 +02:00
|
|
|
|
add_proc_region(p, &enter_1, "Betreten (1. Versuch)");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_USE, &use_cmd, 0, "Benutzen");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10; /* in case it has any effects on alliance victories */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_GIVE, &give_control_cmd, 0, "GIB KOMMANDO");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10; /* in case it has any effects on alliance victories */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_LEAVE, &leave_cmd, 0, "Verlassen");
|
|
|
|
|
|
2012-06-17 07:38:44 +02:00
|
|
|
|
add_proc_region(p, &do_battle, "Attackieren");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(K_BESIEGE)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_region(p, &do_siege, "Belagern");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10; /* can't allow reserve before siege (weapons) */
|
2012-06-18 02:24:23 +02:00
|
|
|
|
add_proc_region(p, &enter_1, "Betreten (2. Versuch)");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_RESERVE, &reserve_cmd, 0, "Reservieren");
|
|
|
|
|
add_proc_order(p, K_CLAIM, &claim_cmd, 0, NULL);
|
|
|
|
|
add_proc_unit(p, &follow_unit, "Folge auf Einheiten setzen");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10; /* rest rng again before economics */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_region(p, &economics, "Zerstoeren, Geben, Rekrutieren, Vergessen");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2014-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(K_PAY)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_PAY, &pay_cmd, 0, "Gebaeudeunterhalt (disable)");
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
add_proc_postregion(p, &maintain_buildings_1,
|
|
|
|
|
"Gebaeudeunterhalt (1. Versuch)");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10; /* QUIT fuer sich alleine */
|
2012-06-17 07:38:44 +02:00
|
|
|
|
add_proc_global(p, quit, "Sterben");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(K_CAST)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_global(p, &magic, "Zaubern");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
|
|
|
|
add_proc_order(p, K_TEACH, &teach_cmd, PROC_THISORDER | PROC_LONGORDER,
|
|
|
|
|
"Lehren");
|
|
|
|
|
p += 10;
|
|
|
|
|
add_proc_order(p, K_STUDY, &learn_cmd, PROC_THISORDER | PROC_LONGORDER,
|
|
|
|
|
"Lernen");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
|
|
|
|
add_proc_order(p, K_MAKE, &make_cmd, PROC_THISORDER | PROC_LONGORDER,
|
|
|
|
|
"Produktion");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_postregion(p, &produce, "Arbeiten, Handel, Rekruten");
|
|
|
|
|
add_proc_postregion(p, &split_allocations, "Produktion II");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2012-06-18 02:24:23 +02:00
|
|
|
|
add_proc_region(p, &enter_2, "Betreten (3. Versuch)");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_region(p, &sinkships, "Schiffe sinken");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_global(p, &movement, "Bewegungen");
|
|
|
|
|
|
|
|
|
|
if (get_param_int(global.parameters, "work.auto", 0)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_region(p, &auto_work, "Arbeiten (auto)");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_GUARD, &guard_on_cmd, 0, "Bewache (an)");
|
|
|
|
|
|
2012-07-09 08:27:41 +02:00
|
|
|
|
if (get_param_int(global.parameters, "rules.encounters", 1)) {
|
|
|
|
|
p += 10;
|
|
|
|
|
add_proc_global(p, &encounters, "Zufallsbegegnungen");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
|
|
|
|
add_proc_unit(p, &monster_kills_peasants,
|
|
|
|
|
"Monster fressen und vertreiben Bauern");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_global(p, &randomevents, "Zufallsereignisse");
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
add_proc_global(p, &monthly_healing, "Regeneration (HP)");
|
2012-06-18 07:31:30 +02:00
|
|
|
|
add_proc_global(p, ®enerate_aura, "Regeneration (Aura)");
|
2014-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(K_DEFAULT)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_global(p, &defaultorders, "Defaults setzen");
|
|
|
|
|
}
|
|
|
|
|
add_proc_global(p, &demographics, "Nahrung, Seuchen, Wachstum, Wanderung");
|
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(K_SORT)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2012-06-17 08:31:25 +02:00
|
|
|
|
add_proc_global(p, restack_units, "Einheiten sortieren");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
add_proc_order(p, K_PROMOTION, &promotion_cmd, 0, "Heldenbefoerderung");
|
2014-06-16 03:34:39 +02:00
|
|
|
|
if (!keyword_disabled(K_NUMBER)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_order(p, K_NUMBER, &renumber_cmd, 0, "Neue Nummern (Einheiten)");
|
2011-03-07 08:02:35 +01:00
|
|
|
|
p += 10;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
add_proc_global(p, &renumber_factions, "Neue Nummern");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void processorders(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
static int init = 0;
|
|
|
|
|
|
|
|
|
|
if (!init) {
|
|
|
|
|
init_processor();
|
|
|
|
|
init = 1;
|
|
|
|
|
}
|
|
|
|
|
update_spells();
|
|
|
|
|
process();
|
|
|
|
|
/*************************************************/
|
|
|
|
|
|
|
|
|
|
if (get_param_int(global.parameters, "modules.markets", 0)) {
|
|
|
|
|
do_markets();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-18 02:24:23 +02:00
|
|
|
|
log_info(" - Attribute altern");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ageing();
|
|
|
|
|
remove_empty_units();
|
|
|
|
|
|
|
|
|
|
/* must happen AFTER age, because that would destroy them right away */
|
|
|
|
|
if (get_param_int(global.parameters, "modules.wormholes", 0)) {
|
|
|
|
|
create_wormholes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* immer ausf<73>hren, wenn neue Spr<70>che dazugekommen sind, oder sich
|
|
|
|
|
* Beschreibungen ge<EFBFBD>ndert haben */
|
|
|
|
|
update_spells();
|
|
|
|
|
warn_password();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int writepasswd(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
FILE *F;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
char zText[128];
|
|
|
|
|
|
|
|
|
|
sprintf(zText, "%s/passwd", basepath());
|
2013-12-29 09:31:49 +01:00
|
|
|
|
F = fopen(zText, "w");
|
|
|
|
|
if (!F) {
|
|
|
|
|
perror(zText);
|
|
|
|
|
} else {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
faction *f;
|
2012-06-18 02:24:23 +02:00
|
|
|
|
log_info("writing passwords...");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
2014-01-02 05:29:08 +01:00
|
|
|
|
fprintf(F, "%s:%s:%s:%u\n",
|
|
|
|
|
factionid(f), f->email, f->passw, f->subscription);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
fclose(F);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void update_subscriptions(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
FILE *F;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
char zText[MAX_PATH];
|
2011-03-07 08:02:35 +01:00
|
|
|
|
faction *f;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
strcat(strcpy(zText, basepath()), "/subscriptions");
|
|
|
|
|
F = fopen(zText, "r");
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (F == NULL) {
|
2012-05-17 00:52:37 +02:00
|
|
|
|
log_warning(0, "could not open %s.\n", zText);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (;;) {
|
|
|
|
|
char zFaction[5];
|
|
|
|
|
int subscription, fno;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (fscanf(F, "%d %s", &subscription, zFaction) <= 0)
|
|
|
|
|
break;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
fno = atoi36(zFaction);
|
|
|
|
|
f = findfaction(fno);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (f != NULL) {
|
|
|
|
|
f->subscription = subscription;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(F);
|
|
|
|
|
|
|
|
|
|
sprintf(zText, "subscriptions.%u", turn);
|
|
|
|
|
F = fopen(zText, "w");
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (f = factions; f != NULL; f = f->next) {
|
2014-01-02 05:29:08 +01:00
|
|
|
|
fprintf(F, "%s:%u:%s:%s:%u:\n",
|
|
|
|
|
itoa36(f->no), f->subscription, f->email, dbrace(f->race), f->lastorders);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
fclose(F);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int init_data(const char *filename, const char *catalog)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int l;
|
|
|
|
|
|
|
|
|
|
l = read_xml(filename, catalog);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (l)
|
|
|
|
|
return l;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (turn < 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
turn = first_turn;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|