limit equipment names to 15 byte plus nul.

This commit is contained in:
Enno Rehling 2017-09-18 17:46:26 +02:00
parent 6ab35d80d0
commit e2f6ada862
4 changed files with 51 additions and 55 deletions

View File

@ -69,7 +69,7 @@
</set> </set>
<!-- equipment-sets for random encounters --> <!-- equipment-sets for random encounters -->
<set name="random_desert"> <set name="rand_desert">
<skill name="melee" level="d2"/> <skill name="melee" level="d2"/>
<skill name="trade" level="d3"/> <skill name="trade" level="d3"/>
<skill name="riding" level="d2+1"/> <skill name="riding" level="d2+1"/>
@ -79,53 +79,53 @@
<item name="money" amount="d30+19"/> <item name="money" amount="d30+19"/>
</set> </set>
<set name="random_swamp"> <set name="rand_swamp">
<skill name="stealth" level="d3+1"/> <skill name="stealth" level="d3+1"/>
<skill name="polearm" level="d3+1"/> <skill name="polearm" level="d3+1"/>
<item name="spear" amount="1"/> <item name="spear" amount="1"/>
<item name="money" amount="d20+9"/> <item name="money" amount="d20+9"/>
</set> </set>
<set name="random_glacier"> <set name="rand_glacier">
<skill name="armorer" level="d2+1"/> <skill name="armorer" level="d2+1"/>
<skill name="melee" level="d2+1"/> <skill name="melee" level="d2+1"/>
<item name="sword" amount="1"/> <item name="sword" amount="1"/>
<item name="money" amount="d20+19"/> <item name="money" amount="d20+19"/>
</set> </set>
<set name="random_mountain"> <set name="rand_mountain">
<skill name="armorer" level="d2+1"/> <skill name="armorer" level="d2+1"/>
<skill name="melee" level="d2+1"/> <skill name="melee" level="d2+1"/>
<skill name="trade" level="d3"/> <skill name="trade" level="d3"/>
<item name="sword" amount="1"/> <item name="sword" amount="1"/>
<item name="money" amount="d40+59"/> <item name="money" amount="d40+59"/>
<subset chance="0.6"> <subset chance="0.6">
<set name="item_plate"/> <set name="i_plate"/>
</subset> </subset>
</set> </set>
<set name="random_highland"> <set name="rand_highland">
<skill name="melee" level="d2"/> <skill name="melee" level="d2"/>
<item name="sword" amount="1"/> <item name="sword" amount="1"/>
<item name="money" amount="d10+19"/> <item name="money" amount="d10+19"/>
</set> </set>
<set name="random_forest"> <set name="rand_forest">
<skill name="stealth" level="d2"/> <skill name="stealth" level="d2"/>
<skill name="perception" level="d2+1"/> <skill name="perception" level="d2+1"/>
<skill name="bow" level="d3+1"/> <skill name="bow" level="d3+1"/>
<item name="bow" amount="1"/> <item name="bow" amount="1"/>
<item name="money" amount="d20+9"/> <item name="money" amount="d20+9"/>
<subset chance="0.2"> <subset chance="0.2">
<set name="random_herbalist"/> <set name="rand_herbalist"/>
</subset> </subset>
</set> </set>
<set name="random_herbalist"> <set name="rand_herbalist">
<skill name="herbalism" level="d2"/> <skill name="herbalism" level="d2"/>
</set> </set>
<set name="random_villagers"> <set name="rand_villagers">
<item name="money" amount="d80+19"/> <item name="money" amount="d80+19"/>
<skill name="cartmaking" level="d2-1"/> <skill name="cartmaking" level="d2-1"/>
<skill name="mining" level="d2-1"/> <skill name="mining" level="d2-1"/>
@ -136,43 +136,43 @@
<item name="money" amount="d30+10"/> <item name="money" amount="d30+10"/>
</set> </set>
<set name="random_plain"> <set name="rand_plain">
<item name="money" amount="d80+19"/> <item name="money" amount="d80+19"/>
<subset> <subset>
<set name="random_sword" chance="0.25"/> <set name="rand_sword" chance="0.25"/>
<set name="random_spear" chance="0.25"/> <set name="rand_spear" chance="0.25"/>
<set name="random_crossbow" chance="0.25"/> <set name="rand_crossbow" chance="0.25"/>
<set name="random_bow" chance="0.25"/> <set name="rand_bow" chance="0.25"/>
</subset> </subset>
<subset chance="0.4"> <subset chance="0.4">
<set name="item_chain"/> <set name="i_chain"/>
</subset> </subset>
<subset chance="0.3"> <subset chance="0.3">
<set name="random_rider"/> <set name="rand_rider"/>
</subset> </subset>
</set> </set>
<set name="random_spear"> <set name="rand_spear">
<skill name="polearm" level="d3"/> <skill name="polearm" level="d3"/>
<item name="spear" amount="1"/> <item name="spear" amount="1"/>
</set> </set>
<set name="random_sword"> <set name="rand_sword">
<skill name="melee" level="d3"/> <skill name="melee" level="d3"/>
<item name="sword" amount="1"/> <item name="sword" amount="1"/>
</set> </set>
<set name="random_crossbow"> <set name="rand_crossbow">
<skill name="crossbow" level="d3"/> <skill name="crossbow" level="d3"/>
<item name="crossbow" amount="1"/> <item name="crossbow" amount="1"/>
</set> </set>
<set name="random_bow"> <set name="rand_bow">
<skill name="bow" level="d3"/> <skill name="bow" level="d3"/>
<item name="bow" amount="1"/> <item name="bow" amount="1"/>
</set> </set>
<set name="random_rider"> <set name="rand_rider">
<item name="horse" amount="1"/> <item name="horse" amount="1"/>
<skill name="riding" level="d3"/> <skill name="riding" level="d3"/>
</set> </set>
@ -184,9 +184,9 @@
<skill name="bow" level="d3+1"/> <skill name="bow" level="d3+1"/>
<subset> <subset>
<!-- dracoiden haben immer eine von drei waffen --> <!-- dracoiden haben immer eine von drei waffen -->
<set name="item_sword" chance="0.33"/> <set name="i_sword" chance="0.33"/>
<set name="item_spear" chance="0.33"/> <set name="i_spear" chance="0.33"/>
<set name="item_bow" chance="0.34"/> <set name="i_bow" chance="0.34"/>
</subset> </subset>
</set> </set>
@ -195,38 +195,34 @@
<item name="rustysword" amount="1"/> <item name="rustysword" amount="1"/>
<item name="rustychainmail" amount="d2-1"/> <item name="rustychainmail" amount="d2-1"/>
<subset chance="0.3"> <subset chance="0.3">
<set name="item_rustyshield"/> <set name="i_rustyshield"/>
</subset> </subset>
</set> </set>
<!-- single-item sets (that can be given a percentage-chance in a subset) --> <!-- single-item sets (that can be given a percentage-chance in a subset) -->
<set name="item_plate"> <set name="i_plate">
<item name="plate" amount="1"/> <item name="plate" amount="1"/>
</set> </set>
<set name="item_spear"> <set name="i_spear">
<item name="spear" amount="1"/> <item name="spear" amount="1"/>
</set> </set>
<set name="item_bow"> <set name="i_bow">
<item name="bow" amount="1"/> <item name="bow" amount="1"/>
</set> </set>
<set name="item_sword"> <set name="i_sword">
<item name="sword" amount="1"/> <item name="sword" amount="1"/>
</set> </set>
<set name="item_chain"> <set name="i_chain">
<item name="chainmail" amount="1"/> <item name="chainmail" amount="1"/>
</set> </set>
<set name="item_log"> <set name="i_rustyshield">
<item name="log" amount="1"/> <item name="rustyshield" amount="1"/>
</set>
<set name="item_rustychain">
<item name="rustychainmail" amount="1"/>
</set> </set>
<set name="spo_dragon"> <set name="spo_dragon">

View File

@ -213,7 +213,7 @@ equipment *get_equipment(const char *eqname)
{ {
const char *match; const char *match;
assert(strlen(eqname) <= EQNAMELEN); assert(strlen(eqname) < EQNAMELEN);
match = cb_find_str(&cb_equipments, eqname); match = cb_find_str(&cb_equipments, eqname);
if (match) { if (match) {
@ -228,9 +228,9 @@ equipment *create_equipment(const char *eqname)
size_t len = strlen(eqname); size_t len = strlen(eqname);
eq_entry ent; eq_entry ent;
if (len > EQNAMELEN) { if (len >= EQNAMELEN) {
log_error("equipment names should be no longer than %d bytes: %s", EQNAMELEN, eqname); log_error("equipment names should be no longer than %d bytes: %s", EQNAMELEN-1, eqname);
len = EQNAMELEN; len = EQNAMELEN-1;
} }
memset(ent.key, 0, EQNAMELEN); memset(ent.key, 0, EQNAMELEN);
memcpy(ent.key, eqname, len); memcpy(ent.key, eqname, len);

View File

@ -51,21 +51,21 @@ static void test_get_equipment(CuTest * tc)
equipment * eq; equipment * eq;
test_setup(); test_setup();
eq = create_equipment("catapultammo"); eq = create_equipment("catapultammo123");
CuAssertPtrNotNull(tc, eq); CuAssertPtrNotNull(tc, eq);
CuAssertStrEquals(tc, "catapultammo", eq->name); CuAssertStrEquals(tc, "catapultammo123", eq->name);
eq = get_equipment("catapultammo"); eq = get_equipment("catapultammo123");
CuAssertPtrNotNull(tc, eq); CuAssertPtrNotNull(tc, eq);
CuAssertStrEquals(tc, "catapultammo", eq->name); CuAssertStrEquals(tc, "catapultammo123", eq->name);
eq = get_equipment("catapult"); eq = get_equipment("catapult");
CuAssertPtrEquals(tc, NULL, eq); CuAssertPtrEquals(tc, NULL, eq);
eq = create_equipment("catapult"); eq = create_equipment("catapult");
eq = get_equipment("catapult"); eq = get_equipment("catapult");
CuAssertPtrNotNull(tc, eq); CuAssertPtrNotNull(tc, eq);
CuAssertStrEquals(tc, "catapult", eq->name); CuAssertStrEquals(tc, "catapult", eq->name);
eq = get_equipment("catapultammo"); eq = get_equipment("catapultammo123");
CuAssertPtrNotNull(tc, eq); CuAssertPtrNotNull(tc, eq);
CuAssertStrEquals(tc, "catapultammo", eq->name); CuAssertStrEquals(tc, "catapultammo123", eq->name);
test_cleanup(); test_cleanup();
} }

View File

@ -263,7 +263,7 @@ static void get_villagers(region * r, unit * u)
u); u);
leave(newunit, true); leave(newunit, true);
fset(newunit, UFL_ISNEW | UFL_MOVED); fset(newunit, UFL_ISNEW | UFL_MOVED);
equip_unit(newunit, get_equipment("random_villagers")); equip_unit(newunit, get_equipment("rand_villagers"));
} }
static void get_allies(region * r, unit * u) static void get_allies(region * r, unit * u)
@ -282,7 +282,7 @@ static void get_allies(region * r, unit * u)
if (get_money(u) / u->number < 100 + rng_int() % 200) if (get_money(u) / u->number < 100 + rng_int() % 200)
return; return;
name = "random_plain_men"; name = "random_plain_men";
equip = "random_plain"; equip = "rand_plain";
number = rng_int() % 8 + 2; number = rng_int() % 8 + 2;
break; break;
} }
@ -293,7 +293,7 @@ static void get_allies(region * r, unit * u)
return; return;
} }
name = "random_forest_men"; name = "random_forest_men";
equip = "random_forest"; equip = "rand_forest";
number = rng_int() % 6 + 2; number = rng_int() % 6 + 2;
} }
break; break;
@ -303,7 +303,7 @@ static void get_allies(region * r, unit * u)
return; return;
} }
name = "random_swamp_men"; name = "random_swamp_men";
equip = "random_swamp"; equip = "rand_swamp";
number = rng_int() % 6 + 2; number = rng_int() % 6 + 2;
break; break;
@ -312,7 +312,7 @@ static void get_allies(region * r, unit * u)
return; return;
} }
name = "random_desert_men"; name = "random_desert_men";
equip = "random_desert"; equip = "rand_desert";
number = rng_int() % 12 + 2; number = rng_int() % 12 + 2;
break; break;
@ -321,7 +321,7 @@ static void get_allies(region * r, unit * u)
return; return;
} }
name = "random_highland_men"; name = "random_highland_men";
equip = "random_highland"; equip = "rand_highland";
number = rng_int() % 8 + 2; number = rng_int() % 8 + 2;
break; break;
@ -330,7 +330,7 @@ static void get_allies(region * r, unit * u)
return; return;
} }
name = "random_mountain_men"; name = "random_mountain_men";
equip = "random_mountain"; equip = "rand_mountain";
number = rng_int() % 6 + 2; number = rng_int() % 6 + 2;
break; break;
@ -339,7 +339,7 @@ static void get_allies(region * r, unit * u)
return; return;
} }
name = "random_glacier_men"; name = "random_glacier_men";
equip = "random_glacier"; equip = "rand_glacier";
number = rng_int() % 4 + 2; number = rng_int() % 4 + 2;
break; break;