2015-01-30 20:37:14 +01:00
|
|
|
|
/*
|
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2015
|
2010-08-08 09:40:42 +02:00
|
|
|
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
|
|
|
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
|
|
|
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
|
|
|
|
* Enno Rehling (enno@eressea.de)
|
|
|
|
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
|
|
|
|
*
|
|
|
|
|
* based on:
|
|
|
|
|
*
|
|
|
|
|
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
|
2017-11-20 17:03:12 +01:00
|
|
|
|
* Atlantis v1.7 Copyright 1996 by Alex Schr<EFBFBD>der
|
2010-08-08 09:40:42 +02:00
|
|
|
|
*
|
|
|
|
|
* This program may not be used, modified or distributed without
|
|
|
|
|
* prior permission by the authors of Eressea.
|
|
|
|
|
* This program may not be sold or used commercially without prior written
|
|
|
|
|
* permission from the authors.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-24 19:41:36 +01:00
|
|
|
|
#ifdef _MSC_VER
|
2010-08-08 09:40:42 +02:00
|
|
|
|
#include <platform.h>
|
2018-02-24 19:41:36 +01:00
|
|
|
|
#endif
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2016-08-31 11:35:07 +02:00
|
|
|
|
#include "monsters.h"
|
|
|
|
|
|
2014-02-18 05:45:00 +01:00
|
|
|
|
#include "economy.h"
|
|
|
|
|
#include "give.h"
|
2016-11-01 22:11:10 +01:00
|
|
|
|
#include "guard.h"
|
2014-11-01 12:09:56 +01:00
|
|
|
|
#include "laws.h"
|
2014-11-02 11:10:26 +01:00
|
|
|
|
#include "keyword.h"
|
2016-03-08 14:09:22 +01:00
|
|
|
|
#include "study.h"
|
2018-02-14 20:00:48 +01:00
|
|
|
|
#include "move.h"
|
2017-08-21 20:18:19 +02:00
|
|
|
|
|
2010-08-08 09:40:42 +02:00
|
|
|
|
/* kernel includes */
|
2018-02-14 20:00:48 +01:00
|
|
|
|
#include "kernel/build.h"
|
|
|
|
|
#include "kernel/building.h"
|
|
|
|
|
#include "kernel/calendar.h"
|
|
|
|
|
#include "kernel/config.h"
|
|
|
|
|
#include "kernel/curse.h"
|
|
|
|
|
#include "kernel/equipment.h"
|
|
|
|
|
#include "kernel/faction.h"
|
|
|
|
|
#include "kernel/item.h"
|
|
|
|
|
#include "kernel/messages.h"
|
|
|
|
|
#include "kernel/order.h"
|
|
|
|
|
#include "kernel/pathfinder.h"
|
|
|
|
|
#include "kernel/pool.h"
|
|
|
|
|
#include "kernel/race.h"
|
|
|
|
|
#include "kernel/region.h"
|
|
|
|
|
#include "kernel/ship.h"
|
|
|
|
|
#include "kernel/terrain.h"
|
|
|
|
|
#include "kernel/terrainid.h"
|
|
|
|
|
#include "kernel/unit.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
|
|
2010-08-08 09:40:42 +02:00
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/event.h>
|
|
|
|
|
#include <util/language.h>
|
|
|
|
|
#include <util/lists.h>
|
|
|
|
|
#include <util/log.h>
|
|
|
|
|
#include <util/rand.h>
|
|
|
|
|
#include <util/rng.h>
|
2017-12-30 19:49:21 +01:00
|
|
|
|
#include <util/strings.h>
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2018-02-14 20:00:48 +01:00
|
|
|
|
/* attributes includes */
|
|
|
|
|
#include <attributes/targetregion.h>
|
|
|
|
|
#include <attributes/hate.h>
|
|
|
|
|
|
|
|
|
|
#include <spells/regioncurse.h>
|
|
|
|
|
|
2017-01-26 17:41:21 +01:00
|
|
|
|
#include <selist.h>
|
2012-06-05 06:45:25 +02:00
|
|
|
|
|
2010-08-08 09:40:42 +02:00
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
#define DRAGON_RANGE 20 /* max. Distanz zum n<>chsten Drachenziel */
|
2016-12-23 18:05:38 +01:00
|
|
|
|
#define MOVE_PERCENT 25 /* chance fuer bewegung */
|
2010-08-08 09:40:42 +02:00
|
|
|
|
#define MAXILLUSION_TEXTS 3
|
|
|
|
|
|
2015-11-23 12:37:42 +01:00
|
|
|
|
static double attack_chance; /* rules.monsters.attack_chance, or default 0.4 */
|
|
|
|
|
|
2015-07-02 11:08:38 +02:00
|
|
|
|
static void give_peasants(unit *u, const item_type *itype, int reduce) {
|
|
|
|
|
char buf[64];
|
2017-12-11 18:35:30 +01:00
|
|
|
|
snprintf(buf, sizeof(buf), "%s 0 %d %s", LOC(u->faction->locale, keyword(K_GIVE)), reduce, LOC(u->faction->locale, itype->rtype->_name));
|
2015-07-02 11:08:38 +02:00
|
|
|
|
unit_addorder(u, parse_order(buf, u->faction->locale));
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 02:07:46 +01:00
|
|
|
|
static double random_move_chance(void) {
|
2016-12-23 18:05:38 +01:00
|
|
|
|
static int rule;
|
2016-09-23 20:36:57 +02:00
|
|
|
|
static int config;
|
|
|
|
|
if (config_changed(&config)) {
|
2016-12-23 23:58:24 +01:00
|
|
|
|
rule = config_get_int("rules.monsters.random_move_percent", MOVE_PERCENT);
|
2016-09-23 20:36:57 +02:00
|
|
|
|
}
|
2016-12-23 18:05:38 +01:00
|
|
|
|
return rule * 0.01;
|
2015-11-17 02:07:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static void reduce_weight(unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int capacity, weight = 0;
|
|
|
|
|
item **itmp = &u->items;
|
|
|
|
|
int horses = get_resource(u, get_resourcetype(R_HORSE));
|
|
|
|
|
|
|
|
|
|
if (horses > 0) {
|
2018-01-01 08:23:52 +01:00
|
|
|
|
if (horses > u->number * 2) horses = u->number * 2;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
change_resource(u, get_resourcetype(R_HORSE), -horses);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
|
|
/* 0. ditch any vehicles */
|
|
|
|
|
while (*itmp != NULL) {
|
|
|
|
|
item *itm = *itmp;
|
|
|
|
|
const item_type *itype = itm->type;
|
|
|
|
|
if (itype->flags & ITF_VEHICLE) {
|
2015-07-02 11:08:38 +02:00
|
|
|
|
give_peasants(u, itm->type, itm->number);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
weight += itm->number * itype->weight;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (*itmp == itm)
|
|
|
|
|
itmp = &itm->next;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
|
|
capacity = walkingcapacity(u);
|
|
|
|
|
|
|
|
|
|
/* 1. get rid of anything that isn't silver or really lightweight or helpful in combat */
|
|
|
|
|
for (itmp = &u->items; *itmp && capacity > 0;) {
|
|
|
|
|
item *itm = *itmp;
|
|
|
|
|
const item_type *itype = itm->type;
|
|
|
|
|
weight += itm->number * itype->weight;
|
|
|
|
|
if (weight > capacity) {
|
|
|
|
|
if (itype->weight >= 10 && itype->rtype->wtype == 0
|
|
|
|
|
&& itype->rtype->atype == 0) {
|
|
|
|
|
if (itype->capacity < itype->weight) {
|
2018-02-24 19:41:36 +01:00
|
|
|
|
int reduce = (weight - capacity) / itype->weight;
|
|
|
|
|
if (reduce > itm->number) {
|
|
|
|
|
reduce = itm->number;
|
|
|
|
|
}
|
2015-07-02 11:08:38 +02:00
|
|
|
|
give_peasants(u, itm->type, reduce);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
weight -= reduce * itype->weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (*itmp == itm)
|
|
|
|
|
itmp = &itm->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (itmp = &u->items; *itmp && weight > capacity;) {
|
|
|
|
|
item *itm = *itmp;
|
|
|
|
|
const item_type *itype = itm->type;
|
|
|
|
|
weight += itm->number * itype->weight;
|
|
|
|
|
if (itype->capacity < itype->weight) {
|
2018-02-24 19:41:36 +01:00
|
|
|
|
int reduce = (weight - capacity) / itype->weight;
|
|
|
|
|
if (reduce > itm->number) {
|
|
|
|
|
reduce = itm->number;
|
|
|
|
|
}
|
2015-07-02 11:08:38 +02:00
|
|
|
|
give_peasants(u, itm->type, reduce);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
weight -= reduce * itype->weight;
|
|
|
|
|
}
|
|
|
|
|
if (*itmp == itm)
|
|
|
|
|
itmp = &itm->next;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static order *monster_attack(unit * u, const unit * target)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-08-16 16:18:59 +02:00
|
|
|
|
assert(u->region == target->region);
|
|
|
|
|
assert(u->faction != target->faction);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (!cansee(u->faction, u->region, target, 0))
|
|
|
|
|
return NULL;
|
|
|
|
|
if (monster_is_waiting(u))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2018-05-21 13:27:02 +02:00
|
|
|
|
if (u->region->land && (u->region->flags & RF_GUARDED) == 0) {
|
|
|
|
|
return NULL;
|
2018-04-22 00:18:35 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return create_order(K_ATTACK, u->faction->locale, "%i", target->no);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 18:05:38 +01:00
|
|
|
|
void monsters_desert(struct faction *monsters)
|
|
|
|
|
{
|
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
|
|
assert(monsters!=NULL);
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (u->faction!=monsters
|
|
|
|
|
&& (u_race(u)->flags & RCF_DESERT)) {
|
|
|
|
|
if (fval(u, UFL_ISNEW))
|
|
|
|
|
continue;
|
|
|
|
|
if (rng_int() % 100 < 5) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("desertion",
|
|
|
|
|
"unit region", u, r));
|
|
|
|
|
u_setfaction(u, monsters);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 14:20:01 +02:00
|
|
|
|
int monster_attacks(unit * monster, bool rich_only)
|
2015-11-16 19:28:24 +01:00
|
|
|
|
{
|
2017-09-09 12:58:10 +02:00
|
|
|
|
const race *rc_serpent = get_race(RC_SEASERPENT);
|
2017-06-18 14:20:01 +02:00
|
|
|
|
if (monster->status < ST_AVOID) {
|
|
|
|
|
region *r = monster->region;
|
|
|
|
|
unit *u2;
|
|
|
|
|
int money = 0;
|
|
|
|
|
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u2->faction != monster->faction && cansee(monster->faction, r, u2, 0) && !in_safe_building(u2, monster)) {
|
|
|
|
|
int m = get_money(u2);
|
2017-09-09 12:58:10 +02:00
|
|
|
|
if (u_race(monster) == rc_serpent) {
|
|
|
|
|
/* attack bigger ships only */
|
|
|
|
|
if (!u2->ship || u2->ship->type->cargo <= 50000) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 14:20:01 +02:00
|
|
|
|
if (!rich_only || m > 0) {
|
|
|
|
|
order *ord = monster_attack(monster, u2);
|
|
|
|
|
if (ord) {
|
|
|
|
|
addlist(&monster->orders, ord);
|
|
|
|
|
money += m;
|
|
|
|
|
}
|
2015-11-16 19:28:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 14:20:01 +02:00
|
|
|
|
return money;
|
2015-11-16 19:28:24 +01:00
|
|
|
|
}
|
2017-06-18 14:20:01 +02:00
|
|
|
|
return 0;
|
2015-11-16 19:28:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 16:48:05 +01:00
|
|
|
|
static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-11-16 19:28:24 +01:00
|
|
|
|
int money;
|
2015-11-23 12:37:42 +01:00
|
|
|
|
bool attacks = attack_chance > 0.0;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2014-09-01 15:42:56 +02:00
|
|
|
|
/* falls genug geld in der region ist, treiben wir steuern ein. */
|
|
|
|
|
if (rmoney(r) >= wanted) {
|
|
|
|
|
/* 5% chance, dass der drache aus einer laune raus attackiert */
|
2017-02-18 19:21:54 +01:00
|
|
|
|
if (!attacks) {
|
2014-09-01 15:42:56 +02:00
|
|
|
|
/* Drachen haben in E3 und E4 keine Einnahmen. Neuer Befehl Pluendern erstmal nur fuer Monster?*/
|
2014-11-02 11:10:26 +01:00
|
|
|
|
return create_order(K_LOOT, default_locale, NULL);
|
2014-09-01 15:42:56 +02:00
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 14:36:56 +01:00
|
|
|
|
/* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an
|
|
|
|
|
* und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
|
2015-11-16 19:28:24 +01:00
|
|
|
|
money = 0;
|
2016-10-31 07:45:06 +01:00
|
|
|
|
if (attacks && is_guard(udragon)) {
|
2017-06-18 14:20:01 +02:00
|
|
|
|
money += monster_attacks(udragon, true);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 15:42:56 +02:00
|
|
|
|
/* falls die einnahmen erreicht werden, bleibt das monster noch eine */
|
|
|
|
|
/* runde hier. */
|
2015-11-16 19:28:24 +01:00
|
|
|
|
if (money + rmoney(r) >= wanted) {
|
2015-11-11 14:36:56 +01:00
|
|
|
|
return create_order(K_LOOT, default_locale, NULL);
|
2014-09-01 15:42:56 +02:00
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2014-09-01 15:42:56 +02:00
|
|
|
|
/* wenn wir NULL zurueckliefern, macht der drache was anderes, z.b. weggehen */
|
|
|
|
|
return NULL;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static int all_money(region * r, faction * f)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
int m;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
m = rmoney(r);
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (f != u->faction) {
|
|
|
|
|
m += get_money(u);
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return m;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static direction_t richest_neighbour(region * r, faction * f, int absolut)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
/* m - maximum an Geld, d - Richtung, i - index, t = Geld hier */
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
double m;
|
|
|
|
|
double t;
|
|
|
|
|
direction_t d = NODIRECTION, i;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (absolut == 1 || rpeasants(r) == 0) {
|
|
|
|
|
m = (double)all_money(r, f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
m = (double)all_money(r, f) / (double)rpeasants(r);
|
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
/* finde die region mit dem meisten geld */
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
region *rn = rconnect(r, i);
|
|
|
|
|
if (rn != NULL && fval(rn->terrain, LAND_REGION)) {
|
|
|
|
|
if (absolut == 1 || rpeasants(rn) == 0) {
|
|
|
|
|
t = (double)all_money(rn, f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
t = (double)all_money(rn, f) / (double)rpeasants(rn);
|
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (t > m) {
|
|
|
|
|
m = t;
|
|
|
|
|
d = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return d;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-09 02:51:48 +02:00
|
|
|
|
static bool room_for_race_in_region(region * r, const race * rc)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2016-10-03 20:15:38 +02:00
|
|
|
|
if (rc->splitsize > 0) {
|
|
|
|
|
unit *u;
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (u_race(u) == rc) {
|
|
|
|
|
c += u->number;
|
|
|
|
|
if (c > rc->splitsize * 2) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2016-10-03 20:15:38 +02:00
|
|
|
|
return true;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static direction_t random_neighbour(region * r, unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int i;
|
2016-10-03 20:15:38 +02:00
|
|
|
|
region *next[MAXDIRECTIONS], *backup[MAXDIRECTIONS];
|
|
|
|
|
region **pick;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int rr, c = 0, c2 = 0;
|
2016-10-03 16:26:40 +02:00
|
|
|
|
const race *rc = u_race(u);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
|
|
get_neighbours(r, next);
|
|
|
|
|
/* Nachsehen, wieviele Regionen in Frage kommen */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
2016-10-03 16:26:40 +02:00
|
|
|
|
region *rn = next[i];
|
|
|
|
|
if (rn && can_survive(u, rn)) {
|
|
|
|
|
if (room_for_race_in_region(rn, rc)) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
c++;
|
2016-10-03 16:26:40 +02:00
|
|
|
|
} else {
|
|
|
|
|
next[i] = NULL;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2016-10-03 20:15:38 +02:00
|
|
|
|
backup[i] = rn;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
c2++;
|
2016-10-03 16:38:17 +02:00
|
|
|
|
} else {
|
|
|
|
|
next[i] = NULL;
|
2016-10-03 20:15:38 +02:00
|
|
|
|
backup[i] = NULL;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
2016-10-03 20:15:38 +02:00
|
|
|
|
pick = next;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (c == 0) {
|
|
|
|
|
if (c2 == 0) {
|
|
|
|
|
return NODIRECTION;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2016-10-03 20:15:38 +02:00
|
|
|
|
pick = backup;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
c = c2;
|
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Zuf<75>llig eine ausw<73>hlen */
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
rr = rng_int() % c;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Durchz<68>hlen */
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2016-10-03 20:15:38 +02:00
|
|
|
|
c = 0;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
2016-10-03 20:15:38 +02:00
|
|
|
|
region *rn = pick[i];
|
2016-10-03 16:38:17 +02:00
|
|
|
|
if (rn) {
|
2016-10-03 16:28:18 +02:00
|
|
|
|
if (c == rr) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return (direction_t)i;
|
2016-10-03 16:28:18 +02:00
|
|
|
|
}
|
2016-10-03 20:15:38 +02:00
|
|
|
|
c++;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
assert(1 == 0); /* Bis hierhin sollte er niemals kommen. */
|
|
|
|
|
return NODIRECTION;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static direction_t treeman_neighbour(region * r)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int i;
|
|
|
|
|
int rr;
|
|
|
|
|
int c = 0;
|
|
|
|
|
region * next[MAXDIRECTIONS];
|
|
|
|
|
|
|
|
|
|
get_neighbours(r, next);
|
|
|
|
|
/* Nachsehen, wieviele Regionen in Frage kommen */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
if (next[i] && rterrain(next[i]) != T_OCEAN
|
|
|
|
|
&& rterrain(next[i]) != T_GLACIER && rterrain(next[i]) != T_DESERT) {
|
|
|
|
|
++c;
|
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (c == 0) {
|
|
|
|
|
return NODIRECTION;
|
|
|
|
|
}
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Zuf<75>llig eine ausw<73>hlen */
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
rr = rng_int() % c;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Durchz<68>hlen */
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
c = -1;
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
if (next[i] && rterrain(next[i]) != T_OCEAN
|
|
|
|
|
&& rterrain(next[i]) != T_GLACIER && rterrain(next[i]) != T_DESERT) {
|
|
|
|
|
if (++c == rr) {
|
|
|
|
|
return (direction_t)i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
assert(!"this should never happen"); /* Bis hierhin sollte er niemals kommen. */
|
|
|
|
|
return NODIRECTION;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static order *monster_move(region * r, unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
direction_t d = NODIRECTION;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (monster_is_waiting(u)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-09-19 16:10:10 +02:00
|
|
|
|
if (fval(u_race(u), RCF_DRAGON)) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
d = richest_neighbour(r, u->faction, 1);
|
2016-09-19 16:10:10 +02:00
|
|
|
|
}
|
|
|
|
|
else if (get_race(RC_TREEMAN)==u_race(u)) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
d = treeman_neighbour(r);
|
2016-09-19 16:10:10 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
d = random_neighbour(r, u);
|
|
|
|
|
}
|
|
|
|
|
/* falls kein geld gefunden wird, zufaellig verreisen, aber nicht in
|
|
|
|
|
* den ozean */
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (d == NODIRECTION)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
reduce_weight(u);
|
|
|
|
|
return create_order(K_MOVE, u->faction->locale, "%s",
|
|
|
|
|
LOC(u->faction->locale, directions[d]));
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static int dragon_affinity_value(region * r, unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int m = all_money(r, u->faction);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (u_race(u) == get_race(RC_FIREDRAGON)) {
|
2015-11-17 17:19:06 +01:00
|
|
|
|
return dice(4, m / 2);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2015-11-17 17:19:06 +01:00
|
|
|
|
return dice(6, m / 3);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static attrib *set_new_dragon_target(unit * u, region * r, int range)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int max_affinity = 0;
|
|
|
|
|
region *max_region = NULL;
|
2017-01-26 17:41:21 +01:00
|
|
|
|
selist *ql, *rlist = regions_in_range(r, range, allowed_dragon);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int qi;
|
|
|
|
|
|
2017-01-26 17:41:21 +01:00
|
|
|
|
for (qi = 0, ql = rlist; ql; selist_advance(&ql, &qi, 1)) {
|
|
|
|
|
region *r2 = (region *)selist_get(ql, qi);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int affinity = dragon_affinity_value(r2, u);
|
|
|
|
|
if (affinity > max_affinity) {
|
|
|
|
|
max_affinity = affinity;
|
|
|
|
|
max_region = r2;
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 17:41:21 +01:00
|
|
|
|
selist_free(rlist);
|
2011-04-26 07:20:27 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (max_region && max_region != r) {
|
|
|
|
|
attrib *a = a_find(u->attribs, &at_targetregion);
|
|
|
|
|
if (!a) {
|
|
|
|
|
a = a_add(&u->attribs, make_targetregion(max_region));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
a->data.v = max_region;
|
|
|
|
|
}
|
|
|
|
|
return a;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return NULL;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 19:04:09 +02:00
|
|
|
|
static order *plan_move_to_target(unit * u, const region * target, int moves,
|
2015-01-30 20:37:14 +01:00
|
|
|
|
bool(*allowed) (const region *, const region *))
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
region *r = u->region;
|
|
|
|
|
region **plan;
|
2018-04-22 19:04:09 +02:00
|
|
|
|
direction_t steps[DRAGON_RANGE];
|
|
|
|
|
int position;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (monster_is_waiting(u))
|
|
|
|
|
return NULL;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2018-04-22 19:04:09 +02:00
|
|
|
|
plan = path_find(r, target, DRAGON_RANGE, allowed);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (plan == NULL)
|
|
|
|
|
return NULL;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2018-04-22 19:04:09 +02:00
|
|
|
|
for (position = 0; position != moves && plan[position + 1]; ++position) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
region *prev = plan[position];
|
2018-04-22 19:04:09 +02:00
|
|
|
|
region *next = plan[position + 1];
|
2015-01-30 20:37:14 +01:00
|
|
|
|
direction_t dir = reldirection(prev, next);
|
|
|
|
|
assert(dir != NODIRECTION && dir != D_SPECIAL);
|
2018-04-22 19:04:09 +02:00
|
|
|
|
steps[position] = dir;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2018-04-22 19:04:09 +02:00
|
|
|
|
return make_movement_order(u->faction->locale, steps, position);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 01:49:37 +02:00
|
|
|
|
void random_growl(const unit *u, region *target, int rand)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2016-05-31 01:49:37 +02:00
|
|
|
|
const struct locale *lang = u->faction->locale;
|
2016-06-11 13:47:38 +02:00
|
|
|
|
const char *growl;
|
|
|
|
|
switch(rand){
|
|
|
|
|
case 1: growl = "growl1"; break;
|
|
|
|
|
case 2: growl = "growl2"; break;
|
|
|
|
|
case 3: growl = "growl3"; break;
|
|
|
|
|
case 4: growl = "growl4"; break;
|
|
|
|
|
default: growl = "growl0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-05-31 01:49:37 +02:00
|
|
|
|
if (rname(target, lang)) {
|
2016-06-11 13:47:38 +02:00
|
|
|
|
message *msg = msg_message("dragon_growl", "dragon number target growl", u, u->number, target, growl);
|
2016-05-31 01:49:37 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg);
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern struct attrib_type at_direction;
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static order *monster_learn(unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int c = 0;
|
|
|
|
|
int n;
|
|
|
|
|
skill *sv;
|
|
|
|
|
const struct locale *lang = u->faction->locale;
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
/* can these monsters even study? */
|
|
|
|
|
if (!unit_can_study(u)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-03-07 08:03:10 +01:00
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Monster lernt ein zuf<75>lliges Talent aus allen, in denen es schon
|
2015-01-30 20:37:14 +01:00
|
|
|
|
* Lerntage hat. */
|
|
|
|
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
|
|
|
|
if (sv->level > 0)
|
|
|
|
|
++c;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
|
|
if (c == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
n = rng_int() % c + 1;
|
|
|
|
|
c = 0;
|
|
|
|
|
|
|
|
|
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
|
|
|
|
if (sv->level > 0) {
|
|
|
|
|
if (++c == n) {
|
|
|
|
|
return create_order(K_STUDY, lang, "'%s'", skillname(sv->id, lang));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 20:15:38 +02:00
|
|
|
|
static bool check_overpopulated(const unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2016-10-03 20:15:38 +02:00
|
|
|
|
const race *rc = u_race(u);
|
|
|
|
|
if (rc->splitsize > 0) {
|
|
|
|
|
unit *u2;
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
for (u2 = u->region->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u != u2 && u_race(u2) == rc) {
|
|
|
|
|
c += u2->number;
|
|
|
|
|
if (c > rc->splitsize * 2)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static void recruit_dracoids(unit * dragon, int size)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
faction *f = dragon->faction;
|
|
|
|
|
region *r = dragon->region;
|
|
|
|
|
const struct item *weapon = NULL;
|
|
|
|
|
unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
fset(un, UFL_ISNEW | UFL_MOVED);
|
|
|
|
|
|
|
|
|
|
name_unit(un);
|
|
|
|
|
change_money(dragon, -un->number * 50);
|
2018-05-11 21:30:26 +02:00
|
|
|
|
equip_unit(un, "new_dracoid");
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
2018-02-14 11:24:38 +01:00
|
|
|
|
unit_setstatus(un, ST_FIGHT);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (weapon = un->items; weapon; weapon = weapon->next) {
|
|
|
|
|
const weapon_type *wtype = weapon->type->rtype->wtype;
|
2017-11-20 17:03:12 +01:00
|
|
|
|
if (wtype && wtype->flags & WTF_MISSILE) {
|
2018-02-14 11:24:38 +01:00
|
|
|
|
unit_setstatus(un, ST_BEHIND);
|
2017-11-20 17:03:12 +01:00
|
|
|
|
break;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
static order *plan_dragon(unit * u)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
attrib *ta = a_find(u->attribs, &at_targetregion);
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
region *tr = NULL;
|
|
|
|
|
bool move = false;
|
|
|
|
|
order *long_order = NULL;
|
2016-09-19 20:10:01 +02:00
|
|
|
|
static int rc_cache;
|
|
|
|
|
static const race *rc_wyrm;
|
|
|
|
|
const race * rc = u_race(u);
|
|
|
|
|
|
|
|
|
|
if (rc_changed(&rc_cache)) {
|
|
|
|
|
rc_wyrm = get_race(RC_WYRM);
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (ta == NULL) {
|
2015-12-07 17:59:50 +01:00
|
|
|
|
move |= (rpeasants(r) == 0); /* when no peasants, move */
|
|
|
|
|
move |= (rmoney(r) == 0); /* when no money, move */
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
move |= chance(0.04); /* 4% chance to change your mind */
|
|
|
|
|
|
2016-09-19 20:10:01 +02:00
|
|
|
|
if (rc == rc_wyrm && !move) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
unit *u2;
|
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* wyrme sind einzelg<6C>nger */
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (u2 == u) {
|
|
|
|
|
/* we do not make room for newcomers, so we don't need to look at them */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (u2 != u && u_race(u2) == u_race(u) && chance(0.5)) {
|
|
|
|
|
move = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
2015-12-30 14:04:10 +01:00
|
|
|
|
if (move && (!ta || chance(0.1))) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
/* dragon gets bored and looks for a different place to go */
|
|
|
|
|
ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (ta != NULL) {
|
|
|
|
|
tr = (region *)ta->data.v;
|
|
|
|
|
if (tr == NULL || !path_exists(u->region, tr, DRAGON_RANGE, allowed_dragon)) {
|
|
|
|
|
ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
|
2015-11-16 16:57:51 +01:00
|
|
|
|
if (ta) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
tr = findregion(ta->data.sa[0], ta->data.sa[1]);
|
2015-11-16 16:57:51 +01:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (tr != NULL) {
|
|
|
|
|
assert(long_order == NULL);
|
2017-02-18 21:15:14 +01:00
|
|
|
|
/* TODO: per-race planning functions? */
|
2016-09-19 20:10:01 +02:00
|
|
|
|
if (rc == rc_wyrm) {
|
2018-04-22 19:04:09 +02:00
|
|
|
|
long_order = plan_move_to_target(u, tr, 1, allowed_dragon);
|
2016-09-19 20:10:01 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
switch (old_race(rc)) {
|
|
|
|
|
case RC_FIREDRAGON:
|
2018-04-22 19:04:09 +02:00
|
|
|
|
long_order = plan_move_to_target(u, tr, 4, allowed_dragon);
|
2016-09-19 20:10:01 +02:00
|
|
|
|
break;
|
|
|
|
|
case RC_DRAGON:
|
2018-04-22 19:04:09 +02:00
|
|
|
|
long_order = plan_move_to_target(u, tr, 3, allowed_dragon);
|
2016-09-19 20:10:01 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2015-07-02 11:08:38 +02:00
|
|
|
|
if (long_order) {
|
|
|
|
|
reduce_weight(u);
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (rng_int() % 100 < 15) {
|
2016-05-31 01:49:37 +02:00
|
|
|
|
random_growl(u, tr, rng_int() % 5);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2014-06-30 03:10:02 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
else {
|
|
|
|
|
/* we have no target. do we like it here, then? */
|
|
|
|
|
long_order = get_money_for_dragon(u->region, u, income(u));
|
|
|
|
|
if (long_order == NULL) {
|
|
|
|
|
/* money is gone, need a new target */
|
|
|
|
|
set_new_dragon_target(u, u->region, DRAGON_RANGE);
|
|
|
|
|
}
|
|
|
|
|
else if (u_race(u) != get_race(RC_FIREDRAGON)) {
|
|
|
|
|
/* neue dracoiden! */
|
|
|
|
|
if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) {
|
|
|
|
|
int ra = 20 + rng_int() % 100;
|
|
|
|
|
if (get_money(u) > ra * 50 + 100 && rng_int() % 100 < 50) {
|
|
|
|
|
recruit_dracoids(u, ra);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (long_order == NULL) {
|
2015-11-16 19:45:56 +01:00
|
|
|
|
int attempts = 0;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
skill_t sk = SK_PERCEPTION;
|
|
|
|
|
/* study perception (or a random useful skill) */
|
2016-11-20 19:08:39 +01:00
|
|
|
|
while (!skill_enabled(sk) || (attempts < MAXSKILLS && u_race(u)->bonus[sk] < (++attempts < 10?1:-5 ))) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
sk = (skill_t)(rng_int() % MAXSKILLS);
|
|
|
|
|
}
|
|
|
|
|
long_order = create_order(K_STUDY, u->faction->locale, "'%s'",
|
|
|
|
|
skillname(sk, u->faction->locale));
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return long_order;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
|
void plan_monsters(faction * f)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
region *r;
|
2015-11-23 12:37:42 +01:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
assert(f);
|
2015-11-23 17:12:48 +01:00
|
|
|
|
attack_chance = config_get_flt("rules.monsters.attack_chance", 0.4);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
f->lastorders = turn;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit *u;
|
2018-04-22 00:18:35 +02:00
|
|
|
|
bool attacking = false;
|
|
|
|
|
/* Tiny optimization: Monsters on land only attack randomly when
|
|
|
|
|
* they are guarding. If nobody is guarding this region (RF_GUARDED),
|
|
|
|
|
* there can't be any random attacks.
|
|
|
|
|
*/
|
|
|
|
|
if (!r->land || r->flags & RF_GUARDED) {
|
|
|
|
|
attacking = chance(attack_chance);
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2016-09-19 20:10:01 +02:00
|
|
|
|
const race *rc = u_race(u);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
attrib *ta;
|
|
|
|
|
order *long_order = NULL;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Ab hier nur noch Befehle f<>r NPC-Einheiten. */
|
2017-04-17 16:50:15 +02:00
|
|
|
|
if (u->faction!=f)
|
2015-01-30 20:37:14 +01:00
|
|
|
|
continue;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2018-07-02 19:58:26 +02:00
|
|
|
|
/* Parteitarnung von Monstern ist doof: */
|
|
|
|
|
if (fval(u, UFL_ANON_FACTION)) {
|
|
|
|
|
u->flags &= ~UFL_ANON_FACTION;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Befehle m<>ssen jede Runde neu gegeben werden: */
|
2015-11-02 15:27:01 +01:00
|
|
|
|
free_orders(&u->orders);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (skill_enabled(SK_PERCEPTION)) {
|
|
|
|
|
/* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */
|
|
|
|
|
produceexp(u, SK_PERCEPTION, u->number);
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2016-10-31 07:45:06 +01:00
|
|
|
|
if (attacking && (!r->land || is_guard(u))) {
|
2017-06-18 14:20:01 +02:00
|
|
|
|
monster_attacks(u, false);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2018-04-22 00:18:35 +02:00
|
|
|
|
/* units with a plan to kill get ATTACK orders (even if they don't guard): */
|
2015-01-30 20:37:14 +01:00
|
|
|
|
ta = a_find(u->attribs, &at_hate);
|
|
|
|
|
if (ta && !monster_is_waiting(u)) {
|
|
|
|
|
unit *tu = (unit *)ta->data.v;
|
|
|
|
|
if (tu && tu->region == r) {
|
2015-11-23 17:00:07 +01:00
|
|
|
|
order * ord = monster_attack(u, tu);
|
|
|
|
|
if (ord) {
|
|
|
|
|
addlist(&u->orders, ord);
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
else if (tu) {
|
2018-04-22 00:18:35 +02:00
|
|
|
|
bool(*allowed)(const struct region * src, const struct region * r) = allowed_walk;
|
|
|
|
|
if (canfly(u)) {
|
|
|
|
|
allowed = allowed_fly;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2018-04-22 19:04:09 +02:00
|
|
|
|
long_order = plan_move_to_target(u, tu->region, 2, allowed);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
a_remove(&u->attribs, ta);
|
|
|
|
|
}
|
|
|
|
|
/* All monsters guard the region: */
|
2017-06-18 14:20:01 +02:00
|
|
|
|
if (u->status < ST_FLEE && !monster_is_waiting(u) && r->land) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
addlist(&u->orders, create_order(K_GUARD, u->faction->locale, NULL));
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
/* Einheiten mit Bewegungsplan kriegen ein NACH: */
|
|
|
|
|
if (long_order == NULL) {
|
2017-12-29 06:13:28 +01:00
|
|
|
|
ta = a_find(u->attribs, &at_targetregion);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (ta) {
|
|
|
|
|
if (u->region == (region *)ta->data.v) {
|
|
|
|
|
a_remove(&u->attribs, ta);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-19 20:10:01 +02:00
|
|
|
|
else if (rc->flags & RCF_MOVERANDOM) {
|
2015-11-17 02:07:46 +01:00
|
|
|
|
if (chance(random_move_chance()) || check_overpopulated(u)) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
long_order = monster_move(r, u);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (long_order == NULL) {
|
|
|
|
|
/* Ab hier noch nicht generalisierte Spezialbehandlungen. */
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2016-09-19 20:10:01 +02:00
|
|
|
|
if (fval(rc, RCF_DRAGON)) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
long_order = plan_dragon(u);
|
2016-09-19 20:10:01 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (rc == get_race(RC_SEASERPENT)) {
|
|
|
|
|
long_order = create_order(K_PIRACY, f->locale, NULL);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (rc->flags & RCF_LEARN) {
|
|
|
|
|
long_order = monster_learn(u);
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-25 15:29:26 +01:00
|
|
|
|
if (long_order == NULL && unit_can_study(u)) {
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um
|
2015-11-25 15:29:26 +01:00
|
|
|
|
* zu bewachen: */
|
2016-09-19 20:10:01 +02:00
|
|
|
|
if (rc->bonus[SK_WEAPONLESS] != -99) {
|
2015-11-25 15:29:26 +01:00
|
|
|
|
if (effskill(u, SK_WEAPONLESS, 0) < 1) {
|
|
|
|
|
long_order =
|
|
|
|
|
create_order(K_STUDY, f->locale, "'%s'",
|
|
|
|
|
skillname(SK_WEAPONLESS, f->locale));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (long_order) {
|
|
|
|
|
addlist(&u->orders, long_order);
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
pathfinder_cleanup();
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-28 15:57:51 +02:00
|
|
|
|
static int nrand(int handle_start, int sub)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
int res = 0;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
do {
|
2018-06-28 22:48:57 +02:00
|
|
|
|
if (rng_int() % 100 < handle_start) {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
res++;
|
2018-06-28 22:48:57 +02:00
|
|
|
|
}
|
2018-04-28 15:57:51 +02:00
|
|
|
|
handle_start -= sub;
|
|
|
|
|
} while (handle_start > 0);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return res;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-31 11:35:07 +02:00
|
|
|
|
unit *spawn_seaserpent(region *r, faction *f) {
|
|
|
|
|
unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL);
|
|
|
|
|
fset(u, UFL_ISNEW | UFL_MOVED);
|
2018-05-11 21:30:26 +02:00
|
|
|
|
equip_unit(u, "seed_seaserpent");
|
2016-08-31 11:35:07 +02:00
|
|
|
|
return u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-20 17:03:12 +01:00
|
|
|
|
* Drachen und Seeschlangen k<EFBFBD>nnen entstehen
|
2016-08-31 11:35:07 +02:00
|
|
|
|
*/
|
2011-03-07 08:03:10 +01:00
|
|
|
|
void spawn_dragons(void)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
region *r;
|
|
|
|
|
faction *monsters = get_or_create_monsters();
|
2017-11-07 19:35:21 +01:00
|
|
|
|
int minage = config_get_int("monsters.spawn.min_age", 100);
|
2018-06-28 22:48:57 +02:00
|
|
|
|
int spawn_chance = config_get_int("monsters.spawn.chance", 100);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2017-11-07 19:35:21 +01:00
|
|
|
|
if (spawn_chance <= 0) {
|
|
|
|
|
/* monster spawning disabled */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit *u;
|
2017-11-07 19:35:21 +01:00
|
|
|
|
if (r->age < minage) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-08-31 11:35:07 +02:00
|
|
|
|
if (fval(r->terrain, SEA_REGION)) {
|
2017-11-07 19:35:21 +01:00
|
|
|
|
if (rng_int() % spawn_chance < 1) {
|
2016-08-31 11:35:07 +02:00
|
|
|
|
u = spawn_seaserpent(r, monsters);
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
2016-08-31 11:35:07 +02:00
|
|
|
|
else if ((r->terrain == newterrain(T_GLACIER)
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|| r->terrain == newterrain(T_SWAMP)
|
|
|
|
|
|| r->terrain == newterrain(T_DESERT))
|
2018-06-28 22:48:57 +02:00
|
|
|
|
&& rng_int() % spawn_chance < 6)
|
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
if (chance(0.80)) {
|
|
|
|
|
u = create_unit(r, monsters, nrand(60, 20) + 1, get_race(RC_FIREDRAGON), 0, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
fset(u, UFL_ISNEW | UFL_MOVED);
|
2018-05-11 21:30:26 +02:00
|
|
|
|
equip_unit(u, "seed_dragon");
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-09-12 19:48:03 +02:00
|
|
|
|
log_debug("spawning %d %s in %s.\n", u->number,
|
|
|
|
|
LOC(default_locale,
|
2018-06-28 22:48:57 +02:00
|
|
|
|
rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL));
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
name_unit(u);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
/* add message to the region */
|
|
|
|
|
ADDMSG(&r->msgs,
|
|
|
|
|
msg_message("sighting", "region race number", r, u_race(u), u->number));
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/** Untote k<>nnen entstehen */
|
2011-03-07 08:03:10 +01:00
|
|
|
|
void spawn_undead(void)
|
2010-08-08 09:40:42 +02:00
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
|
region *r;
|
|
|
|
|
faction *monsters = get_monsters();
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
int unburied = deathcount(r);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2017-08-21 20:18:19 +02:00
|
|
|
|
if (r->attribs) {
|
|
|
|
|
if (curse_active(get_curse(r->attribs, &ct_holyground))) {
|
2016-08-29 21:02:39 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-28 22:48:57 +02:00
|
|
|
|
|
2015-12-07 17:59:50 +01:00
|
|
|
|
if (r->land && unburied > rpeasants(r) / 20
|
2018-06-28 22:48:57 +02:00
|
|
|
|
&& rng_int() % 10000 < 200) {
|
2015-09-12 19:48:03 +02:00
|
|
|
|
message *msg;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
unit *u;
|
|
|
|
|
/* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen.
|
2017-11-20 17:03:12 +01:00
|
|
|
|
* Lieber sammeln lassen, bis sie mindestens 5% der Bev<EFBFBD>lkerung sind, und
|
2015-01-30 20:37:14 +01:00
|
|
|
|
* dann erst auferstehen. */
|
|
|
|
|
int undead = unburied / (rng_int() % 2 + 1);
|
|
|
|
|
const race *rc = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
if (r->age < 100)
|
|
|
|
|
undead = undead * r->age / 100; /* newbie-regionen kriegen weniger ab */
|
|
|
|
|
|
|
|
|
|
if (!undead || r->age < 20)
|
|
|
|
|
continue;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
switch (rng_int() % 3) {
|
|
|
|
|
case 0:
|
|
|
|
|
rc = get_race(RC_SKELETON);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
rc = get_race(RC_ZOMBIE);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
rc = get_race(RC_GHOUL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u = create_unit(r, monsters, undead, rc, 0, NULL, NULL);
|
|
|
|
|
fset(u, UFL_ISNEW | UFL_MOVED);
|
|
|
|
|
if ((rc == get_race(RC_SKELETON) || rc == get_race(RC_ZOMBIE))
|
|
|
|
|
&& rng_int() % 10 < 4) {
|
2018-05-11 21:30:26 +02:00
|
|
|
|
equip_unit(u, "rising_undead");
|
2015-01-30 20:37:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAXSKILLS; i++) {
|
|
|
|
|
if (rc->bonus[i] >= 1) {
|
|
|
|
|
set_level(u, (skill_t)i, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
u->hp = unit_max_hp(u) * u->number;
|
|
|
|
|
|
|
|
|
|
deathcounts(r, -undead);
|
|
|
|
|
name_unit(u);
|
|
|
|
|
|
2015-09-12 19:48:03 +02:00
|
|
|
|
log_debug("spawning %d %s in %s.\n", u->number,
|
|
|
|
|
LOC(default_locale,
|
|
|
|
|
rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL));
|
|
|
|
|
msg = msg_message("undeadrise", "region", r);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
add_message(&r->msgs, msg);
|
|
|
|
|
for (u = r->units; u; u = u->next)
|
|
|
|
|
freset(u->faction, FFL_SELECT);
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (fval(u->faction, FFL_SELECT))
|
|
|
|
|
continue;
|
|
|
|
|
fset(u->faction, FFL_SELECT);
|
|
|
|
|
add_message(&u->faction->msgs, msg);
|
|
|
|
|
}
|
|
|
|
|
msg_release(msg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int i = deathcount(r);
|
|
|
|
|
if (i) {
|
2017-11-20 17:03:12 +01:00
|
|
|
|
/* Gr<47>ber verwittern, 3% der Untoten finden die ewige Ruhe */
|
2015-01-30 20:37:14 +01:00
|
|
|
|
deathcounts(r, (int)(-i * 0.03));
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-08 09:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-23 18:05:38 +01:00
|
|
|
|
|
|
|
|
|
bool monster_is_waiting(const unit * u)
|
|
|
|
|
{
|
|
|
|
|
int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED;
|
|
|
|
|
if (fval(u, test))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void eaten_by_monster(unit * u)
|
|
|
|
|
{
|
|
|
|
|
/* adjustment for smaller worlds */
|
|
|
|
|
double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
|
|
|
|
|
int n = 0;
|
|
|
|
|
int horse = -1;
|
|
|
|
|
const resource_type *rhorse = get_resourcetype(R_HORSE);
|
|
|
|
|
const race *rc = u_race(u);
|
2017-02-05 18:38:53 +01:00
|
|
|
|
int scare;
|
2016-12-23 18:05:38 +01:00
|
|
|
|
|
2017-02-05 18:38:53 +01:00
|
|
|
|
scare = rc_scare(rc);
|
|
|
|
|
if (scare>0) {
|
|
|
|
|
n = rng_int() % scare * u->number;
|
2016-12-23 18:05:38 +01:00
|
|
|
|
} else {
|
|
|
|
|
n = rng_int() % (u->number / 20 + 1);
|
|
|
|
|
horse = 0;
|
|
|
|
|
}
|
|
|
|
|
horse = horse ? i_get(u->items, rhorse->itype) : 0;
|
|
|
|
|
|
|
|
|
|
n = (int)(n * multi);
|
|
|
|
|
if (n > 0) {
|
2018-02-24 19:41:36 +01:00
|
|
|
|
|
2016-12-23 18:05:38 +01:00
|
|
|
|
n = lovar(n);
|
|
|
|
|
|
|
|
|
|
if (n > 0) {
|
2018-02-24 19:41:36 +01:00
|
|
|
|
int p = rpeasants(u->region);
|
|
|
|
|
if (p < n) n = p;
|
2016-12-23 18:05:38 +01:00
|
|
|
|
deathcounts(u->region, n);
|
|
|
|
|
rsetpeasants(u->region, rpeasants(u->region) - n);
|
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (horse > 0) {
|
|
|
|
|
i_change(&u->items, rhorse->itype, -horse);
|
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void absorbed_by_monster(unit * u)
|
|
|
|
|
{
|
|
|
|
|
int n = rng_int() % (u->number / 20 + 1);
|
|
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
|
n = lovar(n);
|
|
|
|
|
if (n > 0) {
|
2018-02-24 19:41:36 +01:00
|
|
|
|
int p = rpeasants(u->region);
|
|
|
|
|
if (p < n) n = p;
|
2016-12-23 18:05:38 +01:00
|
|
|
|
rsetpeasants(u->region, rpeasants(u->region) - n);
|
|
|
|
|
scale_number(u, u->number + n);
|
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
|
|
|
|
|
"unit race amount", u, u_race(u), n));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int scareaway(region * r, int anzahl)
|
|
|
|
|
{
|
|
|
|
|
int n, p, diff = 0, emigrants[MAXDIRECTIONS];
|
|
|
|
|
direction_t d;
|
|
|
|
|
|
2018-02-24 19:41:36 +01:00
|
|
|
|
p = rpeasants(r);
|
|
|
|
|
if (anzahl < 1) anzahl = 1;
|
|
|
|
|
if (anzahl > p) anzahl = p;
|
|
|
|
|
assert(p >= 0 && anzahl >= 0);
|
2016-12-23 18:05:38 +01:00
|
|
|
|
|
|
|
|
|
/* Wandern am Ende der Woche (normal) oder wegen Monster. Die
|
|
|
|
|
* Wanderung wird erst am Ende von demographics () ausgefuehrt.
|
|
|
|
|
* emigrants[] ist local, weil r->newpeasants durch die Monster
|
|
|
|
|
* vielleicht schon hochgezaehlt worden ist. */
|
|
|
|
|
|
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; d++)
|
|
|
|
|
emigrants[d] = 0;
|
|
|
|
|
|
2018-02-24 19:41:36 +01:00
|
|
|
|
for (n = anzahl; n; n--) {
|
2016-12-23 18:05:38 +01:00
|
|
|
|
direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS);
|
|
|
|
|
region *rc = rconnect(r, dir);
|
|
|
|
|
|
|
|
|
|
if (rc && fval(rc->terrain, LAND_REGION)) {
|
|
|
|
|
++diff;
|
|
|
|
|
rc->land->newpeasants++;
|
|
|
|
|
emigrants[dir]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rsetpeasants(r, p - diff);
|
|
|
|
|
assert(p >= diff);
|
|
|
|
|
return diff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void scared_by_monster(unit * u)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
const race *rc = u_race(u);
|
2017-02-05 18:38:53 +01:00
|
|
|
|
int scare;
|
|
|
|
|
|
|
|
|
|
scare = rc_scare(rc);
|
|
|
|
|
if (scare>0) {
|
|
|
|
|
n = rng_int() % scare * u->number;
|
2016-12-23 18:05:38 +01:00
|
|
|
|
} else {
|
|
|
|
|
n = rng_int() % (u->number / 4 + 1);
|
|
|
|
|
}
|
|
|
|
|
if (n > 0) {
|
|
|
|
|
n = lovar(n);
|
|
|
|
|
if (n > 0) {
|
2018-02-24 19:41:36 +01:00
|
|
|
|
int p = rpeasants(u->region);
|
|
|
|
|
if (p < n) n = p;
|
2016-12-23 18:05:38 +01:00
|
|
|
|
n = scareaway(u->region, n);
|
|
|
|
|
if (n > 0) {
|
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("fleescared",
|
|
|
|
|
"amount unit", n, u));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void monster_kills_peasants(unit * u)
|
|
|
|
|
{
|
|
|
|
|
if (!monster_is_waiting(u)) {
|
|
|
|
|
if (u_race(u)->flags & RCF_SCAREPEASANTS) {
|
|
|
|
|
scared_by_monster(u);
|
|
|
|
|
}
|
|
|
|
|
if (u_race(u)->flags & RCF_KILLPEASANTS) {
|
|
|
|
|
eaten_by_monster(u);
|
|
|
|
|
}
|
|
|
|
|
if (u_race(u)->flags & RCF_ABSORBPEASANTS) {
|
|
|
|
|
absorbed_by_monster(u);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void make_zombie(unit * u)
|
|
|
|
|
{
|
|
|
|
|
u_setfaction(u, get_monsters());
|
|
|
|
|
scale_number(u, 1);
|
|
|
|
|
u->hp = unit_max_hp(u) * u->number;
|
|
|
|
|
u_setrace(u, get_race(RC_ZOMBIE));
|
|
|
|
|
u->irace = NULL;
|
|
|
|
|
}
|