2016-08-21 21:21:56 +02:00
|
|
|
|
/*
|
|
|
|
|
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 "volcano.h"
|
|
|
|
|
|
|
|
|
|
#include "alchemy.h"
|
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/messages.h>
|
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/unit.h>
|
2016-08-26 18:26:26 +02:00
|
|
|
|
#include <kernel/terrain.h>
|
2016-08-21 21:21:56 +02:00
|
|
|
|
|
|
|
|
|
/* attributes includes */
|
|
|
|
|
#include <attributes/reduceproduction.h>
|
|
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/log.h>
|
|
|
|
|
#include <util/rand.h>
|
|
|
|
|
#include <util/message.h>
|
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
static int nb_armor(const unit * u, int index)
|
|
|
|
|
{
|
|
|
|
|
const item *itm;
|
|
|
|
|
int av = 0;
|
|
|
|
|
int s = 0, a = 0;
|
|
|
|
|
|
|
|
|
|
if (!(u_race(u)->battle_flags & BF_EQUIPMENT))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2017-01-23 11:13:01 +01:00
|
|
|
|
/* Normale R<>stung */
|
2016-08-21 21:21:56 +02:00
|
|
|
|
|
|
|
|
|
for (itm = u->items; itm; itm = itm->next) {
|
|
|
|
|
const armor_type *atype = itm->type->rtype->atype;
|
|
|
|
|
if (atype != NULL) {
|
|
|
|
|
int *schutz = &a;
|
|
|
|
|
if (atype->flags & ATF_SHIELD)
|
|
|
|
|
schutz = &s;
|
|
|
|
|
if (*schutz <= index) {
|
|
|
|
|
*schutz += itm->number;
|
|
|
|
|
if (*schutz > index) {
|
|
|
|
|
av += atype->prot;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return av;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 21:05:11 +01:00
|
|
|
|
static bool resurrect_unit(unit *u) {
|
|
|
|
|
if (oldpotiontype[P_HEAL]) {
|
|
|
|
|
bool heiltrank = false;
|
|
|
|
|
if (get_effect(u, oldpotiontype[P_HEAL]) > 0) {
|
|
|
|
|
change_effect(u, oldpotiontype[P_HEAL], -1);
|
|
|
|
|
heiltrank = true;
|
|
|
|
|
}
|
|
|
|
|
else if (i_get(u->items, oldpotiontype[P_HEAL]) > 0) {
|
|
|
|
|
i_change(&u->items, oldpotiontype[P_HEAL], -1);
|
|
|
|
|
change_effect(u, oldpotiontype[P_HEAL], 3);
|
|
|
|
|
heiltrank = true;
|
|
|
|
|
}
|
2018-02-16 20:06:36 +01:00
|
|
|
|
if (heiltrank && (rng_int() % 2)) {
|
2018-02-15 21:05:11 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 20:06:36 +01:00
|
|
|
|
static int damage_unit(unit * u, const char *dam, bool physical, bool magic)
|
2016-08-21 21:21:56 +02:00
|
|
|
|
{
|
|
|
|
|
int *hp, hpstack[20];
|
|
|
|
|
int h;
|
2018-02-16 20:06:36 +01:00
|
|
|
|
int healings;
|
2018-02-15 21:05:11 +01:00
|
|
|
|
int i, dead = 0, hp_rem = 0;
|
2016-08-21 21:21:56 +02:00
|
|
|
|
|
|
|
|
|
assert(u->number);
|
2017-05-24 08:52:19 +02:00
|
|
|
|
if (fval(u_race(u), RCF_ILLUSIONARY)) {
|
2016-08-21 21:21:56 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(u->number <= u->hp);
|
|
|
|
|
h = u->hp / u->number;
|
|
|
|
|
/* HP verteilen */
|
|
|
|
|
if (u->number < 20) {
|
|
|
|
|
hp = hpstack;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
hp = malloc(u->number * sizeof(int));
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < u->number; i++)
|
|
|
|
|
hp[i] = h;
|
|
|
|
|
h = u->hp - (u->number * h);
|
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
|
hp[i]++;
|
|
|
|
|
|
|
|
|
|
/* Schaden */
|
|
|
|
|
for (i = 0; i < u->number; i++) {
|
|
|
|
|
int damage = dice_rand(dam);
|
2017-02-24 20:47:47 +01:00
|
|
|
|
if (magic) {
|
|
|
|
|
variant magres = magic_resistance(u);
|
2017-10-29 18:55:43 +01:00
|
|
|
|
int save = magres.sa[0] / magres.sa[1];
|
|
|
|
|
damage -= damage * save;
|
2017-02-24 20:47:47 +01:00
|
|
|
|
}
|
|
|
|
|
if (physical) {
|
2016-08-21 21:21:56 +02:00
|
|
|
|
damage -= nb_armor(u, i);
|
2017-02-24 20:47:47 +01:00
|
|
|
|
}
|
2016-08-21 21:21:56 +02:00
|
|
|
|
hp[i] -= damage;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 20:06:36 +01:00
|
|
|
|
/* does this unit have any healing potions or effects? */
|
|
|
|
|
healings = i_get(u->items, oldpotiontype[P_HEAL]) * 4;
|
|
|
|
|
healings += get_effect(u, oldpotiontype[P_HEAL]);
|
2016-08-21 21:21:56 +02:00
|
|
|
|
/* Auswirkungen */
|
|
|
|
|
for (i = 0; i < u->number; i++) {
|
|
|
|
|
if (hp[i] <= 0) {
|
|
|
|
|
/* Sieben Leben */
|
2016-09-19 08:56:33 +02:00
|
|
|
|
if (u_race(u) == get_race(RC_CAT) && (chance(1.0 / 7))) {
|
2016-08-21 21:21:56 +02:00
|
|
|
|
hp[i] = u->hp / u->number;
|
|
|
|
|
hp_rem += hp[i];
|
|
|
|
|
}
|
2018-02-16 20:06:36 +01:00
|
|
|
|
else if (healings > 0) {
|
|
|
|
|
--healings;
|
|
|
|
|
if (resurrect_unit(u)) {
|
|
|
|
|
/* Heiltrank benutzen */
|
|
|
|
|
hp[i] = u->hp / u->number;
|
|
|
|
|
hp_rem += hp[i];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
++dead;
|
|
|
|
|
}
|
2018-02-15 21:05:11 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
++dead;
|
2016-08-21 21:21:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
hp_rem += hp[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scale_number(u, u->number - dead);
|
|
|
|
|
u->hp = hp_rem;
|
|
|
|
|
|
|
|
|
|
if (hp != hpstack) {
|
|
|
|
|
free(hp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static region *rrandneighbour(region * r)
|
|
|
|
|
{
|
|
|
|
|
direction_t i;
|
|
|
|
|
region *rc = NULL;
|
|
|
|
|
int rr, c = 0;
|
|
|
|
|
|
|
|
|
|
/* Nachsehen, wieviele Regionen in Frage kommen */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
c++;
|
|
|
|
|
}
|
2017-01-23 11:13:01 +01:00
|
|
|
|
/* Zuf<75>llig eine ausw<73>hlen */
|
2016-08-21 21:21:56 +02:00
|
|
|
|
|
|
|
|
|
rr = rng_int() % c;
|
|
|
|
|
|
2017-01-23 11:13:01 +01:00
|
|
|
|
/* Durchz<68>hlen */
|
2016-08-21 21:21:56 +02:00
|
|
|
|
|
|
|
|
|
c = -1;
|
|
|
|
|
for (i = 0; i != MAXDIRECTIONS; i++) {
|
|
|
|
|
rc = rconnect(r, i);
|
|
|
|
|
c++;
|
|
|
|
|
if (c == rr)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
assert(i != MAXDIRECTIONS);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
volcano_destruction(region * volcano, region * r, const char *damage)
|
|
|
|
|
{
|
|
|
|
|
attrib *a;
|
|
|
|
|
unit **up;
|
|
|
|
|
int percent = 25, time = 6 + rng_int() % 12;
|
|
|
|
|
|
|
|
|
|
rsettrees(r, 2, 0);
|
|
|
|
|
rsettrees(r, 1, 0);
|
|
|
|
|
rsettrees(r, 0, 0);
|
|
|
|
|
|
|
|
|
|
a = a_find(r->attribs, &at_reduceproduction);
|
|
|
|
|
if (!a) {
|
|
|
|
|
a = a_add(&r->attribs, make_reduceproduction(percent, time));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Produktion vierteln ... */
|
|
|
|
|
a->data.sa[0] = (short)percent;
|
2017-01-23 11:13:01 +01:00
|
|
|
|
/* F<>r 6-17 Runden */
|
2016-08-21 21:21:56 +02:00
|
|
|
|
a->data.sa[1] = (short)(a->data.sa[1] + time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Personen bekommen 4W10 Punkte Schaden. */
|
|
|
|
|
|
|
|
|
|
for (up = &r->units; *up;) {
|
|
|
|
|
unit *u = *up;
|
|
|
|
|
if (u->number) {
|
|
|
|
|
int dead = damage_unit(u, damage, true, false);
|
|
|
|
|
/* TODO create undead */
|
|
|
|
|
if (dead) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("volcano_dead",
|
|
|
|
|
"unit region dead", u, volcano, dead));
|
|
|
|
|
}
|
|
|
|
|
if (!fval(u->faction, FFL_SELECT)) {
|
|
|
|
|
fset(u->faction, FFL_SELECT);
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("volcanooutbreaknn",
|
2017-12-25 21:55:50 +01:00
|
|
|
|
"region", volcano));
|
2016-08-21 21:21:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (u == *up) {
|
|
|
|
|
up = &u->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (r != volcano) {
|
|
|
|
|
ADDMSG(&r->msgs, msg_message("volcanooutbreak",
|
|
|
|
|
"regionv regionn", volcano, r));
|
|
|
|
|
}
|
|
|
|
|
remove_empty_units_in_region(r);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 18:26:26 +02:00
|
|
|
|
void volcano_outbreak(region * r, region *rn)
|
2016-08-21 21:21:56 +02:00
|
|
|
|
{
|
|
|
|
|
unit *u;
|
|
|
|
|
faction *f;
|
|
|
|
|
|
|
|
|
|
for (f = NULL, u = r->units; u; u = u->next) {
|
|
|
|
|
if (f != u->faction) {
|
|
|
|
|
f = u->faction;
|
|
|
|
|
freset(f, FFL_SELECT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volcano_destruction(r, r, "4d10");
|
|
|
|
|
if (rn) {
|
|
|
|
|
volcano_destruction(r, rn, "3d10");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 11:13:01 +01:00
|
|
|
|
static bool stop_smoke_chance(void) {
|
2017-01-23 11:44:34 +01:00
|
|
|
|
static int cache, percent = 0;
|
|
|
|
|
if (config_changed(&cache)) {
|
|
|
|
|
percent = config_get_int("volcano.stop.percent", 12);
|
|
|
|
|
}
|
2018-02-16 20:06:36 +01:00
|
|
|
|
return percent != 0 && (rng_int() % 100) < percent;
|
2017-01-23 11:13:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool outbreak_chance(void) {
|
2017-01-23 11:44:34 +01:00
|
|
|
|
static int cache, percent = 0;
|
|
|
|
|
if (config_changed(&cache)) {
|
|
|
|
|
percent = config_get_int("volcano.outbreak.percent", 8);
|
|
|
|
|
}
|
2018-02-16 20:06:36 +01:00
|
|
|
|
return percent != 0 && (rng_int() % 100) < percent;
|
2017-01-23 11:13:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 20:06:36 +01:00
|
|
|
|
void volcano_update(void)
|
2016-08-22 21:27:24 +02:00
|
|
|
|
{
|
2018-02-16 20:06:36 +01:00
|
|
|
|
region *r;
|
2016-08-26 18:26:26 +02:00
|
|
|
|
const struct terrain_type *t_active, *t_volcano;
|
|
|
|
|
|
|
|
|
|
t_volcano = get_terrain("volcano");
|
|
|
|
|
t_active = get_terrain("activevolcano");
|
2016-08-22 21:27:24 +02:00
|
|
|
|
/* Vulkane qualmen, brechen aus ... */
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
2016-08-26 18:26:26 +02:00
|
|
|
|
if (r->terrain == t_active) {
|
2016-08-22 21:27:24 +02:00
|
|
|
|
if (a_find(r->attribs, &at_reduceproduction)) {
|
|
|
|
|
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
|
2016-08-26 18:26:26 +02:00
|
|
|
|
r->terrain = t_volcano;
|
2016-08-22 21:27:24 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2017-01-23 11:13:01 +01:00
|
|
|
|
if (stop_smoke_chance()) {
|
2016-08-22 21:27:24 +02:00
|
|
|
|
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
|
2016-08-26 18:26:26 +02:00
|
|
|
|
r->terrain = t_volcano;
|
2016-08-22 21:27:24 +02:00
|
|
|
|
}
|
2017-01-23 11:13:01 +01:00
|
|
|
|
else if (r->uid == 1246051340 || outbreak_chance()) {
|
2017-02-18 21:15:14 +01:00
|
|
|
|
/* HACK: a fixed E4-only region-uid in Code.
|
|
|
|
|
* FIXME: In E4 gibt es eine Ebene #1246051340, die Smalland heisst.
|
|
|
|
|
* da das kein aktiver Vulkan ist, ist dieser Test da nicht idiotisch?
|
|
|
|
|
* das sollte bestimmt rn betreffen? */
|
2016-08-26 18:26:26 +02:00
|
|
|
|
region *rn;
|
|
|
|
|
rn = rrandneighbour(r);
|
|
|
|
|
volcano_outbreak(r, rn);
|
|
|
|
|
r->terrain = t_volcano;
|
2016-08-22 21:27:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-26 18:26:26 +02:00
|
|
|
|
else if (r->terrain == t_volcano) {
|
2016-11-18 13:30:24 +01:00
|
|
|
|
int volcano_chance = config_get_int("volcano.active.percent", 4);
|
|
|
|
|
if (rng_int() % 100 < volcano_chance) {
|
2016-08-22 21:27:24 +02:00
|
|
|
|
ADDMSG(&r->msgs, msg_message("volcanostartsmoke", "region", r));
|
2016-08-26 18:26:26 +02:00
|
|
|
|
r->terrain = t_active;
|
2016-08-22 21:27:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-06 21:04:30 +01:00
|
|
|
|
|
|
|
|
|
bool volcano_module(void)
|
|
|
|
|
{
|
|
|
|
|
static int cache;
|
|
|
|
|
static bool active;
|
|
|
|
|
if (config_changed(&cache)) {
|
|
|
|
|
active = config_get_int("modules.volcano", 0) != 0;
|
|
|
|
|
}
|
|
|
|
|
return active;
|
|
|
|
|
}
|