2010-08-08 10:06:34 +02:00
|
|
|
#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>
|
2018-09-29 11:37:17 +02:00
|
|
|
#include <kernel/attrib.h>
|
2018-09-29 13:21:46 +02:00
|
|
|
#include <kernel/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
|
|
|
}
|