use getters/setters to access unit::race

This commit is contained in:
Enno Rehling 2013-05-02 03:50:24 +02:00
parent 3d7be88bad
commit b4b8c49934
9 changed files with 66 additions and 62 deletions

4
.gitignore vendored
View File

@ -12,3 +12,7 @@ ipch/
src/Release/
game-e3/data/
game-e3/reports/
game-e3/*.log*
game-e2/data
game-e2/reports/
game-e2/*.log*

@ -1 +1 @@
Subproject commit 79feb5723c075a45a1a94ed286c87993314ce8da
Subproject commit efc7373fb9f9171caa226f06ebca75b1b8425548

View File

@ -67,7 +67,7 @@ static int fix_familiars(struct lua_State *L)
free(mage->spellbook);
mage->spellbook = 0;
snprintf(buffer, sizeof(buffer), "%s_familiar", u->race->_name[0]);
snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name[0]);
eq = get_equipment(buffer);
if (eq) {
equip_unit_mask(u, eq, EQUIP_SPELLS);

View File

@ -164,7 +164,7 @@ static order *get_money_for_dragon(region * r, unit * u, int wanted)
/* falls genug geld in der region ist, treiben wir steuern ein. */
if (rmoney(r) >= wanted) {
/* 5% chance, dass der drache aus einer laune raus attackiert */
if (chance(1.0 - u->race->aggression)) {
if (chance(1.0 - u_race(u)->aggression)) {
return create_order(K_TAX, default_locale, NULL);
}
}
@ -251,7 +251,7 @@ static bool room_for_race_in_region(region * r, const race * rc)
int c = 0;
for (u = r->units; u; u = u->next) {
if (u->race == rc)
if (u_race(u) == rc)
c += u->number;
}
@ -274,7 +274,7 @@ static direction_t random_neighbour(region * r, unit * u)
for (i = 0; i != MAXDIRECTIONS; i++) {
rc = next[i];
if (rc && can_survive(u, rc)) {
if (room_for_race_in_region(rc, u->race)) {
if (room_for_race_in_region(rc, u_race(u))) {
c++;
}
c2++;
@ -302,7 +302,7 @@ static direction_t random_neighbour(region * r, unit * u)
if (rc && can_survive(u, rc)) {
if (c2 == 0) {
c++;
} else if (room_for_race_in_region(rc, u->race)) {
} else if (room_for_race_in_region(rc, u_race(u))) {
c++;
}
if (c == rr)
@ -361,7 +361,7 @@ static order *monster_move(region * r, unit * u)
if (monster_is_waiting(u)) {
return NULL;
}
switch (old_race(u->race)) {
switch (old_race(u_race(u))) {
case RC_FIREDRAGON:
case RC_DRAGON:
case RC_WYRM:
@ -390,7 +390,7 @@ static int dragon_affinity_value(region * r, unit * u)
{
int m = all_money(r, u->faction);
if (u->race == new_race[RC_FIREDRAGON]) {
if (u_race(u) == new_race[RC_FIREDRAGON]) {
return (int)(normalvariate(m, m / 2));
} else {
return (int)(normalvariate(m, m / 4));
@ -483,7 +483,7 @@ static order *monster_seeks_target(region * r, unit * u)
* derzeit gibt es nur den alp
*/
switch (old_race(u->race)) {
switch (old_race(u_race(u))) {
case RC_ALP:
target = alp_target(u);
break;
@ -498,7 +498,7 @@ static order *monster_seeks_target(region * r, unit * u)
}
if (r == target->region) { /* Wir haben ihn! */
if (u->race == new_race[RC_ALP]) {
if (u_race(u) == new_race[RC_ALP]) {
alp_findet_opfer(u, r);
} else {
assert(!"Seeker-Monster hat keine Aktion fuer Ziel");
@ -599,11 +599,11 @@ static bool check_overpopulated(unit * u)
int c = 0;
for (u2 = u->region->units; u2; u2 = u2->next) {
if (u2->race == u->race && u != u2)
if (u_race(u2) == u_race(u) && u != u2)
c += u2->number;
}
if (c > u->race->splitsize * 2)
if (c > u_race(u)->splitsize * 2)
return true;
return false;
@ -654,7 +654,7 @@ static order *plan_dragon(unit * u)
}
move |= chance(0.04); /* 4% chance to change your mind */
if (u->race == new_race[RC_WYRM] && !move) {
if (u_race(u) == new_race[RC_WYRM] && !move) {
unit *u2;
for (u2 = r->units; u2; u2 = u2->next) {
/* wyrme sind einzelgänger */
@ -662,7 +662,7 @@ static order *plan_dragon(unit * u)
/* we do not make room for newcomers, so we don't need to look at them */
break;
}
if (u2 != u && u2->race == u->race && chance(0.5)) {
if (u2 != u && u_race(u2) == u_race(u) && chance(0.5)) {
move = true;
break;
}
@ -684,7 +684,7 @@ static order *plan_dragon(unit * u)
}
if (tr != NULL) {
assert(long_order == NULL);
switch (old_race(u->race)) {
switch (old_race(u_race(u))) {
case RC_FIREDRAGON:
long_order = make_movement_order(u, tr, 4, allowed_dragon);
break;
@ -716,7 +716,7 @@ static order *plan_dragon(unit * u)
if (long_order == NULL) {
/* money is gone, need a new target */
set_new_dragon_target(u, u->region, DRAGON_RANGE);
} else if (u->race != new_race[RC_FIREDRAGON]) {
} else if (u_race(u) != new_race[RC_FIREDRAGON]) {
/* neue dracoiden! */
if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) {
int ra = 20 + rng_int() % 100;
@ -729,7 +729,7 @@ static order *plan_dragon(unit * u)
if (long_order == NULL) {
skill_t sk = SK_PERCEPTION;
/* study perception (or a random useful skill) */
while (!skill_enabled[sk] || u->race->bonus[sk] < -5) {
while (!skill_enabled[sk] || u_race(u)->bonus[sk] < -5) {
sk = (skill_t) (rng_int() % MAXSKILLS);
}
long_order = create_order(K_STUDY, u->faction->locale, "'%s'",
@ -808,7 +808,7 @@ void plan_monsters(faction * f)
if (u->region == (region *) ta->data.v) {
a_remove(&u->attribs, ta);
}
} else if (u->race->flags & RCF_MOVERANDOM) {
} else if (u_race(u)->flags & RCF_MOVERANDOM) {
if (rng_int() % 100 < MOVECHANCE || check_overpopulated(u)) {
long_order = monster_move(r, u);
}
@ -818,7 +818,7 @@ void plan_monsters(faction * f)
if (long_order == NULL) {
/* Einheiten, die Waffenlosen Kampf lernen könnten, lernen es um
* zu bewachen: */
if (u->race->bonus[SK_WEAPONLESS] != -99) {
if (u_race(u)->bonus[SK_WEAPONLESS] != -99) {
if (eff_skill(u, SK_WEAPONLESS, u->region) < 1) {
long_order =
create_order(K_STUDY, f->locale, "'%s'",
@ -834,7 +834,7 @@ void plan_monsters(faction * f)
handle_event(u->attribs, "ai_move", u);
}
switch (old_race(u->race)) {
switch (old_race(u_race(u))) {
case RC_SEASERPENT:
long_order = create_order(K_PIRACY, f->locale, NULL);
break;
@ -849,7 +849,7 @@ void plan_monsters(faction * f)
long_order = plan_dragon(u);
break;
default:
if (u->race->flags & RCF_LEARN) {
if (u_race(u)->flags & RCF_LEARN) {
long_order = monster_learn(u);
}
break;
@ -915,14 +915,14 @@ void spawn_dragons(void)
if (verbosity >= 2) {
log_printf(stdout, "%d %s in %s.\n", u->number,
LOC(default_locale,
rc_name(u->race, u->number != 1)), regionname(r, NULL));
rc_name(u_race(u), u->number != 1)), regionname(r, NULL));
}
name_unit(u);
/* add message to the region */
ADDMSG(&r->msgs,
msg_message("sighting", "region race number", r, u->race, u->number));
msg_message("sighting", "region race number", r, u_race(u), u->number));
}
}
}
@ -990,7 +990,7 @@ void spawn_undead(void)
if (verbosity >= 2) {
log_printf(stdout, "%d %s in %s.\n", u->number,
LOC(default_locale,
rc_name(u->race, u->number != 1)), regionname(r, NULL));
rc_name(u_race(u), u->number != 1)), regionname(r, NULL));
}
{

View File

@ -31,7 +31,7 @@ void age_firedragon(unit * u)
{
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_DRAGON];
u_setrace(u, new_race[RC_DRAGON]);
u->irace = NULL;
scale_number(u, 1);
u->hp = (int)(unit_max_hp(u) * u->number * q);
@ -42,7 +42,7 @@ void age_dragon(unit * u)
{
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_WYRM];
u_setrace(u, new_race[RC_WYRM]);
u->irace = NULL;
u->hp = (int)(unit_max_hp(u) * u->number * q);
}

View File

@ -40,7 +40,7 @@ static void oldfamiliars(unit * u)
char fname[64];
/* these familiars have no special skills.
*/
snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]);
snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name[0]);
create_mage(u, M_GRAY);
equip_unit(u, get_equipment(fname));
}
@ -55,7 +55,7 @@ static void equip_newunits(const struct equipment *eq, struct unit *u)
{
struct region *r = u->region;
switch (old_race(u->race)) {
switch (old_race(u_race(u))) {
case RC_ELF:
set_show_item(u->faction, I_FEENSTIEFEL);
break;

View File

@ -62,7 +62,7 @@ void age_skeleton(unit * u)
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2);
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_SKELETON_LORD];
u_setrace(u, new_race[RC_SKELETON_LORD]);
u->irace = NULL;
scale_number(u, n);
u->hp = (int)(unit_max_hp(u) * u->number * q);
@ -74,7 +74,7 @@ void age_zombie(unit * u)
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2);
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_ZOMBIE_LORD];
u_setrace(u, new_race[RC_ZOMBIE_LORD]);
u->irace = NULL;
scale_number(u, n);
u->hp = (int)(unit_max_hp(u) * u->number * q);
@ -86,7 +86,7 @@ void age_ghoul(unit * u)
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2);
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_GHOUL_LORD];
u_setrace(u, new_race[RC_GHOUL_LORD]);
u->irace = NULL;
scale_number(u, n);
u->hp = (int)(unit_max_hp(u) * u->number * q);

View File

@ -525,7 +525,7 @@ int sp_mindblast_temp(struct castorder * co)
continue;
}
if (humanoidrace(du->race) && force >= du->number) {
if (humanoidrace(u_race(du)) && force >= du->number) {
if (!is_magic_resistant(mage, du, 0)) {
skill_t sk = random_skill(du, true);
if (sk != NOSKILL) {
@ -591,7 +591,7 @@ int sp_mindblast(struct castorder * co)
continue;
}
if (humanoidrace(du->race) && force >= du->number) {
if (humanoidrace(u_race(du)) && force >= du->number) {
if (!is_magic_resistant(mage, du, 0)) {
skill_t sk = random_skill(du, false);
if (sk != NOSKILL) {
@ -815,7 +815,7 @@ int sp_shadowcall(struct castorder * co)
make_fighter(b, u, fi->side, is_attacker(fi));
msg =
msg_message("sp_shadowcall_effect", "mage amount race", mage, u->number,
u->race);
u_race(u));
message_all(b, msg);
msg_release(msg);
return level;
@ -980,7 +980,7 @@ int sp_chaosrow(struct castorder * co)
if (chance(power / n)) {
int row = statusrow(df->status);
df->side->size[row] -= df->alive;
if (df->unit->race->battle_flags & BF_NOBLOCK) {
if (u_race(df->unit)->battle_flags & BF_NOBLOCK) {
df->side->nonblockers[row] -= df->alive;
}
row = FIRST_ROW + (rng_int() % (LAST_ROW - FIRST_ROW));
@ -1002,7 +1002,7 @@ int sp_chaosrow(struct castorder * co)
}
assert(statusrow(df->status) == row);
df->side->size[row] += df->alive;
if (df->unit->race->battle_flags & BF_NOBLOCK) {
if (u_race(df->unit)->battle_flags & BF_NOBLOCK) {
df->side->nonblockers[row] += df->alive;
}
k += df->alive;
@ -1074,7 +1074,7 @@ int sp_flee(struct castorder * co)
--force;
++panik;
} else if (!(df->person[n].flags & FL_COURAGE)
|| !fval(df->unit->race, RCF_UNDEAD)) {
|| !fval(u_race(df->unit), RCF_UNDEAD)) {
if (!is_magic_resistant(mage, df->unit, 0)) {
df->person[n].flags |= FL_PANICED;
++panik;
@ -1552,7 +1552,7 @@ int sp_reanimate(struct castorder * co)
while (healable--) {
fighter *tf = select_corpse(b, fi);
if (tf != NULL && tf->side->casualties > 0
&& tf->unit->race != new_race[RC_DAEMON]
&& u_race(tf->unit) != new_race[RC_DAEMON]
&& (chance(c))) {
assert(tf->alive < tf->unit->number);
/* t.fighter->person[].hp beginnt mit t.index = 0 zu zählen,
@ -1617,11 +1617,11 @@ static int heal_fighters(quicklist * fgs, int *power, bool heal_monsters)
break;
/* Untote kann man nicht heilen */
if (df->unit->number == 0 || fval(df->unit->race, RCF_NOHEAL))
if (df->unit->number == 0 || fval(u_race(df->unit), RCF_NOHEAL))
continue;
/* wir heilen erstmal keine Monster */
if (heal_monsters || playerrace(df->unit->race)) {
if (heal_monsters || playerrace(u_race(df->unit))) {
int n, hp = df->unit->hp / df->unit->number;
int rest = df->unit->hp % df->unit->number;
@ -1718,7 +1718,7 @@ int sp_undeadhero(struct castorder * co)
break;
/* keine Monster */
if (!playerrace(du->race))
if (!playerrace(u_race(du)))
continue;
if (df->alive + df->run.number < du->number) {

View File

@ -490,8 +490,8 @@ static const race *select_familiar(const race * magerace, magic_t magiegebiet)
static void make_familiar(unit * familiar, unit * mage)
{
/* skills and spells: */
if (familiar->race->init_familiar != NULL) {
familiar->race->init_familiar(familiar);
if (u_race(familiar)->init_familiar != NULL) {
u_race(familiar)->init_familiar(familiar);
} else {
log_error("could not perform initialization for familiar %s.\n", familiar->faction->race->_name[0]);
}
@ -1636,7 +1636,7 @@ static int sp_great_drought(castorder * co)
rsetterrain(r, T_OCEAN);
/* Einheiten duerfen hier auf keinen Fall geloescht werden! */
for (u = r->units; u; u = u->next) {
if (u->race != new_race[RC_SPELL] && u->ship == 0) {
if (u_race(u) != new_race[RC_SPELL] && u->ship == 0) {
set_number(u, 0);
}
}
@ -2151,7 +2151,7 @@ static int sp_ironkeeper(castorder * co)
tkill));
}
msg = msg_message("summon_effect", "mage amount race", mage, 1, keeper->race);
msg = msg_message("summon_effect", "mage amount race", mage, 1, u_race(keeper));
r_addmessage(r, NULL, msg);
msg_release(msg);
@ -2580,7 +2580,7 @@ static int sp_summondragon(castorder * co)
for (rl2 = rl; rl2; rl2 = rl2->next) {
region *r2 = rl2->data;
for (u = r2->units; u; u = u->next) {
if (u->race == new_race[RC_WYRM] || u->race == new_race[RC_DRAGON]) {
if (u_race(u) == new_race[RC_WYRM] || u_race(u) == new_race[RC_DRAGON]) {
attrib *a = a_find(u->attribs, &at_targetregion);
if (!a) {
a = a_add(&u->attribs, make_targetregion(r));
@ -2690,7 +2690,7 @@ static int sp_unholypower(castorder * co)
u = pa->param[i]->data.u;
switch (old_race(u->race)) {
switch (old_race(u_race(u))) {
case RC_SKELETON:
target_race = new_race[RC_SKELETON_LORD];
break;
@ -2711,7 +2711,7 @@ static int sp_unholypower(castorder * co)
if (u->number <= n) {
n -= u->number;
u->irace = NULL;
u->race = target_race;
u_setrace(u, target_race);
u->hp = unit_max_hp(u) * u->number - wounds;
ADDMSG(&r->msgs, msg_message("unholypower_effect",
"mage target race", mage, u, target_race));
@ -3013,7 +3013,7 @@ static int sp_summonshadowlords(castorder * co)
set_level(u, SK_PERCEPTION, 5);
ADDMSG(&mage->faction->msgs, msg_message("summon_effect", "mage amount race",
mage, amount, u->race));
mage, amount, u_race(u)));
return cast_level;
}
@ -3228,7 +3228,7 @@ static int sp_bloodsacrifice(castorder * co)
static void skill_summoned(unit * u, int level)
{
if (level > 0) {
const race *rc = u->race;
const race *rc = u_race(u);
skill_t sk;
for (sk = 0; sk != MAXSKILLS; ++sk) {
if (rc->bonus[sk] > 0) {
@ -3642,7 +3642,7 @@ static int sp_rallypeasantmob(castorder * co)
for (u = r->units; u; u = un) {
un = u->next;
if (is_monsters(u->faction) && u->race == new_race[RC_PEASANT]) {
if (is_monsters(u->faction) && u_race(u) == new_race[RC_PEASANT]) {
rsetpeasants(r, rpeasants(r) + u->number);
rsetmoney(r, rmoney(r) + get_money(u));
set_money(u, 0);
@ -3755,7 +3755,7 @@ static int sp_migranten(castorder * co)
target = pa->param[0]->data.u; /* Zieleinheit */
/* Personen unserer Rasse koennen problemlos normal uebergeben werden */
if (target->race == mage->faction->race) {
if (u_race(target) == mage->faction->race) {
/* u ist von unserer Art, das Ritual waere verschwendete Aura. */
ADDMSG(&mage->faction->msgs, msg_message("sp_migranten_fail1",
"unit region command target", mage, mage->region, co->order, target));
@ -3766,7 +3766,7 @@ static int sp_migranten(castorder * co)
}
/* Keine Monstereinheiten */
if (!playerrace(target->race)) {
if (!playerrace(u_race(target))) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail_nomonsters", ""));
return 0;
@ -4036,7 +4036,7 @@ static int sp_pump(castorder * co)
target = pa->param[0]->data.u; /* Zieleinheit */
if (fval(target->race, RCF_UNDEAD)) {
if (fval(u_race(target), RCF_UNDEAD)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"error_not_on_undead", ""));
return 0;
@ -4102,7 +4102,7 @@ static int sp_seduce(castorder * co)
target = pa->param[0]->data.u; /* Zieleinheit */
if (fval(target->race, RCF_UNDEAD)) {
if (fval(u_race(target), RCF_UNDEAD)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail_noundead", ""));
return 0;
@ -4179,7 +4179,7 @@ static int sp_calm_monster(castorder * co)
target = pa->param[0]->data.u; /* Zieleinheit */
if (fval(target->race, RCF_UNDEAD)) {
if (fval(u_race(target), RCF_UNDEAD)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail_noundead", ""));
return 0;
@ -4503,7 +4503,7 @@ int sp_illusionary_shapeshift(castorder * co)
return 0;
}
irace = u_irace(u);
if (irace == u->race) {
if (irace == u_race(u)) {
trigger *trestore = trigger_changerace(u, NULL, irace);
add_trigger(&u->attribs, "timer", trigger_timeout((int)power + 2,
trestore));
@ -4712,7 +4712,7 @@ int sp_dreamreading(castorder * co)
u = pa->param[0]->data.u;
/* Illusionen und Untote abfangen. */
if (fval(u->race, RCF_UNDEAD | RCF_ILLUSIONARY)) {
if (fval(u_race(u), RCF_UNDEAD | RCF_ILLUSIONARY)) {
ADDMSG(&mage->faction->msgs, msg_unitnotfound(mage, co->order,
pa->param[0]));
return 0;
@ -5521,7 +5521,7 @@ int sp_showastral(castorder * co)
region *r2 = rl2->data;
if (!is_cursed(r2->attribs, C_ASTRALBLOCK, 0)) {
for (u = r2->units; u; u = u->next) {
if (u->race != new_race[RC_SPECIAL] && u->race != new_race[RC_SPELL])
if (u_race(u) != new_race[RC_SPECIAL] && u_race(u) != new_race[RC_SPELL])
n++;
}
}
@ -5541,7 +5541,7 @@ int sp_showastral(castorder * co)
for (rl2 = rl; rl2; rl2 = rl2->next) {
if (!is_cursed(rl2->data->attribs, C_ASTRALBLOCK, 0)) {
for (u = rl2->data->units; u; u = u->next) {
if (u->race != new_race[RC_SPECIAL] && u->race != new_race[RC_SPELL]) {
if (u_race(u) != new_race[RC_SPECIAL] && u_race(u) != new_race[RC_SPELL]) {
c++;
scat(unitname(u));
scat(" (");
@ -5551,7 +5551,7 @@ int sp_showastral(castorder * co)
}
icat(u->number);
scat(" ");
scat(LOC(mage->faction->locale, rc_name(u->race, u->number != 1)));
scat(LOC(mage->faction->locale, rc_name(u_race(u), u->number != 1)));
scat(", Entfernung ");
icat(distance(rl2->data, rt));
scat(")");
@ -5681,7 +5681,7 @@ int sp_disruptastral(castorder * co)
if (trl != NULL) {
for (u = r2->units; u; u = u->next) {
if (u->race != new_race[RC_SPELL]) {
if (u_race(u) != new_race[RC_SPELL]) {
region_list *trl2 = trl;
region *tr;
int c = rng_int() % inhab_regions;