refactoring: eliminate a_findc, and too much const-fuckery

This commit is contained in:
Enno Rehling 2016-02-01 17:31:03 +01:00
parent 4804b2c30a
commit d0f8723ffb
11 changed files with 14 additions and 22 deletions

View File

@ -49,7 +49,7 @@ attrib_type at_movement = {
bool get_movement(attrib * const *alist, int type)
{
const attrib *a = a_findc(*alist, &at_movement);
const attrib *a = a_find(*alist, &at_movement);
if (a == NULL)
return false;
if (a->data.i & type)

View File

@ -45,10 +45,10 @@ void set_prefix(attrib ** ap, const char *str)
a->data.v = _strdup(str);
}
const char *get_prefix(const attrib * a)
const char *get_prefix(attrib * a)
{
char *str;
a = a_findc(a, &at_raceprefix);
a = a_find(a, &at_raceprefix);
if (a == NULL)
return NULL;
str = (char *)a->data.v;

View File

@ -24,7 +24,7 @@ extern "C" {
extern struct attrib_type at_raceprefix;
extern void set_prefix(struct attrib **ap, const char *str);
extern const char *get_prefix(const struct attrib *a);
extern const char *get_prefix(struct attrib *a);
#ifdef __cplusplus
}

View File

@ -180,10 +180,10 @@ alliedgroup(const struct plane *pl, const struct faction *f,
}
mode = ally_mode(sf, mode) | (mode & autoalliance(pl, f, f2));
if (AllianceRestricted()) {
if (a_findc(f->attribs, &at_npcfaction)) {
if (a_find(f->attribs, &at_npcfaction)) {
return mode;
}
if (a_findc(f2->attribs, &at_npcfaction)) {
if (a_find(f2->attribs, &at_npcfaction)) {
return mode;
}
if (f->alliance != f2->alliance) {
@ -232,7 +232,7 @@ int alliedunit(const unit * u, const faction * f2, int mode)
sf = u->faction->allies;
if (fval(u, UFL_GROUP)) {
const attrib *a = a_findc(u->attribs, &at_group);
const attrib *a = a_find(u->attribs, &at_group);
if (a != NULL)
sf = ((group *)a->data.v)->allies;
}

View File

@ -242,10 +242,10 @@ const char *rc_name_s(const race * rc, name_t n)
const char *raceprefix(const unit * u)
{
const attrib *asource = u->faction->attribs;
attrib *asource = u->faction->attribs;
if (fval(u, UFL_GROUP)) {
const attrib *agroup = a_findc(u->attribs, &at_group);
attrib *agroup = a_find(u->attribs, &at_group);
if (agroup != NULL)
asource = ((const group *)(agroup->data.v))->attribs;
}

View File

@ -122,7 +122,7 @@ get_followers(unit * target, region * r, const region_list * route_end,
unit *uf;
for (uf = r->units; uf; uf = uf->next) {
if (fval(uf, UFL_FOLLOWING) && !fval(uf, UFL_NOTMOVING)) {
const attrib *a = a_findc(uf->attribs, &at_follow);
const attrib *a = a_find(uf->attribs, &at_follow);
if (a && a->data.v == target) {
follower *fnew = (follower *)malloc(sizeof(follower));
fnew->uf = uf;

View File

@ -354,7 +354,7 @@ const char **illusion)
bt_illusion = bt_find("illusioncastle");
if (bt_illusion && b->type == bt_illusion) {
const attrib *a = a_findc(b->attribs, &at_icastle);
const attrib *a = a_find(b->attribs, &at_icastle);
if (a != NULL) {
*illusion = buildingtype(icastle_type(a), b, b->size);
}

View File

@ -3091,9 +3091,9 @@ static int sp_summonshadowlords(castorder * co)
static bool chaosgate_valid(const connection * b)
{
const attrib *a = a_findc(b->from->attribs, &at_direction);
const attrib *a = a_find(b->from->attribs, &at_direction);
if (!a)
a = a_findc(b->to->attribs, &at_direction);
a = a_find(b->to->attribs, &at_direction);
if (!a)
return false;
return true;

View File

@ -101,13 +101,6 @@ attrib *a_find(attrib * a, const attrib_type * at)
return a;
}
const attrib *a_findc(const attrib * a, const attrib_type * at)
{
while (a && a->type != at)
a = a->nexttype;
return a;
}
static attrib *a_insert(attrib * head, attrib * a)
{
attrib **pa;

View File

@ -68,7 +68,6 @@ extern "C" {
extern attrib *a_select(attrib * a, const void *data,
bool(*compare) (const attrib *, const void *));
extern attrib *a_find(attrib * a, const attrib_type * at);
extern const attrib *a_findc(const attrib * a, const attrib_type * at);
extern attrib *a_add(attrib ** pa, attrib * at);
extern int a_remove(attrib ** pa, attrib * at);
extern void a_removeall(attrib ** a, const attrib_type * at);

View File

@ -149,7 +149,7 @@ attrib *create_special_direction(region * r, region * rt, int duration,
spec_direction *special_direction(const region * from, const region * to)
{
const attrib *a = a_findc(from->attribs, &at_direction);
const attrib *a = a_find(from->attribs, &at_direction);
while (a != NULL && a->type == &at_direction) {
spec_direction *sd = (spec_direction *)a->data.v;