forked from github/server
merge monster.c and monsters.c
move RCF_DESERT handling to monsters.c
This commit is contained in:
parent
4502692f30
commit
cc227fb707
|
@ -114,7 +114,6 @@ set (ERESSEA_SRC
|
||||||
magic.c
|
magic.c
|
||||||
market.c
|
market.c
|
||||||
morale.c
|
morale.c
|
||||||
monster.c
|
|
||||||
randenc.c
|
randenc.c
|
||||||
renumber.c
|
renumber.c
|
||||||
volcano.c
|
volcano.c
|
||||||
|
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "chaos.h"
|
#include "chaos.h"
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "spells/shipcurse.h"
|
#include "spells/shipcurse.h"
|
||||||
#include "monster.h"
|
|
||||||
#include "monsters.h"
|
#include "monsters.h"
|
||||||
|
|
||||||
#include <kernel/equipment.h>
|
#include <kernel/equipment.h>
|
||||||
|
|
|
@ -54,7 +54,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include "summary.h"
|
#include "summary.h"
|
||||||
#include "teleport.h"
|
#include "teleport.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "market.h"
|
#include "market.h"
|
||||||
|
|
||||||
#include <modules/autoseed.h>
|
#include <modules/autoseed.h>
|
||||||
|
|
|
@ -19,7 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "chaos.h"
|
#include "chaos.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
|
|
|
@ -31,7 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "spy.h"
|
#include "spy.h"
|
||||||
#include "study.h"
|
#include "study.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "morale.h"
|
#include "morale.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "calendar.h"
|
#include "calendar.h"
|
||||||
|
|
|
@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
|
|
||||||
#include <kernel/ally.h>
|
#include <kernel/ally.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/password.h>
|
#include <util/password.h>
|
||||||
|
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
#include <quicklist.h>
|
#include <quicklist.h>
|
||||||
|
|
|
@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
#include "market.h"
|
#include "market.h"
|
||||||
#include "morale.h"
|
#include "morale.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "randenc.h"
|
#include "randenc.h"
|
||||||
#include "renumber.h"
|
#include "renumber.h"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "battle.h"
|
#include "battle.h"
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
|
|
||||||
#include <kernel/ally.h>
|
#include <kernel/ally.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
|
224
src/monster.c
224
src/monster.c
|
@ -1,224 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2015, 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 "monster.h"
|
|
||||||
|
|
||||||
/* gamecode includes */
|
|
||||||
#include "economy.h"
|
|
||||||
#include "give.h"
|
|
||||||
#include "move.h"
|
|
||||||
|
|
||||||
/* attributes includes */
|
|
||||||
#include <attributes/targetregion.h>
|
|
||||||
#include <attributes/hate.h>
|
|
||||||
#include <attributes/attributes.h>
|
|
||||||
|
|
||||||
/* kernel includes */
|
|
||||||
#include <kernel/build.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/terrain.h>
|
|
||||||
#include <kernel/terrainid.h>
|
|
||||||
#include <kernel/unit.h>
|
|
||||||
|
|
||||||
/* util includes */
|
|
||||||
#include <util/attrib.h>
|
|
||||||
#include <util/base36.h>
|
|
||||||
#include <util/bsdstring.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>
|
|
||||||
|
|
||||||
/* libc includes */
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#define MOVECHANCE 25 /* chance fuer bewegung */
|
|
||||||
|
|
||||||
#define MAXILLUSION_TEXTS 3
|
|
||||||
|
|
||||||
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);
|
|
||||||
attrib *a;
|
|
||||||
|
|
||||||
a = a_find(rc->attribs, &at_scare);
|
|
||||||
if (a) {
|
|
||||||
n = rng_int() & a->data.i * u->number;
|
|
||||||
} 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) {
|
|
||||||
n = lovar(n);
|
|
||||||
n = _min(rpeasants(u->region), n);
|
|
||||||
|
|
||||||
if (n > 0) {
|
|
||||||
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);
|
|
||||||
n = _min(rpeasants(u->region), n);
|
|
||||||
if (n > 0) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
anzahl = _min(_max(1, anzahl), rpeasants(r));
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
p = rpeasants(r);
|
|
||||||
assert(p >= 0 && anzahl >= 0);
|
|
||||||
for (n = _min(p, anzahl); n; n--) {
|
|
||||||
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);
|
|
||||||
attrib *a;
|
|
||||||
a = a_find(rc->attribs, &at_scare);
|
|
||||||
if (a) {
|
|
||||||
n = rng_int() & a->data.i * u->number;
|
|
||||||
} else {
|
|
||||||
n = rng_int() % (u->number / 4 + 1);
|
|
||||||
}
|
|
||||||
if (n > 0) {
|
|
||||||
n = lovar(n);
|
|
||||||
n = _min(rpeasants(u->region), n);
|
|
||||||
if (n > 0) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
faction *get_or_create_monsters(void)
|
|
||||||
{
|
|
||||||
faction *f = findfaction(MONSTER_ID);
|
|
||||||
if (!f) {
|
|
||||||
const race *rc = rc_get_or_create("dragon");
|
|
||||||
const char *email = config_get("monster.email");
|
|
||||||
f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, default_locale, 0);
|
|
||||||
renumber_faction(f, MONSTER_ID);
|
|
||||||
faction_setname(f, "Monster");
|
|
||||||
fset(f, FFL_NPC | FFL_NOIDLEOUT);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
faction *get_monsters(void) {
|
|
||||||
return get_or_create_monsters();
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 1998-2015, 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.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef H_GC_MONSTER
|
|
||||||
#define H_GC_MONSTER
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct unit;
|
|
||||||
|
|
||||||
void monster_kills_peasants(struct unit *u);
|
|
||||||
bool monster_is_waiting(const struct unit *u);
|
|
||||||
struct faction *get_monsters(void);
|
|
||||||
struct faction *get_or_create_monsters(void);
|
|
||||||
void make_zombie(struct unit * u);
|
|
||||||
|
|
||||||
#define MONSTER_ID 666
|
|
||||||
#define is_monsters(f) ((f->flags & FFL_NPC) && f==get_monsters())
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
193
src/monsters.c
193
src/monsters.c
|
@ -26,12 +26,12 @@
|
||||||
#include "chaos.h"
|
#include "chaos.h"
|
||||||
#include "give.h"
|
#include "give.h"
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "monster.h"
|
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
#include "study.h"
|
#include "study.h"
|
||||||
|
|
||||||
/* attributes includes */
|
/* attributes includes */
|
||||||
|
#include <attributes/attributes.h>
|
||||||
#include <attributes/targetregion.h>
|
#include <attributes/targetregion.h>
|
||||||
#include <attributes/hate.h>
|
#include <attributes/hate.h>
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define MOVECHANCE .25 /* chance fuer bewegung */
|
#define DRAGON_RANGE 20 /* max. Distanz zum nächsten Drachenziel */
|
||||||
#define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */
|
#define MOVE_PERCENT 25 /* chance fuer bewegung */
|
||||||
#define MAXILLUSION_TEXTS 3
|
#define MAXILLUSION_TEXTS 3
|
||||||
|
|
||||||
static double attack_chance; /* rules.monsters.attack_chance, or default 0.4 */
|
static double attack_chance; /* rules.monsters.attack_chance, or default 0.4 */
|
||||||
|
@ -85,12 +85,12 @@ static void give_peasants(unit *u, const item_type *itype, int reduce) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static double random_move_chance(void) {
|
static double random_move_chance(void) {
|
||||||
static double rule;
|
static int rule;
|
||||||
static int config;
|
static int config;
|
||||||
if (config_changed(&config)) {
|
if (config_changed(&config)) {
|
||||||
rule = config_get_flt("rules.monsters.random_move_chance", MOVECHANCE);
|
rule = config_get_flt("rules.monsters.random_move_percent", MOVE_PERCENT);
|
||||||
}
|
}
|
||||||
return rule;
|
return rule * 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reduce_weight(unit * u)
|
static void reduce_weight(unit * u)
|
||||||
|
@ -165,6 +165,29 @@ static order *monster_attack(unit * u, const unit * target)
|
||||||
return create_order(K_ATTACK, u->faction->locale, "%i", target->no);
|
return create_order(K_ATTACK, u->faction->locale, "%i", target->no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int monster_attacks(unit * monster, bool respect_buildings, bool rich_only)
|
int monster_attacks(unit * monster, bool respect_buildings, bool rich_only)
|
||||||
{
|
{
|
||||||
region *r = monster->region;
|
region *r = monster->region;
|
||||||
|
@ -973,3 +996,161 @@ void spawn_undead(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
attrib *a;
|
||||||
|
|
||||||
|
a = a_find(rc->attribs, &at_scare);
|
||||||
|
if (a) {
|
||||||
|
n = rng_int() & a->data.i * u->number;
|
||||||
|
} 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) {
|
||||||
|
n = lovar(n);
|
||||||
|
n = _min(rpeasants(u->region), n);
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
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);
|
||||||
|
n = _min(rpeasants(u->region), n);
|
||||||
|
if (n > 0) {
|
||||||
|
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;
|
||||||
|
|
||||||
|
anzahl = _min(_max(1, anzahl), rpeasants(r));
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
|
p = rpeasants(r);
|
||||||
|
assert(p >= 0 && anzahl >= 0);
|
||||||
|
for (n = _min(p, anzahl); n; n--) {
|
||||||
|
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);
|
||||||
|
attrib *a;
|
||||||
|
a = a_find(rc->attribs, &at_scare);
|
||||||
|
if (a) {
|
||||||
|
n = rng_int() & a->data.i * u->number;
|
||||||
|
} else {
|
||||||
|
n = rng_int() % (u->number / 4 + 1);
|
||||||
|
}
|
||||||
|
if (n > 0) {
|
||||||
|
n = lovar(n);
|
||||||
|
n = _min(rpeasants(u->region), n);
|
||||||
|
if (n > 0) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
faction *get_or_create_monsters(void)
|
||||||
|
{
|
||||||
|
faction *f = findfaction(MONSTER_ID);
|
||||||
|
if (!f) {
|
||||||
|
const race *rc = rc_get_or_create("dragon");
|
||||||
|
const char *email = config_get("monster.email");
|
||||||
|
f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, default_locale, 0);
|
||||||
|
renumber_faction(f, MONSTER_ID);
|
||||||
|
faction_setname(f, "Monster");
|
||||||
|
fset(f, FFL_NPC | FFL_NOIDLEOUT);
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
faction *get_monsters(void) {
|
||||||
|
return get_or_create_monsters();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,45 @@
|
||||||
#pragma once
|
/*
|
||||||
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
||||||
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
struct unit;
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
struct region;
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
struct faction;
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
struct unit *spawn_seaserpent(struct region *r, struct faction *f);
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
void spawn_dragons(void);
|
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.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef H_GC_MONSTER
|
||||||
|
#define H_GC_MONSTER
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct unit;
|
||||||
|
struct region;
|
||||||
|
struct faction;
|
||||||
|
|
||||||
|
struct unit *spawn_seaserpent(struct region *r, struct faction *f);
|
||||||
|
void spawn_dragons(void);
|
||||||
|
void monsters_desert(struct faction *monsters);
|
||||||
|
|
||||||
|
void monster_kills_peasants(struct unit *u);
|
||||||
|
bool monster_is_waiting(const struct unit *u);
|
||||||
|
struct faction *get_monsters(void);
|
||||||
|
struct faction *get_or_create_monsters(void);
|
||||||
|
void make_zombie(struct unit * u);
|
||||||
|
|
||||||
|
#define MONSTER_ID 666
|
||||||
|
#define is_monsters(f) ((f->flags & FFL_NPC) && f==get_monsters())
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <kernel/terrain.h>
|
#include <kernel/terrain.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
#include "monster.h"
|
|
||||||
#include "monsters.h"
|
#include "monsters.h"
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
|
|
@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "travelthru.h"
|
#include "travelthru.h"
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "lighthouse.h"
|
#include "lighthouse.h"
|
||||||
#include "piracy.h"
|
#include "piracy.h"
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
/* util iclude */
|
/* util iclude */
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "volcano.h"
|
#include "volcano.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "chaos.h"
|
#include "chaos.h"
|
||||||
#include "study.h"
|
#include "study.h"
|
||||||
|
@ -826,22 +826,7 @@ void randomevents(void)
|
||||||
|
|
||||||
/* monster-einheiten desertieren */
|
/* monster-einheiten desertieren */
|
||||||
if (monsters) {
|
if (monsters) {
|
||||||
for (r = regions; r; r = r->next) {
|
monsters_desert(monsters);
|
||||||
unit *u;
|
|
||||||
|
|
||||||
for (u = r->units; u; u = u->next) {
|
|
||||||
if (u->faction && !is_monsters(u->faction)
|
|
||||||
&& (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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chaos_update();
|
chaos_update();
|
||||||
|
|
|
@ -26,7 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "market.h"
|
#include "market.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "travelthru.h"
|
#include "travelthru.h"
|
||||||
|
|
||||||
/* modules includes */
|
/* modules includes */
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "spells.h"
|
#include "spells.h"
|
||||||
#include "direction.h"
|
#include "direction.h"
|
||||||
#include "randenc.h"
|
#include "randenc.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "teleport.h"
|
#include "teleport.h"
|
||||||
|
|
||||||
#include <spells/borders.h>
|
#include <spells/borders.h>
|
||||||
|
|
|
@ -24,7 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "study.h"
|
#include "study.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "academy.h"
|
#include "academy.h"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "summary.h"
|
#include "summary.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "calendar.h"
|
#include "calendar.h"
|
||||||
|
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
|
|
|
@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "monster.h"
|
#include "monsters.h"
|
||||||
#include "donations.h"
|
#include "donations.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
Loading…
Reference in New Issue