2001-01-25 10:37:55 +01:00
|
|
|
|
/* vi: set ts=2:
|
|
|
|
|
*
|
2001-04-16 16:34:19 +02:00
|
|
|
|
*
|
2003-07-29 11:48:03 +02:00
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
2001-01-25 10:37:55 +01: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-pbem.de)
|
|
|
|
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
|
|
|
|
*
|
|
|
|
|
* based on:
|
|
|
|
|
*
|
|
|
|
|
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
|
|
|
|
|
* Atlantis v1.7 Copyright 1996 by Alex Schr<EFBFBD>der
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include "eressea.h"
|
|
|
|
|
#include "monster.h"
|
2001-04-16 16:34:19 +02:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
/* gamecode includes */
|
2001-01-25 10:37:55 +01:00
|
|
|
|
#include "economy.h"
|
2001-04-16 16:34:19 +02:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
/* triggers includes */
|
|
|
|
|
#include <triggers/removecurse.h>
|
|
|
|
|
|
|
|
|
|
/* attributes includes */
|
|
|
|
|
#include <attributes/targetregion.h>
|
|
|
|
|
#include <attributes/hate.h>
|
|
|
|
|
|
|
|
|
|
/* spezialmonster */
|
|
|
|
|
#include <spells/alp.h>
|
|
|
|
|
|
2001-04-16 16:34:19 +02:00
|
|
|
|
/* kernel includes */
|
2004-06-21 18:45:27 +02:00
|
|
|
|
#include <kernel/build.h>
|
2005-10-02 23:11:17 +02:00
|
|
|
|
#include <kernel/equipment.h>
|
2004-06-21 18:45:27 +02:00
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/give.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/message.h>
|
|
|
|
|
#include <kernel/movement.h>
|
|
|
|
|
#include <kernel/names.h>
|
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/pathfinder.h>
|
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
|
#include <kernel/skill.h>
|
2005-10-25 14:38:01 +02:00
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
|
#include <kernel/terrainid.h>
|
2004-06-21 18:45:27 +02:00
|
|
|
|
#include <kernel/unit.h>
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
|
#include <attrib.h>
|
|
|
|
|
#include <base36.h>
|
|
|
|
|
#include <event.h>
|
2002-02-23 20:19:08 +01:00
|
|
|
|
#include <rand.h>
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#define UNDEAD_REPRODUCTION 0 /* vermehrung */
|
|
|
|
|
#define MOVECHANCE 25 /* chance fuer bewegung */
|
|
|
|
|
|
|
|
|
|
#define MAXILLUSION_TEXTS 3
|
|
|
|
|
|
2005-07-31 02:01:25 +02:00
|
|
|
|
static void
|
|
|
|
|
reduce_weight(unit * u)
|
|
|
|
|
{
|
2005-10-29 13:17:21 +02:00
|
|
|
|
int horses = new_get_resource(u, oldresourcetype[R_HORSE]);
|
2005-07-31 02:01:25 +02:00
|
|
|
|
int capacity = walkingcapacity(u);
|
|
|
|
|
item ** itmp = &u->items;
|
|
|
|
|
int weight = 0;
|
|
|
|
|
|
|
|
|
|
if (horses > 0) {
|
2005-10-29 13:17:21 +02:00
|
|
|
|
horses = min(horses, (u->number*2));
|
|
|
|
|
new_change_resource(u, oldresourcetype[R_HORSE], - horses);
|
2005-07-31 02:01:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-31 03:07:07 +02:00
|
|
|
|
/* 1. get rid of anything that isn't silver or really lightweight or helpful in combat */
|
2005-07-31 02:01:25 +02:00
|
|
|
|
while (capacity>0 && *itmp!=NULL) {
|
|
|
|
|
item * itm = *itmp;
|
|
|
|
|
const item_type * itype = itm->type;
|
|
|
|
|
weight += itm->number*itype->weight;
|
|
|
|
|
if (weight>capacity) {
|
2005-07-31 03:07:07 +02:00
|
|
|
|
if (itype->weight>=10 && itype->rtype->wtype==0 && itype->rtype->atype==0) {
|
2005-07-31 02:01:25 +02:00
|
|
|
|
if (itype->capacity < itype->weight) {
|
|
|
|
|
int reduce = min(itm->number, -((capacity-weight)/itype->weight));
|
|
|
|
|
give_item(reduce, itm->type, u, NULL, NULL);
|
|
|
|
|
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) {
|
|
|
|
|
int reduce = min(itm->number, -((capacity-weight)/itype->weight));
|
|
|
|
|
give_item(reduce, itm->type, u, NULL, NULL);
|
|
|
|
|
weight -= reduce * itype->weight;
|
|
|
|
|
}
|
|
|
|
|
if (*itmp==itm) itmp=&itm->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
static boolean
|
|
|
|
|
is_waiting(const unit * u)
|
|
|
|
|
{
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (fval(u, UFL_ISNEW|UFL_MOVED)) return true;
|
|
|
|
|
return false;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static order *
|
2001-01-25 10:37:55 +01:00
|
|
|
|
monster_attack(unit * u, const unit * target)
|
|
|
|
|
{
|
2005-07-10 22:58:13 +02:00
|
|
|
|
char zText[20];
|
|
|
|
|
|
|
|
|
|
if (u->region!=target->region) return NULL;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (u->faction==target->faction) return NULL;
|
2005-07-10 22:58:13 +02:00
|
|
|
|
if (!cansee(u->faction, u->region, target, 0)) return NULL;
|
|
|
|
|
if (is_waiting(u)) return NULL;
|
|
|
|
|
|
|
|
|
|
sprintf(zText, "%s %s",
|
|
|
|
|
locale_string(u->faction->locale, keywords[K_ATTACK]),
|
|
|
|
|
unitid(target));
|
|
|
|
|
return parse_order(zText, u->faction->locale);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static order *
|
2001-01-25 10:37:55 +01:00
|
|
|
|
get_money_for_dragon(region * r, unit * u, int wanted)
|
|
|
|
|
{
|
|
|
|
|
unit *u2;
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
/* attackiere bewachende einheiten */
|
2005-04-30 19:07:46 +02:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
|
|
|
|
if (u2 != u && getguard(u2)&GUARD_TAX) {
|
|
|
|
|
order * ord = monster_attack(u, u2);
|
|
|
|
|
if (ord) addlist(&u->orders, ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-04-30 19:07:46 +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 */
|
2005-05-05 04:50:14 +02:00
|
|
|
|
if (chance(1.0-u->race->aggression)) return parse_order(keywords[K_TAX], default_locale);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an */
|
2001-01-25 10:37:55 +01:00
|
|
|
|
n = 0;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
for (u2 = r->units; u2; u2 = u2->next) {
|
2005-05-21 13:50:21 +02:00
|
|
|
|
if (u2->faction != u->faction && cansee(u->faction, r, u2, 0)) {
|
|
|
|
|
int m = get_money(u2);
|
|
|
|
|
if (m==0 || (getguard(u2) & GUARD_TAX)) continue;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
else {
|
|
|
|
|
order * ord = monster_attack(u, u2);
|
|
|
|
|
if (ord) {
|
|
|
|
|
addlist(&u->orders, ord);
|
2005-05-21 13:50:21 +02:00
|
|
|
|
n += m;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* falls die einnahmen erreicht werden, bleibt das monster noch eine
|
2001-01-25 10:37:55 +01:00
|
|
|
|
* runde hier. */
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (n + rmoney(r) >= wanted) {
|
|
|
|
|
return parse_order(keywords[K_TAX], default_locale);
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* wenn wir NULL zur<75>ckliefern, macht der drache was anderes, z.b. weggehen */
|
|
|
|
|
return NULL;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static int
|
2005-05-21 13:50:21 +02:00
|
|
|
|
all_money(region * r, faction * f)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
int m;
|
|
|
|
|
|
|
|
|
|
m = rmoney(r);
|
2005-05-21 13:50:21 +02:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (f!=u->faction) {
|
|
|
|
|
m += get_money(u);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static direction_t
|
2005-05-21 13:50:21 +02:00
|
|
|
|
richest_neighbour(region * r, faction * f, int absolut)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* m - maximum an Geld, d - Richtung, i - index, t = Geld hier */
|
|
|
|
|
|
|
|
|
|
double m;
|
|
|
|
|
double t;
|
|
|
|
|
direction_t d = NODIRECTION, i;
|
|
|
|
|
|
|
|
|
|
if (absolut == 1 || rpeasants(r) == 0) {
|
2005-05-21 13:50:21 +02:00
|
|
|
|
m = (double) all_money(r, f);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
} else {
|
2005-05-21 13:50:21 +02:00
|
|
|
|
m = (double) all_money(r, f) / (double) rpeasants(r);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* finde die region mit dem meisten geld */
|
|
|
|
|
|
2005-10-25 14:38:01 +02: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);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
} else {
|
2005-10-25 14:38:01 +02:00
|
|
|
|
t = (double) all_money(rn, f) / (double) rpeasants(rn);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (t > m) {
|
|
|
|
|
m = t;
|
|
|
|
|
d = i;
|
|
|
|
|
}
|
2005-10-25 14:38:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static boolean
|
2001-12-10 01:13:39 +01:00
|
|
|
|
room_for_race_in_region(region *r, const race * rc)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
for(u=r->units;u;u=u->next) {
|
|
|
|
|
if(u->race == rc) c += u->number;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if(c > (rc->splitsize*2))
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static direction_t
|
2001-01-25 10:37:55 +01:00
|
|
|
|
random_neighbour(region * r, unit *u)
|
|
|
|
|
{
|
|
|
|
|
direction_t i;
|
|
|
|
|
region *rc;
|
|
|
|
|
int rr, c = 0, c2 = 0;
|
|
|
|
|
|
|
|
|
|
/* Nachsehen, wieviele Regionen in Frage kommen */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
rc = rconnect(r, i);
|
|
|
|
|
if (rc && can_survive(u, rc)) {
|
|
|
|
|
if(room_for_race_in_region(rc, u->race)) {
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
c2++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == 0) {
|
|
|
|
|
if(c2 == 0) {
|
|
|
|
|
return NODIRECTION;
|
|
|
|
|
} else {
|
|
|
|
|
c = c2;
|
|
|
|
|
c2 = 0; /* c2 == 0 -> room_for_race nicht beachten */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Zuf<75>llig eine ausw<73>hlen */
|
|
|
|
|
|
|
|
|
|
rr = rand() % c;
|
|
|
|
|
|
|
|
|
|
/* Durchz<68>hlen */
|
|
|
|
|
|
|
|
|
|
c = -1;
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
rc = rconnect(r, i);
|
|
|
|
|
if (rc && can_survive(u, rc)) {
|
|
|
|
|
if(c2 == 0) {
|
|
|
|
|
c++;
|
|
|
|
|
} else if(room_for_race_in_region(rc, u->race)) {
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
if (c == rr) return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(1 == 0); /* Bis hierhin sollte er niemals kommen. */
|
|
|
|
|
return NODIRECTION;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static direction_t
|
2001-01-25 10:37:55 +01:00
|
|
|
|
treeman_neighbour(region * r)
|
|
|
|
|
{
|
|
|
|
|
direction_t i;
|
|
|
|
|
int rr;
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
/* Nachsehen, wieviele Regionen in Frage kommen */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
if (rconnect(r, i)
|
|
|
|
|
&& rterrain(rconnect(r, i)) != T_OCEAN
|
|
|
|
|
&& rterrain(rconnect(r, i)) != T_GLACIER
|
|
|
|
|
&& rterrain(rconnect(r, i)) != T_DESERT) {
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == 0) {
|
|
|
|
|
return NODIRECTION;
|
|
|
|
|
}
|
|
|
|
|
/* Zuf<75>llig eine ausw<73>hlen */
|
|
|
|
|
|
|
|
|
|
rr = rand() % c;
|
|
|
|
|
|
|
|
|
|
/* Durchz<68>hlen */
|
|
|
|
|
|
|
|
|
|
c = -1;
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
if (rconnect(r, i)
|
|
|
|
|
&& rterrain(rconnect(r, i)) != T_OCEAN
|
|
|
|
|
&& rterrain(rconnect(r, i)) != T_GLACIER
|
|
|
|
|
&& rterrain(rconnect(r, i)) != T_DESERT) {
|
|
|
|
|
c++;
|
|
|
|
|
if (c == rr) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(1 == 0); /* Bis hierhin sollte er niemals kommen. */
|
|
|
|
|
return NODIRECTION;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static order *
|
|
|
|
|
monster_move(region * r, unit * u)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
|
direction_t d = NODIRECTION;
|
|
|
|
|
|
|
|
|
|
switch(old_race(u->race)) {
|
|
|
|
|
case RC_FIREDRAGON:
|
|
|
|
|
case RC_DRAGON:
|
|
|
|
|
case RC_WYRM:
|
2005-05-21 13:50:21 +02:00
|
|
|
|
d = richest_neighbour(r, u->faction, 1);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
break;
|
|
|
|
|
case RC_TREEMAN:
|
|
|
|
|
d = treeman_neighbour(r);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
d = random_neighbour(r,u);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
/* falls kein geld gefunden wird, zufaellig verreisen, aber nicht in
|
|
|
|
|
* den ozean */
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
if (d == NODIRECTION)
|
2005-04-30 19:07:46 +02:00
|
|
|
|
return NULL;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-07-10 22:58:13 +02:00
|
|
|
|
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
|
|
|
|
locale_string(u->faction->locale, directions[d]));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-07-31 02:01:25 +02:00
|
|
|
|
reduce_weight(u);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
return parse_order(buf, u->faction->locale);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wir machen das mal autoconf-style: */
|
|
|
|
|
#ifndef HAVE_DRAND48
|
|
|
|
|
#define drand48() (((double)rand()) / RAND_MAX)
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static int
|
2001-01-25 10:37:55 +01:00
|
|
|
|
dragon_affinity_value(region *r, unit *u)
|
|
|
|
|
{
|
2005-05-21 13:50:21 +02:00
|
|
|
|
int m = all_money(r, u->faction);
|
2002-02-23 20:19:08 +01:00
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if(u->race == new_race[RC_FIREDRAGON]) {
|
2002-02-23 20:19:08 +01:00
|
|
|
|
return (int)(normalvariate(m,m/2));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
} else {
|
2002-02-23 20:19:08 +01:00
|
|
|
|
return (int)(normalvariate(m,m/4));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static attrib *
|
2001-01-25 10:37:55 +01:00
|
|
|
|
set_new_dragon_target(unit * u, region * r, int range)
|
|
|
|
|
{
|
2004-02-21 13:18:29 +01:00
|
|
|
|
int max_affinity = 0;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
region *max_region = NULL;
|
|
|
|
|
|
2004-02-21 13:18:29 +01:00
|
|
|
|
#if 1
|
|
|
|
|
region_list * rptr, * rlist = regions_in_range(r, range, allowed_dragon);
|
|
|
|
|
for (rptr=rlist;rptr;rptr=rptr->next) {
|
|
|
|
|
region * r2 = rptr->data;
|
|
|
|
|
int affinity = dragon_affinity_value(r2, u);
|
|
|
|
|
if (affinity > max_affinity) {
|
|
|
|
|
max_affinity = affinity;
|
|
|
|
|
max_region = r2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free_regionlist(rlist);
|
|
|
|
|
#else
|
|
|
|
|
int x, y;
|
|
|
|
|
for (x = r->x - range; x < r->x + range; x++) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
for (y = r->y - range; y < r->y + range; y++) {
|
2004-02-21 13:18:29 +01:00
|
|
|
|
region * r2 = findregion(x, y);
|
|
|
|
|
if (r2!=NULL) {
|
|
|
|
|
int affinity = dragon_affinity_value(r2, u);
|
|
|
|
|
if (affinity > max_affinity) {
|
|
|
|
|
if (koor_distance (r->x, r->y, x, y) <= range && path_exists(r, r2, range, allowed_dragon))
|
|
|
|
|
{
|
|
|
|
|
max_affinity = affinity;
|
|
|
|
|
max_region = r2;
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-21 13:18:29 +01:00
|
|
|
|
#endif
|
2001-01-25 10:37:55 +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;
|
|
|
|
|
}
|
2005-01-19 21:33:13 +01:00
|
|
|
|
sprintf(buf, "Kommt aus: %s, Will nach: %s",
|
|
|
|
|
regionname(r, u->faction), regionname(max_region, u->faction));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
usetprivate(u, buf);
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static order *
|
|
|
|
|
make_movement_order(unit * u, const region * target, int moves, boolean (*allowed)(const region *, const region *))
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
region * r = u->region;
|
2003-01-08 22:44:01 +01:00
|
|
|
|
region ** plan = path_find(r, target, DRAGON_RANGE*5, allowed);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
int position = 0;
|
|
|
|
|
char * c;
|
|
|
|
|
|
|
|
|
|
if (plan==NULL) {
|
2005-04-30 19:07:46 +02:00
|
|
|
|
return NULL;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-16 16:34:19 +02:00
|
|
|
|
strcpy(buf, locale_string(u->faction->locale, keywords[K_MOVE]));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
c = buf + strlen(buf);
|
|
|
|
|
|
|
|
|
|
while (position!=moves && plan[position+1]) {
|
|
|
|
|
region * prev = plan[position];
|
|
|
|
|
region * next = plan[++position];
|
|
|
|
|
direction_t dir = reldirection(prev, next);
|
2004-04-12 18:21:23 +02:00
|
|
|
|
assert(dir!=NODIRECTION && dir!=D_SPECIAL);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
*c++ = ' ';
|
2001-04-16 16:34:19 +02:00
|
|
|
|
strcpy(c, locale_string(u->faction->locale, directions[dir]));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
c += strlen(c);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
return parse_order(buf, u->faction->locale);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static order *
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
monster_seeks_target(region *r, unit *u)
|
|
|
|
|
{
|
|
|
|
|
direction_t d;
|
|
|
|
|
unit *target = NULL;
|
|
|
|
|
int dist, dist2;
|
|
|
|
|
direction_t i;
|
|
|
|
|
region *nr;
|
|
|
|
|
|
|
|
|
|
/* Das Monster sucht ein bestimmtes Opfer. Welches, steht
|
|
|
|
|
* in einer Referenz/attribut
|
|
|
|
|
* derzeit gibt es nur den alp
|
|
|
|
|
*/
|
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
switch( old_race(u->race) ) {
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
case RC_ALP:
|
|
|
|
|
target = alp_target(u);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Seeker-Monster gibt kein Ziel an");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: pr<70>fen, ob target <20>berhaupt noch existiert... */
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (!target) {
|
|
|
|
|
log_error(("Monster '%s' hat kein Ziel!\n", unitname(u)));
|
|
|
|
|
return NULL; /* this is a bug workaround! remove!! */
|
|
|
|
|
}
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
|
2005-07-10 22:58:13 +02:00
|
|
|
|
if(r == target->region ) { /* Wir haben ihn! */
|
|
|
|
|
if (u->race == new_race[RC_ALP]) {
|
|
|
|
|
alp_findet_opfer(u, r);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(!"Seeker-Monster hat keine Aktion fuer Ziel");
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Simpler Ansatz: Nachbarregion mit gerinster Distanz suchen.
|
|
|
|
|
* Sinnvoll momentan nur bei Monstern, die sich nicht um das
|
|
|
|
|
* Terrain k<EFBFBD>mmern. Nebelw<EFBFBD>nde & Co machen derzeit auch nix...
|
|
|
|
|
*/
|
|
|
|
|
dist2 = distance(r, target->region);
|
|
|
|
|
d = NODIRECTION;
|
|
|
|
|
for( i = 0; i < MAXDIRECTIONS; i++ ) {
|
|
|
|
|
nr = rconnect(r, i);
|
|
|
|
|
assert(nr);
|
|
|
|
|
dist = distance(nr, target->region);
|
|
|
|
|
if( dist < dist2 ) {
|
|
|
|
|
dist2 = dist;
|
|
|
|
|
d = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert(d != NODIRECTION );
|
|
|
|
|
|
|
|
|
|
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
|
|
|
|
locale_string(u->faction->locale, directions[d]));
|
|
|
|
|
return parse_order(buf, u->faction->locale);
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
unit *
|
|
|
|
|
random_unit(const region * r)
|
|
|
|
|
{
|
|
|
|
|
int c = 0;
|
|
|
|
|
int n;
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if (u->race != new_race[RC_SPELL]) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
c += u->number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
n = rand() % c;
|
|
|
|
|
c = 0;
|
|
|
|
|
u = r->units;
|
|
|
|
|
|
|
|
|
|
while (u && c < n) {
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if (u->race != new_race[RC_SPELL]) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
c += u->number;
|
|
|
|
|
}
|
|
|
|
|
u = u->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return u;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static void
|
|
|
|
|
monster_attacks(unit * u)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
2005-04-30 19:07:46 +02:00
|
|
|
|
region * r = u->region;
|
|
|
|
|
unit * u2;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
for (u2=r->units;u2;u2=u2->next) {
|
|
|
|
|
if (chance(0.75)) {
|
|
|
|
|
order * ord = monster_attack(u, u2);
|
|
|
|
|
if (ord) addlist(&u->orders, ord);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static void
|
2001-01-25 10:37:55 +01:00
|
|
|
|
eaten_by_monster(unit * u)
|
|
|
|
|
{
|
2001-12-10 01:13:39 +01:00
|
|
|
|
int n = 0;
|
|
|
|
|
int horse = 0;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
switch (old_race(u->race)) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
case RC_FIREDRAGON:
|
|
|
|
|
n = rand()%80 * u->number;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
horse = get_item(u, I_HORSE);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case RC_DRAGON:
|
|
|
|
|
n = rand()%200 * u->number;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
horse = get_item(u, I_HORSE);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case RC_WYRM:
|
|
|
|
|
n = rand()%500 * u->number;
|
2001-12-10 01:13:39 +01:00
|
|
|
|
horse = get_item(u, I_HORSE);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
n = rand()%(u->number/20+1);
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-02 09:40:49 +01:00
|
|
|
|
if (n > 0) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
n = lovar(n);
|
|
|
|
|
n = min(rpeasants(u->region), n);
|
|
|
|
|
|
2004-02-09 22:12:46 +01:00
|
|
|
|
if (n > 0) {
|
2001-02-02 09:40:49 +01:00
|
|
|
|
deathcounts(u->region, n);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
rsetpeasants(u->region, rpeasants(u->region) - n);
|
2005-05-10 21:17:56 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if (horse > 0) {
|
|
|
|
|
set_item(u, I_HORSE, 0);
|
2005-05-10 21:17:56 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse));
|
2001-12-10 01:13:39 +01:00
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
static void
|
2001-01-25 10:37:55 +01:00
|
|
|
|
absorbed_by_monster(unit * u)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
switch (old_race(u->race)) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
default:
|
|
|
|
|
n = rand()%(u->number/20+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(n > 0) {
|
|
|
|
|
n = lovar(n);
|
|
|
|
|
n = min(rpeasants(u->region), n);
|
2005-05-10 21:17:56 +02:00
|
|
|
|
if (n > 0){
|
2001-01-25 10:37:55 +01:00
|
|
|
|
rsetpeasants(u->region, rpeasants(u->region) - n);
|
|
|
|
|
scale_number(u, u->number + n);
|
2005-05-10 21:17:56 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
|
|
|
|
|
"unit race amount", u, u->race, n));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static int
|
2001-01-25 10:37:55 +01:00
|
|
|
|
scareaway(region * r, int anzahl)
|
|
|
|
|
{
|
2005-05-11 18:12:42 +02:00
|
|
|
|
int n, p, diff = 0, emigrants[MAXDIRECTIONS];
|
|
|
|
|
direction_t d;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
2005-05-11 18:12:42 +02:00
|
|
|
|
for (d = 0; d != MAXDIRECTIONS; d++)
|
|
|
|
|
emigrants[d] = 0;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
p = rpeasants(r);
|
|
|
|
|
assert(p >= 0 && anzahl >= 0);
|
|
|
|
|
for (n = min(p, anzahl); n; n--) {
|
|
|
|
|
direction_t dir = (direction_t)(rand() % MAXDIRECTIONS);
|
2005-10-25 14:38:01 +02:00
|
|
|
|
region * rc = rconnect(r, dir);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-10-25 14:38:01 +02:00
|
|
|
|
if (rc && fval(rc->terrain, LAND_REGION)) {
|
2005-05-11 18:12:42 +02:00
|
|
|
|
++diff;
|
2005-10-25 14:38:01 +02:00
|
|
|
|
rc->land->newpeasants++;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
emigrants[dir]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-05-11 18:12:42 +02:00
|
|
|
|
rsetpeasants(r, p-diff);
|
|
|
|
|
assert(p >= diff);
|
|
|
|
|
return diff;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static void
|
2001-01-25 10:37:55 +01:00
|
|
|
|
scared_by_monster(unit * u)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
switch (old_race(u->race)) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
case RC_FIREDRAGON:
|
|
|
|
|
n = rand()%160 * u->number;
|
|
|
|
|
break;
|
|
|
|
|
case RC_DRAGON:
|
|
|
|
|
n = rand()%400 * u->number;
|
|
|
|
|
break;
|
|
|
|
|
case RC_WYRM:
|
|
|
|
|
n = rand()%1000 * u->number;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
n = rand()%(u->number/4+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(n > 0) {
|
|
|
|
|
n = lovar(n);
|
|
|
|
|
n = min(rpeasants(u->region), n);
|
|
|
|
|
if(n > 0) {
|
|
|
|
|
n = scareaway(u->region, n);
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if(n > 0) {
|
2005-05-11 18:12:42 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("fleescared",
|
|
|
|
|
"amount unit", n, u));
|
2001-12-10 01:13:39 +01:00
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static const char *
|
2001-01-25 10:37:55 +01:00
|
|
|
|
random_growl(void)
|
|
|
|
|
{
|
|
|
|
|
switch(rand()%5) {
|
|
|
|
|
case 0:
|
|
|
|
|
return "Groammm";
|
|
|
|
|
case 1:
|
|
|
|
|
return "Roaaarrrr";
|
|
|
|
|
case 2:
|
|
|
|
|
return "Chhhhhhhhhh";
|
|
|
|
|
case 3:
|
|
|
|
|
return "Tschrrrkk";
|
|
|
|
|
case 4:
|
|
|
|
|
return "Schhhh";
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern attrib_type at_direction;
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
static order *
|
|
|
|
|
monster_learn(unit *u)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
2005-07-10 22:58:13 +02:00
|
|
|
|
int c = 0;
|
|
|
|
|
int n;
|
|
|
|
|
skill * sv;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
const struct locale * lang = u->faction->locale;
|
2005-07-10 22:58:13 +02:00
|
|
|
|
|
|
|
|
|
/* Monster lernt ein zuf<75>lliges Talent aus allen, in denen es schon
|
|
|
|
|
* Lerntage hat. */
|
|
|
|
|
|
2004-02-16 20:59:26 +01:00
|
|
|
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
|
|
|
|
if (sv->level>0) ++c;
|
|
|
|
|
}
|
2005-07-10 22:58:13 +02:00
|
|
|
|
|
|
|
|
|
if(c == 0) return NULL;
|
|
|
|
|
|
|
|
|
|
n = rand()%c + 1;
|
|
|
|
|
c = 0;
|
|
|
|
|
|
2004-02-16 20:59:26 +01:00
|
|
|
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
2005-07-10 22:58:13 +02:00
|
|
|
|
if (sv->level>0) {
|
|
|
|
|
if (++c == n) {
|
|
|
|
|
sprintf(buf, "%s \"%s\"", locale_string(lang, keywords[K_STUDY]),
|
|
|
|
|
skillname(sv->id, lang));
|
|
|
|
|
return parse_order(buf, lang);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
return NULL;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
monsters_kill_peasants(void)
|
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
|
region *r;
|
|
|
|
|
unit *u;
|
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
for (u = r->units; u; u = u->next) if(!fval(u, UFL_MOVED)) {
|
2005-05-10 21:17:56 +02:00
|
|
|
|
if (u->race->flags & RCF_SCAREPEASANTS) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
scared_by_monster(u);
|
|
|
|
|
}
|
2005-05-10 21:17:56 +02:00
|
|
|
|
if (u->race->flags & RCF_KILLPEASANTS) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
eaten_by_monster(u);
|
|
|
|
|
}
|
2005-05-10 21:17:56 +02:00
|
|
|
|
if (u->race->flags & RCF_ABSORBPEASANTS) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
absorbed_by_monster(u);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
static boolean
|
|
|
|
|
check_overpopulated(unit *u)
|
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
|
unit *u2;
|
|
|
|
|
int c = 0;
|
2003-07-29 11:48:03 +02:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
for(u2 = u->region->units; u2; u2 = u2->next) {
|
|
|
|
|
if(u2->race == u->race && u != u2) c += u2->number;
|
|
|
|
|
}
|
2003-07-29 11:48:03 +02:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
if(c > u->race->splitsize * 2) return true;
|
2003-07-29 11:48:03 +02:00
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-04-30 19:07:46 +02:00
|
|
|
|
recruit_dracoids(unit * dragon, int size)
|
|
|
|
|
{
|
|
|
|
|
faction * f = dragon->faction;
|
|
|
|
|
region * r = dragon->region;
|
2005-10-02 23:11:17 +02:00
|
|
|
|
const struct item * weapon = NULL;
|
|
|
|
|
order * new_order = NULL;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
unit *un = createunit(r, f, size, new_race[RC_DRACOID]);
|
|
|
|
|
|
2005-05-27 22:46:57 +02:00
|
|
|
|
fset(un, UFL_ISNEW|UFL_MOVED);
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
name_unit(un);
|
|
|
|
|
change_money(dragon, -un->number * 50);
|
2005-10-02 23:11:17 +02:00
|
|
|
|
equip_unit(un, get_equipment("recruited_dracoid"));
|
|
|
|
|
|
|
|
|
|
un->status = ST_FIGHT;
|
|
|
|
|
for (weapon=un->items;weapon;weapon=weapon->next) {
|
|
|
|
|
const weapon_type * wtype = weapon->type->rtype->wtype;
|
|
|
|
|
if (wtype && (wtype->flags & WTF_MISSILE)) un->status = ST_BEHIND;
|
|
|
|
|
sprintf(buf, "%s \"%s\"", keywords[K_STUDY],
|
|
|
|
|
skillname(weapon->type->rtype->wtype->skill, f->locale));
|
|
|
|
|
new_order = parse_order(buf, default_locale);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-02 23:11:17 +02:00
|
|
|
|
if (new_order!=NULL) {
|
2005-04-30 19:07:46 +02:00
|
|
|
|
#ifdef LASTORDER
|
2005-10-02 23:11:17 +02:00
|
|
|
|
set_order(&un->lastorder, new_order);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
#else
|
2005-10-02 23:11:17 +02:00
|
|
|
|
addlist(&un->orders, new_order);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
#endif
|
2005-10-02 23:11:17 +02:00
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static order *
|
2004-06-21 18:45:27 +02:00
|
|
|
|
plan_dragon(unit * u)
|
|
|
|
|
{
|
2005-04-16 13:15:47 +02:00
|
|
|
|
attrib * ta = a_find(u->attribs, &at_targetregion);
|
|
|
|
|
region * r = u->region;
|
2004-06-21 18:45:27 +02:00
|
|
|
|
region * tr = NULL;
|
2005-04-16 13:15:47 +02:00
|
|
|
|
boolean move = false;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
order * long_order = NULL;
|
2004-06-21 18:45:27 +02:00
|
|
|
|
|
2005-07-31 02:01:25 +02:00
|
|
|
|
reduce_weight(u);
|
2005-04-16 13:15:47 +02:00
|
|
|
|
|
|
|
|
|
if (ta==NULL) {
|
|
|
|
|
move |= (r->land==0 || r->land->peasants==0); /* when no peasants, move */
|
|
|
|
|
move |= (r->land==0 || r->land->money==0); /* when no money, move */
|
|
|
|
|
}
|
|
|
|
|
move |= chance(0.04); /* 4% chance to change your mind */
|
|
|
|
|
if (move) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
/* dragon gets bored and looks for a different place to go */
|
|
|
|
|
ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
|
|
|
|
|
}
|
|
|
|
|
else ta = a_find(u->attribs, &at_targetregion);
|
|
|
|
|
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);
|
|
|
|
|
if (ta) tr = findregion(ta->data.sa[0], ta->data.sa[1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tr!=NULL) {
|
2005-04-30 19:07:46 +02:00
|
|
|
|
assert(long_order==NULL);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
switch(old_race(u->race)) {
|
|
|
|
|
case RC_FIREDRAGON:
|
2005-04-30 19:07:46 +02:00
|
|
|
|
long_order = make_movement_order(u, tr, 4, allowed_dragon);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
break;
|
|
|
|
|
case RC_DRAGON:
|
2005-04-30 19:07:46 +02:00
|
|
|
|
long_order = make_movement_order(u, tr, 3, allowed_dragon);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
break;
|
|
|
|
|
case RC_WYRM:
|
2005-04-30 19:07:46 +02:00
|
|
|
|
long_order = make_movement_order(u, tr, 1, allowed_dragon);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (rand()%100 < 15) {
|
|
|
|
|
/* do a growl */
|
|
|
|
|
if (rname(tr, u->faction->locale)) {
|
|
|
|
|
sprintf(buf,
|
|
|
|
|
"botschaft an region %s~...~%s~etwas~in~%s.",
|
|
|
|
|
estring(random_growl()), u->number==1?"Ich~rieche":"Wir~riechen",
|
|
|
|
|
estring(rname(tr, u->faction->locale)));
|
|
|
|
|
addlist(&u->orders, parse_order(buf, u->faction->locale));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* 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 */
|
2004-06-21 18:45:27 +02:00
|
|
|
|
set_new_dragon_target(u, u->region, DRAGON_RANGE);
|
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
else if (u->race != new_race[RC_FIREDRAGON]) {
|
|
|
|
|
/* neue dracoiden! */
|
2005-10-25 14:38:01 +02:00
|
|
|
|
if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
int ra = 20 + rand() % 100;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (get_money(u) > ra * 50 + 100 && rand() % 100 < 50) {
|
|
|
|
|
recruit_dracoids(u, ra);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
}
|
2004-06-21 18:45:27 +02:00
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (long_order==NULL) {
|
2005-07-10 22:58:13 +02:00
|
|
|
|
sprintf(buf, "%s \"%s\"", keywords[K_STUDY],
|
|
|
|
|
skillname(SK_OBSERVATION, u->faction->locale));
|
2005-04-30 19:07:46 +02:00
|
|
|
|
long_order = parse_order(buf, default_locale);
|
|
|
|
|
}
|
|
|
|
|
return long_order;
|
2003-07-29 11:48:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
void
|
|
|
|
|
plan_monsters(void)
|
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
|
region *r;
|
2004-06-26 22:51:19 +02:00
|
|
|
|
faction *f = findfaction(MONSTER_FACTION);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
|
2004-12-19 17:39:51 +01:00
|
|
|
|
if (!f) return;
|
2004-06-21 18:45:27 +02:00
|
|
|
|
f->lastorders = turn;
|
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
2004-12-19 17:39:51 +01:00
|
|
|
|
unit *u;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
double attack_chance = MONSTERATTACK;
|
|
|
|
|
boolean attacking = false;
|
|
|
|
|
|
2004-06-21 18:45:27 +02:00
|
|
|
|
for (u = r->units; u; u = u->next) {
|
2004-12-19 17:39:51 +01:00
|
|
|
|
attrib * ta;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
order * long_order = NULL;
|
2004-06-21 18:45:27 +02:00
|
|
|
|
|
|
|
|
|
/* Ab hier nur noch Befehle f<>r NPC-Einheiten. */
|
|
|
|
|
if (u->faction->no != MONSTER_FACTION) continue;
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (attack_chance>0.0) {
|
|
|
|
|
if (chance(attack_chance)) attacking = true;
|
|
|
|
|
attack_chance = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-24 00:39:26 +01:00
|
|
|
|
if (u->status>ST_BEHIND) u->status = ST_FIGHT; /* all monsters fight */
|
2004-06-21 18:45:27 +02:00
|
|
|
|
/* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */
|
|
|
|
|
produceexp(u, SK_OBSERVATION, u->number);
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* Befehle m<>ssen jede Runde neu gegeben werden: */
|
|
|
|
|
free_orders(&u->orders);
|
2004-12-19 17:39:51 +01:00
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (attacking) {
|
|
|
|
|
monster_attacks(u);
|
|
|
|
|
}
|
|
|
|
|
/* units with a plan to kill get ATTACK orders: */
|
2004-06-21 18:45:27 +02:00
|
|
|
|
ta = a_find(u->attribs, &at_hate);
|
2004-12-19 17:39:51 +01:00
|
|
|
|
if (ta && !is_waiting(u)) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
unit * tu = (unit *)ta->data.v;
|
|
|
|
|
if (tu && tu->region==r) {
|
|
|
|
|
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_ATTACK]), itoa36(tu->no));
|
|
|
|
|
addlist(&u->orders, parse_order(buf, u->faction->locale));
|
|
|
|
|
} else if (tu) {
|
|
|
|
|
tu = findunitg(ta->data.i, NULL);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (tu!=NULL) {
|
|
|
|
|
long_order = make_movement_order(u, tu->region, 2, allowed_walk);
|
|
|
|
|
}
|
2004-06-21 18:45:27 +02:00
|
|
|
|
}
|
|
|
|
|
else a_remove(&u->attribs, ta);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* All monsters guard the region: */
|
|
|
|
|
if (!is_waiting(u) && r->land) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
const char * cmd = locale_string(u->faction->locale, keywords[K_GUARD]);
|
|
|
|
|
addlist(&u->orders, parse_order(cmd, u->faction->locale));
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
/* Einheiten mit Bewegungsplan kriegen ein NACH: */
|
|
|
|
|
if (long_order==NULL) {
|
|
|
|
|
attrib * ta = a_find(u->attribs, &at_targetregion);
|
|
|
|
|
if (ta) {
|
|
|
|
|
if (u->region == (region*)ta->data.v) {
|
|
|
|
|
a_remove(&u->attribs, ta);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
} else if (u->race->flags & RCF_MOVERANDOM) {
|
|
|
|
|
if (rand()%100<MOVECHANCE || check_overpopulated(u)) {
|
|
|
|
|
long_order = monster_move(r, u);
|
2004-06-21 18:45:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-04-30 19:07:46 +02:00
|
|
|
|
}
|
2005-07-10 18:32:47 +02:00
|
|
|
|
|
|
|
|
|
if (long_order==NULL) {
|
|
|
|
|
/* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um
|
|
|
|
|
* zu bewachen: */
|
|
|
|
|
if (u->race->bonus[SK_WEAPONLESS] != -99) {
|
|
|
|
|
if (eff_skill(u, SK_WEAPONLESS, u->region) < 1) {
|
2005-07-10 22:58:13 +02:00
|
|
|
|
sprintf(buf, "%s \"%s\"",
|
|
|
|
|
locale_string(f->locale, keywords[K_STUDY]),
|
|
|
|
|
skillname(SK_WEAPONLESS, f->locale));
|
2005-07-10 18:32:47 +02:00
|
|
|
|
long_order = parse_order(buf, f->locale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:07:46 +02:00
|
|
|
|
if (long_order==NULL) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
/* Ab hier noch nicht generalisierte Spezialbehandlungen. */
|
|
|
|
|
|
|
|
|
|
switch (old_race(u->race)) {
|
2005-04-30 19:07:46 +02:00
|
|
|
|
case RC_SEASERPENT:
|
|
|
|
|
long_order = parse_order(keywords[K_PIRACY], default_locale);
|
|
|
|
|
break;
|
|
|
|
|
case RC_ALP:
|
|
|
|
|
long_order = monster_seeks_target(r, u);
|
|
|
|
|
break;
|
|
|
|
|
case RC_FIREDRAGON:
|
|
|
|
|
case RC_DRAGON:
|
|
|
|
|
case RC_WYRM:
|
|
|
|
|
long_order = plan_dragon(u);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (u->race->flags & RCF_LEARN) {
|
|
|
|
|
long_order = monster_learn(u);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-07-14 22:46:35 +02:00
|
|
|
|
}
|
|
|
|
|
if (long_order) {
|
|
|
|
|
set_order(&u->thisorder, copy_order(long_order));
|
2005-04-30 19:07:46 +02:00
|
|
|
|
#ifdef LASTORDER
|
2005-07-14 22:46:35 +02:00
|
|
|
|
set_order(&u->lastorder, copy_order(long_order));
|
2005-04-30 19:07:46 +02:00
|
|
|
|
#else
|
2005-07-14 22:46:35 +02:00
|
|
|
|
addlist(&u->orders, long_order);
|
2005-04-30 19:07:46 +02:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2004-06-21 18:45:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-06-11 10:09:55 +02:00
|
|
|
|
pathfinder_cleanup();
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|