server/src/modules/arena.c

256 lines
6.5 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
/*
2015-01-30 22:10:29 +01:00
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
2010-08-08 10:06:34 +02:00
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>
#if ARENA_MODULE
#include "arena.h"
/* modules include */
#include "score.h"
/* items include */
#include <items/demonseye.h>
/* kernel includes */
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/messages.h>
2010-08-08 10:06:34 +02:00
#include <kernel/order.h>
#include <kernel/plane.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>
#include <move.h>
2010-08-08 10:06:34 +02:00
/* util include */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/gamedata.h>
2010-08-08 10:06:34 +02:00
#include <util/functions.h>
#include <util/strings.h>
2010-08-08 10:06:34 +02:00
#include <util/lists.h>
#include <util/log.h>
#include <util/resolve.h>
#include <util/rng.h>
#include <storage.h>
2010-08-08 10:06:34 +02:00
/* libc include */
#include <assert.h>
#include <stdlib.h>
#include <string.h>
2015-09-06 19:08:57 +02:00
#include <limits.h>
2010-08-08 10:06:34 +02:00
/* exports: */
2011-03-07 08:02:35 +01:00
plane *arena = NULL;
2010-08-08 10:06:34 +02:00
/* local vars */
#define CENTRAL_VOLCANO 1
2011-03-07 08:02:35 +01:00
static region *tower_region[6];
static region *start_region[6];
static region *arena_region(int school)
2010-08-08 10:06:34 +02:00
{
return tower_region[school];
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static building *arena_tower(int school)
2010-08-08 10:06:34 +02:00
{
return arena_region(school)->buildings;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static int leave_fail(unit * u)
2010-08-08 10:06:34 +02:00
{
ADDMSG(&u->faction->msgs, msg_message("arena_leave_fail", "unit", u));
return 1;
2010-08-08 10:06:34 +02:00
}
static int
2011-03-07 08:02:35 +01:00
leave_arena(struct unit *u, const struct item_type *itype, int amount,
order * ord)
2010-08-08 10:06:34 +02:00
{
2014-03-16 05:03:17 +01:00
if (!u->building && leave_fail(u)) {
return -1;
}
if (u->building != arena_tower(u->faction->magiegebiet) && leave_fail(u)) {
return -1;
2014-03-16 05:03:17 +01:00
}
UNUSED_ARG(amount);
UNUSED_ARG(ord);
UNUSED_ARG(itype);
2014-03-16 05:03:17 +01:00
assert(!"not implemented");
return 0;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static int enter_fail(unit * u)
2010-08-08 10:06:34 +02:00
{
ADDMSG(&u->faction->msgs, msg_message("arena_enter_fail", "region unit",
u->region, u));
return 1;
2010-08-08 10:06:34 +02:00
}
static int
enter_arena(unit * u, const item_type * itype, int amount, order * ord)
{
skill_t sk;
region *r = u->region;
unit *u2;
int fee = 2000;
UNUSED_ARG(ord);
UNUSED_ARG(amount);
UNUSED_ARG(itype);
if (u->faction->score > fee * 5) {
score_t score = u->faction->score / 5;
if (score < INT_MAX) {
fee = (int)score;
}
else {
fee = INT_MAX;
}
}
if (getplane(r) == arena)
return -1;
if (u->number != 1 && enter_fail(u))
return -1;
if (get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, fee) < fee
&& enter_fail(u))
return -1;
for (sk = 0; sk != MAXSKILLS; ++sk) {
if (get_level(u, sk) > 1 && enter_fail(u))
return -1;
}
for (u2 = r->units; u2; u2 = u2->next)
if (u2->faction == u->faction)
break;
assert(!"not implemented");
/*
for (res=0;res!=MAXRESOURCES;++res) if (res!=R_SILVER && res!=R_ARENA_GATE && (is_item(res) || is_herb(res) || is_potion(res))) {
int x = get_resource(u, res);
if (x) {
if (u2) {
change_resource(u2, res, x);
change_resource(u, res, -x);
}
else if (enter_fail(u)) return -1;
}
}
*/
if (get_money(u) > fee) {
if (u2)
change_money(u2, get_money(u) - fee);
else if (enter_fail(u))
return -1;
}
ADDMSG(&u->faction->msgs, msg_message("arena_enter_fail", "region unit",
u->region, u));
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE, 1);
use_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, fee);
set_money(u, 109);
fset(u, UFL_ANON_FACTION);
move_unit(u, start_region[rng_int() % 6], NULL);
return 0;
2010-08-08 10:06:34 +02:00
}
#ifdef CENTRAL_VOLCANO
2011-03-07 08:02:35 +01:00
static int caldera_handle(trigger * t, void *data)
2010-08-08 10:06:34 +02:00
{
/* call an event handler on caldera.
* data.v -> ( variant event, int timer )
*/
building *b = (building *)t->data.v;
if (b != NULL) {
unit **up = &b->region->units;
while (*up) {
unit *u = *up;
if (u->building == b) {
message *msg;
if (u->items) {
item **ip = &u->items;
msg = msg_message("caldera_handle_1", "unit items", u, u->items);
while (*ip) {
item *i = *ip;
i_remove(ip, i);
if (*ip == i)
ip = &i->next;
}
}
else {
msg = msg_message("caldera_handle_0", "unit", u);
}
add_message(&u->region->msgs, msg);
set_number(u, 0);
}
if (*up == u)
up = &u->next;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
}
else {
log_error("could not perform caldera::handle()\n");
}
UNUSED_ARG(data);
return 0;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static void caldera_write(const trigger * t, struct storage *store)
2010-08-08 10:06:34 +02:00
{
building *b = (building *)t->data.v;
write_building_reference(b, store);
2010-08-08 10:06:34 +02:00
}
static int caldera_read(trigger * t, struct gamedata *data)
2010-08-08 10:06:34 +02:00
{
int rb =
read_reference(&t->data.v, data, read_building_reference,
resolve_building);
if (rb == 0 && !t->data.v) {
return AT_READ_FAIL;
}
return AT_READ_OK;
2010-08-08 10:06:34 +02:00
}
struct trigger_type tt_caldera = {
"caldera",
NULL,
NULL,
caldera_handle,
caldera_write,
caldera_read
2010-08-08 10:06:34 +02:00
};
#endif
2011-03-07 08:02:35 +01:00
void register_arena(void)
2010-08-08 10:06:34 +02:00
{
at_deprecate("hurting", a_readint);
register_function((pf_generic)enter_arena, "enter_arena");
register_function((pf_generic)leave_arena, "leave_arena");
tt_register(&tt_caldera);
2010-08-08 10:06:34 +02:00
}
#endif /* def ARENA_MODULE */