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 "otherfaction.h"
|
|
|
|
|
2015-11-24 18:52:09 +01:00
|
|
|
#include <kernel/ally.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <util/attrib.h>
|
2016-02-13 13:42:02 +01:00
|
|
|
#include <util/gamedata.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
|
|
|
#include <storage.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*
|
2015-01-30 20:37:14 +01:00
|
|
|
* simple attributes that do not yet have their own file
|
2010-08-08 10:06:34 +02:00
|
|
|
*/
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
void write_of(const variant *var, const void *owner, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
const faction *f = (faction *)var->v;
|
2015-01-30 20:37:14 +01:00
|
|
|
WRITE_INT(store, f->no);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
int read_of(variant *var, void *owner, gamedata *data)
|
2011-03-07 08:02:35 +01:00
|
|
|
{ /* return 1 on success, 0 if attrib needs removal */
|
2015-01-30 20:37:14 +01:00
|
|
|
int of;
|
2012-03-05 04:29:32 +01:00
|
|
|
|
2016-02-13 13:42:02 +01:00
|
|
|
READ_INT(data->store, &of);
|
2015-11-09 13:36:52 +01:00
|
|
|
if (rule_stealth_other()) {
|
2018-02-09 21:20:43 +01:00
|
|
|
var->v = findfaction(of);
|
|
|
|
if (var->v) {
|
2015-01-30 20:37:14 +01:00
|
|
|
return AT_READ_OK;
|
|
|
|
}
|
2012-03-05 04:29:32 +01:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
return AT_READ_FAIL;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
attrib_type at_otherfaction = {
|
2016-02-09 06:43:19 +01:00
|
|
|
"otherfaction", NULL, NULL, NULL, write_of, read_of, NULL, ATF_UNIQUE
|
2010-08-08 10:06:34 +02:00
|
|
|
};
|
|
|
|
|
2017-03-06 21:35:48 +01:00
|
|
|
faction *get_otherfaction(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2017-03-06 21:35:48 +01:00
|
|
|
attrib *a = a_find(u->attribs, &at_otherfaction);
|
|
|
|
if (a) {
|
|
|
|
faction * f = (faction *)(a->data.v);
|
|
|
|
if (f && f->_alive) {
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct attrib *make_otherfaction(struct faction *f)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
attrib *a = a_new(&at_otherfaction);
|
|
|
|
a->data.v = (void *)f;
|
|
|
|
return a;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
faction *visible_faction(const faction * f, const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
if (f == NULL || !alliedunit(u, f, HELP_FSTEALTH)) {
|
2017-03-06 21:35:48 +01:00
|
|
|
faction *fv = get_otherfaction(u);
|
|
|
|
if (fv) return fv;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
return u->faction;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|