Feature #1001 » 0054-Optimize-maybe_become_veteran_real.patch
ai/default/daitools.c | ||
---|---|---|
}
|
||
/**********************************************************************//**
|
||
A helper function for ai_gothere. Estimates the dangers we will
|
||
A helper function for ai_gothere. Estimates the dangers we will
|
||
be facing at our destination and tries to find/request a bodyguard if
|
||
needed.
|
||
**************************************************************************/
|
||
... | ... | |
struct unit *guard = aiguard_guard_of(ait, punit);
|
||
const struct veteran_level *vlevel;
|
||
bool bg_needed = FALSE;
|
||
const struct unit_type *ptype;
|
||
if (is_barbarian(unit_owner(punit))) {
|
||
/* barbarians must have more courage (ie less brains) */
|
||
/* Barbarians must have more courage (ie less brains) */
|
||
aiguard_clear_guard(ait, punit);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
/* If we are fast, there is less danger.
|
||
* FIXME: that assumes that most units have move_rate == SINGLE_MOVE;
|
||
* not true for all rulesets */
|
||
danger /= (unit_type_get(punit)->move_rate / SINGLE_MOVE);
|
||
ptype = unit_type_get(punit);
|
||
danger /= (ptype->move_rate / SINGLE_MOVE);
|
||
if (unit_has_type_flag(punit, UTYF_IGTER)) {
|
||
danger /= 1.5;
|
||
}
|
||
vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
|
||
vlevel = utype_veteran_level(ptype, punit->veteran);
|
||
fc_assert_ret_val(vlevel != NULL, FALSE);
|
||
/* We look for the bodyguard where we stand. */
|
||
if (guard == NULL || unit_tile(guard) != unit_tile(punit)) {
|
||
int my_def = (punit->hp * unit_type_get(punit)->defense_strength
|
||
int my_def = (punit->hp * ptype->defense_strength
|
||
* POWER_FACTOR * vlevel->power_fact / 100);
|
||
if (danger >= my_def) {
|
common/actions.c | ||
---|---|---|
/* Veteran attack and defense bonus */
|
||
{
|
||
const struct veteran_level *vatt =
|
||
utype_veteran_level(unit_type_get(pattacker), pattacker->veteran);
|
||
const struct veteran_level *vdef =
|
||
utype_veteran_level(unit_type_get(pdefender), pdefender->veteran);
|
||
const struct veteran_level *vatt
|
||
= utype_veteran_level(unit_type_get(pattacker), pattacker->veteran);
|
||
const struct veteran_level *vdef
|
||
= utype_veteran_level(unit_type_get(pdefender), pdefender->veteran);
|
||
chance += vatt->power_fact - vdef->power_fact;
|
||
}
|
common/combat.c | ||
---|---|---|
int base_get_defense_power(const struct unit *punit)
|
||
{
|
||
const struct veteran_level *vlevel;
|
||
const struct unit_type *ptype;
|
||
fc_assert_ret_val(punit != NULL, 0);
|
||
vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
|
||
ptype = unit_type_get(punit);
|
||
vlevel = utype_veteran_level(ptype, punit->veteran);
|
||
fc_assert_ret_val(vlevel != NULL, 0);
|
||
return unit_type_get(punit)->defense_strength * POWER_FACTOR
|
||
return ptype->defense_strength * POWER_FACTOR
|
||
* vlevel->power_fact / 100;
|
||
}
|
||
common/unit.c | ||
---|---|---|
int get_activity_rate(const struct unit *punit)
|
||
{
|
||
const struct veteran_level *vlevel;
|
||
const struct unit_type *ptype;
|
||
int move_rate;
|
||
fc_assert_ret_val(punit != NULL, 0);
|
||
vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
|
||
ptype = unit_type_get(punit);
|
||
vlevel = utype_veteran_level(ptype, punit->veteran);
|
||
fc_assert_ret_val(vlevel != NULL, 0);
|
||
/* The speed of the settler depends on its base move_rate, not on
|
||
... | ... | |
* This means sea formers won't have their activity rate increased by
|
||
* Magellan's, and it means injured units work just as fast as
|
||
* uninjured ones. Note the value is never less than SINGLE_MOVE. */
|
||
int move_rate = unit_type_get(punit)->move_rate;
|
||
move_rate = ptype->move_rate;
|
||
/* All settler actions are multiplied by ACTIVITY_FACTOR. */
|
||
return ACTIVITY_FACTOR
|
common/unittype.c | ||
---|---|---|
return game.veteran;
|
||
}
|
||
/**********************************************************************//**
|
||
Return veteran level properties of given veterancy system
|
||
in given veterancy level.
|
||
**************************************************************************/
|
||
const struct veteran_level *
|
||
vsystem_veteran_level(const struct veteran_system *vsystem, int level)
|
||
{
|
||
fc_assert_ret_val(vsystem->definitions != NULL, NULL);
|
||
fc_assert_ret_val(vsystem->levels > level, NULL);
|
||
return (vsystem->definitions + level);
|
||
}
|
||
/**********************************************************************//**
|
||
Return veteran level properties of given unit in given veterancy level.
|
||
**************************************************************************/
|
||
... | ... | |
const struct veteran_system *vsystem = utype_veteran_system(punittype);
|
||
fc_assert_ret_val(vsystem != NULL, NULL);
|
||
fc_assert_ret_val(vsystem->definitions != NULL, NULL);
|
||
fc_assert_ret_val(vsystem->levels > level, NULL);
|
||
return (vsystem->definitions + level);
|
||
return vsystem_veteran_level(vsystem, level);
|
||
}
|
||
/**********************************************************************//**
|
||
... | ... | |
bool utype_veteran_has_power_bonus(const struct unit_type *punittype)
|
||
{
|
||
int i, initial_power_fact = utype_veteran_level(punittype, 0)->power_fact;
|
||
for (i = 1; i < utype_veteran_levels(punittype); i++) {
|
||
if (utype_veteran_level(punittype, i)->power_fact > initial_power_fact) {
|
||
return TRUE;
|
||
}
|
||
}
|
||
return FALSE;
|
||
}
|
||
common/unittype.h | ||
---|---|---|
const struct veteran_system *
|
||
utype_veteran_system(const struct unit_type *punittype);
|
||
int utype_veteran_levels(const struct unit_type *punittype);
|
||
const struct veteran_level *
|
||
vsystem_veteran_level(const struct veteran_system *vsystem, int level)
|
||
fc__attribute((nonnull (1)));
|
||
const struct veteran_level *
|
||
utype_veteran_level(const struct unit_type *punittype, int level);
|
||
const char *utype_veteran_name_translation(const struct unit_type *punittype,
|
server/diplomats.c | ||
---|---|---|
*vatt = utype_veteran_level(unit_type_get(pattacker), pattacker->veteran);
|
||
const struct veteran_level
|
||
*vdef = utype_veteran_level(unit_type_get(pdefender), pdefender->veteran);
|
||
fc_assert_ret_val(vatt != NULL && vdef != NULL, FALSE);
|
||
chance += vatt->power_fact - vdef->power_fact;
|
||
}
|
||
... | ... | |
{
|
||
int escapechance;
|
||
struct city *spyhome;
|
||
const struct unit_type *dipltype = unit_type_get(pdiplomat);
|
||
fc_assert(paction->actor.is_unit.moves_actor == MAK_ESCAPE);
|
||
... | ... | |
* unpromoted unit's power factor */
|
||
{
|
||
const struct veteran_level
|
||
*vunit = utype_veteran_level(unit_type_get(pdiplomat), pdiplomat->veteran);
|
||
*vunit = utype_veteran_level(dipltype, pdiplomat->veteran);
|
||
const struct veteran_level
|
||
*vbase = utype_veteran_level(unit_type_get(pdiplomat), 0);
|
||
*vbase = utype_veteran_level(dipltype, 0);
|
||
escapechance = game.server.diplchance
|
||
+ (vunit->power_fact - vbase->power_fact);
|
||
... | ... | |
FALSE, FALSE, TRUE, FALSE, NULL);
|
||
if (spyhome
|
||
&& !utype_is_consumed_by_action(paction, unit_type_get(pdiplomat))
|
||
&& !utype_is_consumed_by_action(paction, dipltype)
|
||
&& (unit_has_type_flag(pdiplomat, UTYF_SUPERSPY)
|
||
|| fc_rand (100) < escapechance)) {
|
||
/* Attacking Spy/Diplomat survives. */
|
||
... | ... | |
}
|
||
}
|
||
if (!utype_is_consumed_by_action(paction, unit_type_get(pdiplomat))) {
|
||
if (!utype_is_consumed_by_action(paction, dipltype)) {
|
||
/* The unit was caught, not spent. It must therefore be deleted by
|
||
* hand. */
|
||
wipe_unit(pdiplomat, ULR_CAUGHT, NULL);
|
server/edithand.c | ||
---|---|---|
if (packet->veteran != punit->veteran) {
|
||
int v = packet->veteran;
|
||
if (!utype_veteran_level(putype, v)) {
|
||
if (utype_veteran_level(putype, v) == NULL) {
|
||
notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
|
||
_("Invalid veteran level %d for unit %d (%s)."),
|
||
v, id, unit_link(punit));
|
server/unittools.c | ||
---|---|---|
fc_assert_ret_val(vsystem != NULL, FALSE);
|
||
fc_assert_ret_val(vsystem->levels > punit->veteran, FALSE);
|
||
vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
|
||
vlevel = vsystem_veteran_level(vsystem, punit->veteran);
|
||
fc_assert_ret_val(vlevel != NULL, FALSE);
|
||
if (punit->veteran + 1 >= vsystem->levels
|
||
... | ... | |
void notify_unit_experience(struct unit *punit)
|
||
{
|
||
const struct veteran_level *vlevel;
|
||
#ifndef FREECIV_NDEBUG
|
||
const struct veteran_system *vsystem;
|
||
#endif
|
||
if (!punit) {
|
||
return;
|
||
}
|
||
#ifndef FREECIV_NDEBUG
|
||
vsystem = utype_veteran_system(unit_type_get(punit));
|
||
fc_assert_ret(vsystem != NULL);
|
||
fc_assert_ret(vsystem->levels > punit->veteran);
|
||
#endif /* FREECIV_NDEBUG */
|
||
vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran);
|
||
vlevel = vsystem_veteran_level(vsystem, punit->veteran);
|
||
fc_assert_ret(vlevel != NULL);
|
||
notify_player(unit_owner(punit), unit_tile(punit),
|