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>
|
2015-01-30 20:37:14 +01:00
|
|
|
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>
|
|
|
|
#include "movement.h"
|
|
|
|
|
|
|
|
#include <util/attrib.h>
|
2016-02-13 13:42:02 +01:00
|
|
|
#include <util/gamedata.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
#include <util/macros.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
|
|
|
#include <storage.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-05-15 19:08:44 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
static int read_movement(variant *var, void *owner, gamedata *data)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
READ_INT(data->store, &var->i);
|
|
|
|
if (var->i != 0)
|
2015-01-30 20:37:14 +01:00
|
|
|
return AT_READ_OK;
|
|
|
|
else
|
|
|
|
return AT_READ_FAIL;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
attrib_type at_movement = {
|
2018-02-09 21:20:43 +01:00
|
|
|
"movement", NULL, NULL, NULL, a_writeint, read_movement
|
2010-08-08 10:06:34 +02:00
|
|
|
};
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
bool get_movement(attrib * const *alist, int type)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-02-01 17:31:03 +01:00
|
|
|
const attrib *a = a_find(*alist, &at_movement);
|
2015-01-30 20:37:14 +01:00
|
|
|
if (a == NULL)
|
|
|
|
return false;
|
|
|
|
if (a->data.i & type)
|
|
|
|
return true;
|
2011-03-07 08:02:35 +01:00
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void set_movement(attrib ** alist, int type)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
attrib *a = a_find(*alist, &at_movement);
|
|
|
|
if (a == NULL)
|
|
|
|
a = a_add(alist, a_new(&at_movement));
|
|
|
|
a->data.i |= type;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-12-25 18:16:24 +01:00
|
|
|
|
2015-12-16 22:18:44 +01:00
|
|
|
static int age_speedup(attrib * a, void *owner)
|
2014-12-25 18:16:24 +01:00
|
|
|
{
|
2017-01-10 16:31:05 +01:00
|
|
|
UNUSED_ARG(owner);
|
2014-12-25 18:16:24 +01:00
|
|
|
if (a->data.sa[0] > 0) {
|
2015-05-15 19:08:44 +02:00
|
|
|
assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN);
|
|
|
|
assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX);
|
|
|
|
a->data.sa[0] = (short)(a->data.sa[0] - a->data.sa[1]);
|
2014-12-25 18:16:24 +01:00
|
|
|
}
|
|
|
|
return (a->data.sa[0] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
attrib_type at_speedup = {
|
|
|
|
"speedup",
|
|
|
|
NULL, NULL,
|
|
|
|
age_speedup,
|
|
|
|
a_writeint,
|
|
|
|
a_readint
|
|
|
|
};
|
|
|
|
|