2010-08-08 10:06:34 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 1998-2010, 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 "otherfaction.h"
|
|
|
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <util/storage.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* simple attributes that do not yet have their own file
|
|
|
|
*/
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void write_of(const struct attrib *a, const void *owner, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
const faction *f = (faction *) a->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
store->w_int(store, f->no);
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int read_of(struct attrib *a, void *owner, struct storage *store)
|
|
|
|
{ /* return 1 on success, 0 if attrib needs removal */
|
2012-03-05 04:29:32 +01:00
|
|
|
int of;
|
|
|
|
static int rule = -1;
|
|
|
|
if (rule<0) {
|
|
|
|
rule = rule_stealth_faction();
|
|
|
|
}
|
|
|
|
|
|
|
|
of = store->r_int(store);
|
|
|
|
if (rule&2) {
|
|
|
|
a->data.v = findfaction(of);
|
|
|
|
if (a->data.v) {
|
|
|
|
return AT_READ_OK;
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
return AT_READ_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
attrib_type at_otherfaction = {
|
|
|
|
"otherfaction", NULL, NULL, NULL, write_of, read_of, ATF_UNIQUE
|
|
|
|
};
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct faction *get_otherfaction(const struct attrib *a)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
return (faction *) (a->data.v);
|
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
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
attrib *a = a_new(&at_otherfaction);
|
|
|
|
a->data.v = (void *)f;
|
2010-08-08 10:06:34 +02:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
if (f == NULL || !alliedunit(u, f, HELP_FSTEALTH)) {
|
2010-08-08 10:06:34 +02:00
|
|
|
attrib *a = a_find(u->attribs, &at_otherfaction);
|
|
|
|
if (a) {
|
|
|
|
faction *fv = get_otherfaction(a);
|
2011-03-07 08:02:35 +01:00
|
|
|
assert(fv != NULL); /* fv should never be NULL! */
|
2010-08-08 10:06:34 +02:00
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return u->faction;
|
|
|
|
}
|