eliminate R_PERSON hack.

This commit is contained in:
Enno Rehling 2017-03-05 11:25:17 +01:00
parent 5675ef6091
commit aa662e65d2
6 changed files with 38 additions and 7 deletions

View File

@ -6882,6 +6882,7 @@
<text locale="de">"$string"</text> <text locale="de">"$string"</text>
<text locale="en">"$string"</text> <text locale="en">"$string"</text>
</message> </message>
<message name="give_person" section="economy"> <message name="give_person" section="economy">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>
@ -6892,6 +6893,16 @@
<text locale="en">"$unit($unit) transfers $int($amount) person$if($eq($amount,1),"","s") to $unit($target)."</text> <text locale="en">"$unit($unit) transfers $int($amount) person$if($eq($amount,1),"","s") to $unit($target)."</text>
</message> </message>
<message name="receive_person" section="economy">
<type>
<arg name="unit" type="unit"/>
<arg name="amount" type="int"/>
<arg name="target" type="unit"/>
</type>
<text locale="de">"$unit($target) erhält $int($amount) Person$if($eq($amount,1),"","en") von $unit($unit)."</text>
<text locale="en">"$unit($target) receives $int($amount) person$if($eq($amount,1),"","s") from $unit($unit)."</text>
</message>
<message name="give" section="economy"> <message name="give" section="economy">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>
@ -6913,6 +6924,7 @@
<text locale="de">"$unit($target) erhält $int($amount) $resource($resource,$amount) von $unit($unit)."</text> <text locale="de">"$unit($target) erhält $int($amount) $resource($resource,$amount) von $unit($unit)."</text>
<text locale="en">"$unit($target) receives $int($amount) $resource($resource,$amount) from $unit($unit)."</text> <text locale="en">"$unit($target) receives $int($amount) $resource($resource,$amount) from $unit($unit)."</text>
</message> </message>
<message name="give_person_ocean" section="economy"> <message name="give_person_ocean" section="economy">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>

View File

@ -121,6 +121,28 @@ const resource_type * rtype, struct order *ord, int error)
} }
} }
static void add_give_person(unit * u, unit * u2, int given,
struct order *ord, int error)
{
assert(u2);
if (error) {
cmistake(u, ord, error, MSG_COMMERCE);
}
else if (u2->faction != u->faction) {
message *msg;
msg = msg_message("give_person", "unit target resource amount",
u, u2, given);
add_message(&u->faction->msgs, msg);
msg_release(msg);
msg = msg_message("receive_person", "unit target resource amount",
u, u2, given);
add_message(&u2->faction->msgs, msg);
msg_release(msg);
}
}
static bool limited_give(const item_type * type) static bool limited_give(const item_type * type)
{ {
/* trade only money 2:1, if at all */ /* trade only money 2:1, if at all */
@ -531,7 +553,7 @@ void give_unit(unit * u, unit * u2, order * ord)
cmistake(u, ord, 156, MSG_COMMERCE); cmistake(u, ord, 156, MSG_COMMERCE);
return; return;
} }
add_give(u, u2, u->number, u->number, get_resourcetype(R_PERSON), ord, 0); add_give_person(u, u2, u->number, ord, 0);
u_setfaction(u, u2->faction); u_setfaction(u, u2->faction);
u2->faction->newbies += u->number; u2->faction->newbies += u->number;
} }

View File

@ -83,6 +83,8 @@ static void test_give_unit(CuTest * tc) {
CuAssertPtrEquals(tc, env.f2, env.src->faction); CuAssertPtrEquals(tc, env.f2, env.src->faction);
CuAssertIntEquals(tc, 1, env.f2->newbies); CuAssertIntEquals(tc, 1, env.f2->newbies);
CuAssertPtrEquals(tc, 0, env.f1->units); CuAssertPtrEquals(tc, 0, env.f1->units);
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person"));
CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person"));
test_cleanup(); test_cleanup();
} }

View File

@ -622,7 +622,7 @@ const potion_type *oldpotiontype[MAX_POTIONS + 1];
static const char *resourcenames[MAX_RESOURCES] = { static const char *resourcenames[MAX_RESOURCES] = {
"money", "aura", "permaura", "money", "aura", "permaura",
"hp", "peasant", "person", "hp", "peasant",
"sapling", "mallornsapling", "sapling", "mallornsapling",
"tree", "mallorntree", "tree", "mallorntree",
"seed", "mallornseed", "seed", "mallornseed",
@ -982,8 +982,6 @@ void init_resources(void)
* which can be used in a construction recipe or as a spell ingredient. * which can be used in a construction recipe or as a spell ingredient.
*/ */
rt_get_or_create(resourcenames[R_PERSON]); /* lousy hack */
rtype = rt_get_or_create(resourcenames[R_PEASANT]); rtype = rt_get_or_create(resourcenames[R_PEASANT]);
rtype->uchange = res_changepeasants; rtype->uchange = res_changepeasants;

View File

@ -265,7 +265,6 @@ extern "C" {
R_PERMAURA, /* Permanente Aura */ R_PERMAURA, /* Permanente Aura */
R_LIFE, R_LIFE,
R_PEASANT, R_PEASANT,
R_PERSON,
R_SAPLING, R_SAPLING,
R_MALLORN_SAPLING, R_MALLORN_SAPLING,
R_TREE, R_TREE,

View File

@ -165,8 +165,6 @@ static void test_core_resources(CuTest *tc) {
CuAssertPtrNotNull(tc, rtype->itype->give); CuAssertPtrNotNull(tc, rtype->itype->give);
CuAssertPtrNotNull(tc, rtype = rt_find("peasant")); CuAssertPtrNotNull(tc, rtype = rt_find("peasant"));
CuAssertPtrEquals(tc, 0, rtype->itype); CuAssertPtrEquals(tc, 0, rtype->itype);
CuAssertPtrNotNull(tc, rtype = rt_find("person"));
CuAssertPtrEquals(tc, 0, rtype->itype);
CuAssertPtrNotNull(tc, rtype = rt_find("permaura")); CuAssertPtrNotNull(tc, rtype = rt_find("permaura"));
CuAssertPtrEquals(tc, 0, rtype->itype); CuAssertPtrEquals(tc, 0, rtype->itype);
CuAssertPtrNotNull(tc, rtype = rt_find("hp")); CuAssertPtrNotNull(tc, rtype = rt_find("hp"));