try and make coverity understand the equipment trie.

shorten names.
This commit is contained in:
Enno Rehling 2017-09-17 20:42:43 +02:00
parent 8e0bdbe428
commit 455e03fa05
12 changed files with 88 additions and 79 deletions

View File

@ -25,7 +25,7 @@
<item name="log" amount="10"/> <item name="log" amount="10"/>
<item name="stone" amount="4"/> <item name="stone" amount="4"/>
</set> </set>
<set name="autoseed_unit"> <set name="seed_unit">
<item name="log" amount="50"/> <item name="log" amount="50"/>
<item name="stone" amount="50"/> <item name="stone" amount="50"/>
<item name="iron" amount="50"/> <item name="iron" amount="50"/>
@ -38,7 +38,7 @@
<skill name="perception" level="30"/> <skill name="perception" level="30"/>
<skill name="melee" level="1"/> <skill name="melee" level="1"/>
</set> </set>
<set name="autoseed_faction"> <set name="seed_faction">
<item name="adamantium" amount="1"/> <item name="adamantium" amount="1"/>
</set> </set>
</equipment> </equipment>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<equipment> <equipment>
<set name="seaserpent_spoils"> <set name="spo_seaserpent">
<item name="dragonblood" amount="2"/> <item name="dragonblood" amount="2"/>
<item name="seaserpenthead" amount="1"/> <item name="seaserpenthead" amount="1"/>
</set> </set>

View File

@ -2,27 +2,27 @@
<equipment> <equipment>
<!-- equipment given to familiars --> <!-- equipment given to familiars -->
<set name="lynx_familiar"> <set name="fam_lynx">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
</set> </set>
<set name="tunnelworm_familiar"> <set name="fam_tunnelworm">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="mining" level="1"/> <skill name="mining" level="1"/>
<skill name="forestry" level="1"/> <skill name="forestry" level="1"/>
<skill name="stamina" level="1"/> <skill name="stamina" level="1"/>
</set> </set>
<set name="eagle_familiar"> <set name="fam_eagle">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
</set> </set>
<set name="rat_familiar"> <set name="fam_rat">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="stamina" level="6"/> <skill name="stamina" level="6"/>
</set> </set>
<set name="songdragon_familiar"> <set name="fam_songdragon">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="flee" level="2"/> <spell name="flee" level="2"/>
@ -30,7 +30,7 @@
<spell name="frighten" level="8"/> <spell name="frighten" level="8"/>
</set> </set>
<set name="nymph_familiar"> <set name="fam_nymph">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="bow" level="1"/> <skill name="bow" level="1"/>
<skill name="training" level="1"/> <skill name="training" level="1"/>
@ -42,7 +42,7 @@
<spell name="appeasement" level="1"/> <spell name="appeasement" level="1"/>
</set> </set>
<set name="unicorn_familiar"> <set name="fam_unicorn">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="resist_magic" level="3"/> <spell name="resist_magic" level="3"/>
@ -53,11 +53,11 @@
<spell name="appeasement" level="1"/> <spell name="appeasement" level="1"/>
</set> </set>
<set name="direwolf_familiar"> <set name="fam_direwolf">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
</set> </set>
<set name="ghost_familiar"> <set name="fam_ghost">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="steal_aura" level="6"/> <spell name="steal_aura" level="6"/>
@ -65,7 +65,7 @@
<spell name="summonundead" level="6"/> <spell name="summonundead" level="6"/>
</set> </set>
<set name="imp_familiar"> <set name="fam_imp">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="steal_aura" level="6"/> <spell name="steal_aura" level="6"/>
@ -73,14 +73,14 @@
<spell name="seduction" level="6"/> <spell name="seduction" level="6"/>
</set> </set>
<set name="dreamcat_familiar"> <set name="fam_dreamcat">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="shapeshift" level="3"/> <spell name="shapeshift" level="3"/>
<spell name="transferauratraum" level="3"/> <spell name="transferauratraum" level="3"/>
</set> </set>
<set name="fairy_familiar"> <set name="fam_fairy">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="appeasement" level="1"/> <spell name="appeasement" level="1"/>
@ -88,15 +88,15 @@
<spell name="seduction" level="6"/> <spell name="seduction" level="6"/>
</set> </set>
<set name="owl_familiar"> <set name="fam_owl">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
</set> </set>
<set name="hellcat_familiar"> <set name="fam_hellcat">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
</set> </set>
<set name="tiger_familiar"> <set name="fam_tiger">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
</set> </set>

View File

@ -2,18 +2,18 @@
<equipment> <equipment>
<!-- one equipment-set per player-race for the first unit in a faction --> <!-- one equipment-set per player-race for the first unit in a faction -->
<set name="autoseed_dwarf"> <set name="seed_dwarf">
<item name="axe" amount="1"/> <item name="axe" amount="1"/>
<item name="chainmail" amount="1"/> <item name="chainmail" amount="1"/>
<skill name="melee" level="1"/> <skill name="melee" level="1"/>
</set> </set>
<set name="autoseed_elf"> <set name="seed_elf">
<item name="fairyboot" amount="1"/> <item name="fairyboot" amount="1"/>
<callback name="equip_newunits"/> <callback name="equip_newunits"/>
</set> </set>
<set name="autoseed_orc"> <set name="seed_orc">
<skill name="polearm" level="4"/> <skill name="polearm" level="4"/>
<skill name="melee" level="4"/> <skill name="melee" level="4"/>
<skill name="crossbow" level="4"/> <skill name="crossbow" level="4"/>
@ -21,30 +21,30 @@
<skill name="bow" level="4"/> <skill name="bow" level="4"/>
</set> </set>
<set name="autoseed_goblin"> <set name="seed_goblin">
<item name="roi" amount="1"/> <item name="roi" amount="1"/>
<callback name="equip_newunits"/> <callback name="equip_newunits"/>
</set> </set>
<set name="autoseed_human"> <set name="seed_human">
<callback name="equip_newunits"/> <callback name="equip_newunits"/>
</set> </set>
<set name="autoseed_troll"> <set name="seed_troll">
<skill name="building" level="1"/> <skill name="building" level="1"/>
<skill name="perception" level="3"/> <skill name="perception" level="3"/>
<item name="stone" amount="50"/> <item name="stone" amount="50"/>
</set> </set>
<set name="autoseed_demon"> <set name="seed_demon">
<skill name="stamina" level="15"/> <skill name="stamina" level="15"/>
</set> </set>
<set name="autoseed_insect"> <set name="seed_insect">
<item name="nestwarmth" amount="9"/> <item name="nestwarmth" amount="9"/>
</set> </set>
<set name="autoseed_halfling"> <set name="seed_halfling">
<skill name="trade" level="1"/> <skill name="trade" level="1"/>
<skill name="riding" level="2"/> <skill name="riding" level="2"/>
<item name="horse" amount="2"/> <item name="horse" amount="2"/>
@ -58,12 +58,12 @@
<item name="incense" amount="5"/> <item name="incense" amount="5"/>
</set> </set>
<set name="autoseed_cat"> <set name="seed_cat">
<item name="roi" amount="1"/> <item name="roi" amount="1"/>
<callback name="equip_newunits"/> <callback name="equip_newunits"/>
</set> </set>
<set name="autoseed_aquarian"> <set name="seed_aquarian">
<skill name="sailing" level="1"/> <skill name="sailing" level="1"/>
<callback name="equip_newunits"/> <callback name="equip_newunits"/>
</set> </set>
@ -177,7 +177,7 @@
<skill name="riding" level="d3"/> <skill name="riding" level="d3"/>
</set> </set>
<set name="recruited_dracoid"> <set name="new_dracoid">
<!-- dracoiden, von drachen rekrutiert --> <!-- dracoiden, von drachen rekrutiert -->
<skill name="polearm" level="d4+2"/> <skill name="polearm" level="d4+2"/>
<skill name="melee" level="d4+2"/> <skill name="melee" level="d4+2"/>
@ -229,22 +229,22 @@
<item name="rustychainmail" amount="1"/> <item name="rustychainmail" amount="1"/>
</set> </set>
<set name="dragon_spoils"> <set name="spo_dragon">
<item name="dragonblood" amount="4"/> <item name="dragonblood" amount="4"/>
<item name="dragonhead" amount="1"/> <item name="dragonhead" amount="1"/>
</set> </set>
<set name="youngdragon_spoils"> <set name="spo_youngdragon">
<item name="dragonblood" amount="1"/> <item name="dragonblood" amount="1"/>
</set> </set>
<set name="wyrm_spoils"> <set name="spo_wyrm">
<item name="dragonblood" amount="10"/> <item name="dragonblood" amount="10"/>
<item name="dragonhead" amount="1"/> <item name="dragonhead" amount="1"/>
</set> </set>
<!-- sets that are used by the monster-spawning code --> <!-- sets that are used by the monster-spawning code -->
<set name="monster_dragon"> <set name="seed_dragon">
<skill name="magic" level="4"/> <skill name="magic" level="4"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
<skill name="stamina" level="1"/> <skill name="stamina" level="1"/>
@ -252,24 +252,24 @@
<item name="money" amount="d500+99"/> <item name="money" amount="d500+99"/>
</set> </set>
<set name="monster_braineater"> <set name="seed_braineater">
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>
<set name="monster_seaserpent"> <set name="seed_seaserpent">
<skill name="magic" level="4"/> <skill name="magic" level="4"/>
<skill name="stealth" level="2"/> <skill name="stealth" level="2"/>
<skill name="stamina" level="1"/> <skill name="stamina" level="1"/>
<skill name="perception" level="3"/> <skill name="perception" level="3"/>
</set> </set>
<set name="new_orc_unit"> <set name="new_orc">
<skill name="polearm" level="1"/> <skill name="polearm" level="1"/>
<skill name="melee" level="1"/> <skill name="melee" level="1"/>
</set> </set>
<set name="seaserpent_spoils"> <set name="spo_seaserpent">
<item name="dragonblood" amount="6"/> <item name="dragonblood" amount="6"/>
<item name="seaserpenthead" amount="1"/> <item name="seaserpenthead" amount="1"/>
</set> </set>

View File

@ -2,26 +2,26 @@
<equipment> <equipment>
<!-- equipment given to familiars --> <!-- equipment given to familiars -->
<set name="lynx_familiar"> <set name="fam_lynx">
<skill name="espionage" level="1"/> <skill name="espionage" level="1"/>
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>
<set name="tunnelworm_familiar"> <set name="fam_tunnelworm">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="mining" level="1"/> <skill name="mining" level="1"/>
<skill name="forestry" level="1"/> <skill name="forestry" level="1"/>
<skill name="stamina" level="1"/> <skill name="stamina" level="1"/>
</set> </set>
<set name="eagle_familiar"> <set name="fam_eagle">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>
<set name="rat_familiar"> <set name="fam_rat">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="espionage" level="1"/> <skill name="espionage" level="1"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
@ -29,7 +29,7 @@
<skill name="stamina" level="6"/> <skill name="stamina" level="6"/>
</set> </set>
<set name="songdragon_familiar"> <set name="fam_songdragon">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="flee" level="2"/> <spell name="flee" level="2"/>
@ -37,7 +37,7 @@
<spell name="frighten" level="8"/> <spell name="frighten" level="8"/>
</set> </set>
<set name="nymph_familiar"> <set name="fam_nymph">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="bow" level="1"/> <skill name="bow" level="1"/>
<skill name="herbalism" level="1"/> <skill name="herbalism" level="1"/>
@ -54,7 +54,7 @@
<spell name="appeasement" level="1"/> <spell name="appeasement" level="1"/>
</set> </set>
<set name="unicorn_familiar"> <set name="fam_unicorn">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
@ -67,12 +67,12 @@
<spell name="appeasement" level="1"/> <spell name="appeasement" level="1"/>
</set> </set>
<set name="direwolf_familiar"> <set name="fam_direwolf">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>
<set name="ghost_familiar"> <set name="fam_ghost">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="steal_aura" level="6"/> <spell name="steal_aura" level="6"/>
@ -80,7 +80,7 @@
<spell name="summonundead" level="6"/> <spell name="summonundead" level="6"/>
</set> </set>
<set name="imp_familiar"> <set name="fam_imp">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="espionage" level="1"/> <skill name="espionage" level="1"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
@ -92,7 +92,7 @@
<spell name="seduction" level="6"/> <spell name="seduction" level="6"/>
</set> </set>
<set name="dreamcat_familiar"> <set name="fam_dreamcat">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="espionage" level="1"/> <skill name="espionage" level="1"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
@ -103,7 +103,7 @@
<spell name="transferauratraum" level="3"/> <spell name="transferauratraum" level="3"/>
</set> </set>
<set name="fairy_familiar"> <set name="fam_fairy">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<!-- spells --> <!-- spells -->
<spell name="appeasement" level="1"/> <spell name="appeasement" level="1"/>
@ -111,19 +111,19 @@
<spell name="seduction" level="6"/> <spell name="seduction" level="6"/>
</set> </set>
<set name="owl_familiar"> <set name="fam_owl">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="espionage" level="1"/> <skill name="espionage" level="1"/>
<skill name="stealth" level="1"/> <skill name="stealth" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>
<set name="hellcat_familiar"> <set name="fam_hellcat">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>
<set name="tiger_familiar"> <set name="fam_tiger">
<skill name="magic" level="1"/> <skill name="magic" level="1"/>
<skill name="perception" level="1"/> <skill name="perception" level="1"/>
</set> </set>

View File

@ -65,9 +65,9 @@ local function seed(r, email, race, lang)
assert(f) assert(f)
local u = unit.create(f, r) local u = unit.create(f, r)
assert(u) assert(u)
equip_unit(u, "autoseed_faction") equip_unit(u, "seed_faction")
equip_unit(u, "autoseed_unit") equip_unit(u, "seed_unit")
equip_unit(u, "autoseed_" .. race, 7) equip_unit(u, "seed_" .. race, 7)
unit.create(f, r, 5):set_skill("mining", 30) unit.create(f, r, 5):set_skill("mining", 30)
unit.create(f, r, 5):set_skill("quarrying", 30) unit.create(f, r, 5):set_skill("quarrying", 30)
f:set_origin(r) f:set_origin(r)

View File

@ -927,7 +927,7 @@ void kill_troop(troop dt)
if (drops != NULL) { if (drops != NULL) {
i_merge(&du->items, &drops); i_merge(&du->items, &drops);
} }
sprintf(eqname, "%s_spoils", rc->_name); sprintf(eqname, "spo_%s", rc->_name);
eq = get_equipment(eqname); eq = get_equipment(eqname);
if (eq != NULL) { if (eq != NULL) {
equip_items(&du->items, eq); equip_items(&du->items, eq);

View File

@ -266,7 +266,6 @@ void add_recruits(unit * u, int number, int wanted)
strlcpy(equipment, "new_", sizeof(equipment)); strlcpy(equipment, "new_", sizeof(equipment));
strlcat(equipment, u_race(u)->_name, sizeof(equipment)); strlcat(equipment, u_race(u)->_name, sizeof(equipment));
strlcat(equipment, "_unit", sizeof(equipment));
equip_unit(unew, get_equipment(equipment)); equip_unit(unew, get_equipment(equipment));
if (unew != u) { if (unew != u) {

View File

@ -30,6 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <selist.h> #include <selist.h>
#include <critbit.h> #include <critbit.h>
#include <util/log.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
@ -202,31 +203,41 @@ void free_ls(void *arg) {
static critbit_tree cb_equipments = { 0 }; static critbit_tree cb_equipments = { 0 };
#define EQNAMELEN 16
typedef struct eq_entry {
char key[EQNAMELEN];
equipment *value;
} eq_entry;
equipment *get_equipment(const char *eqname) equipment *get_equipment(const char *eqname)
{ {
const char *match; const char *match;
equipment *eq = NULL;
assert(strlen(eqname) <= EQNAMELEN);
match = cb_find_str(&cb_equipments, eqname); match = cb_find_str(&cb_equipments, eqname);
if (match) { if (match) {
cb_get_kv(match, &eq, sizeof(eq)); eq_entry *ent = (eq_entry *)match;
return ent->value;
} }
return eq; return NULL;
} }
equipment *create_equipment(const char *eqname) equipment *create_equipment(const char *eqname)
{ {
equipment *eq; eq_entry ent;
size_t len;
char data[64];
eq = (equipment *)calloc(1, sizeof(equipment)); if (strlen(eqname) > EQNAMELEN) {
eq->name = strdup(eqname); log_error("equipment names should be no longer than %d bytes: %s", EQNAMELEN, eqname);
}
/* OBS: we require the nul-padding property of strncpy here, so do not use strlcpy: */
strncpy(ent.key, eqname, EQNAMELEN);
len = cb_new_kv(eqname, strlen(eqname), &eq, sizeof(eq), data); ent.value = (equipment *)calloc(1, sizeof(equipment));
assert(len <= sizeof(data)); ent.value->name = strdup(eqname);
cb_insert(&cb_equipments, data, len);
return eq; cb_insert(&cb_equipments, &ent, sizeof(ent));
return ent.value;
} }
equipment *get_or_create_equipment(const char *eqname) equipment *get_or_create_equipment(const char *eqname)
@ -258,10 +269,9 @@ static void free_equipment(equipment *eq) {
} }
static int free_equipment_cb(const void * match, const void * key, size_t keylen, void *cbdata) { static int free_equipment_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
equipment *eq; eq_entry * ent = (eq_entry *)match;
cb_get_kv(match, &eq, sizeof(eq)); free_equipment(ent->value);
free_equipment(eq); free(ent->value);
free(eq);
return 0; return 0;
} }

View File

@ -612,7 +612,7 @@ static void recruit_dracoids(unit * dragon, int size)
name_unit(un); name_unit(un);
change_money(dragon, -un->number * 50); change_money(dragon, -un->number * 50);
equip_unit(un, get_equipment("recruited_dracoid")); equip_unit(un, get_equipment("new_dracoid"));
setstatus(un, ST_FIGHT); setstatus(un, ST_FIGHT);
for (weapon = un->items; weapon; weapon = weapon->next) { for (weapon = un->items; weapon; weapon = weapon->next) {
@ -863,7 +863,7 @@ static int nrand(int start, int sub)
unit *spawn_seaserpent(region *r, faction *f) { unit *spawn_seaserpent(region *r, faction *f) {
unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL);
fset(u, UFL_ISNEW | UFL_MOVED); fset(u, UFL_ISNEW | UFL_MOVED);
equip_unit(u, get_equipment("monster_seaserpent")); equip_unit(u, get_equipment("seed_seaserpent"));
return u; return u;
} }
@ -894,7 +894,7 @@ void spawn_dragons(void)
u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL); u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL);
} }
fset(u, UFL_ISNEW | UFL_MOVED); fset(u, UFL_ISNEW | UFL_MOVED);
equip_unit(u, get_equipment("monster_dragon")); equip_unit(u, get_equipment("seed_dragon"));
log_debug("spawning %d %s in %s.\n", u->number, log_debug("spawning %d %s in %s.\n", u->number,
LOC(default_locale, LOC(default_locale,

View File

@ -519,7 +519,7 @@ static void make_familiar(unit * familiar, unit * mage)
const struct equipment *eq; const struct equipment *eq;
char eqname[64]; char eqname[64];
const race * rc = u_race(familiar); const race * rc = u_race(familiar);
snprintf(eqname, sizeof(eqname), "%s_familiar", rc->_name); snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name);
eq = get_equipment(eqname); eq = get_equipment(eqname);
if (eq != NULL) { if (eq != NULL) {
equip_items(&familiar->items, eq); equip_items(&familiar->items, eq);

View File

@ -160,7 +160,7 @@ void spawn_braineaters(float chance)
unit *u = unit *u =
create_unit(r, f0, 1 + rng_int() % 10 + rng_int() % 10, create_unit(r, f0, 1 + rng_int() % 10 + rng_int() % 10,
get_race(RC_HIRNTOETER), 0, NULL, NULL); get_race(RC_HIRNTOETER), 0, NULL, NULL);
equip_unit(u, get_equipment("monster_braineater")); equip_unit(u, get_equipment("seed_braineater"));
next = rng_int() % (int)(chance * 100); next = rng_int() % (int)(chance * 100);
} }