fixing new GIVE

This commit is contained in:
Enno Rehling 2009-10-03 16:54:25 +00:00
parent 51489e305b
commit 3bd0883298
3 changed files with 28 additions and 10 deletions

View File

@ -1124,7 +1124,7 @@ cr_region_header(FILE * F, int plid, int nx, int ny, unsigned int uid)
} else { } else {
fprintf(F, "REGION %d %d %d\n", nx, ny, plid); fprintf(F, "REGION %d %d %d\n", nx, ny, plid);
} }
fprintf(F, "%d;id\n", uid); if (uid) fprintf(F, "%d;id\n", uid);
} }
static void static void
@ -1136,6 +1136,11 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
int plid = plane_id(pl), nx, ny; int plid = plane_id(pl), nx, ny;
const char * tname; const char * tname;
int oc[4][2], o = 0; int oc[4][2], o = 0;
int uid = r->uid;
if (sr->mode<=see_neighbour && !r->land) {
uid = 0;
}
if (opt_cr_absolute_coords) { if (opt_cr_absolute_coords) {
nx = r->x; nx = r->x;
@ -1165,11 +1170,11 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
} }
} }
while (o--) { while (o--) {
cr_region_header(F, plid, oc[o][0], oc[o][1], r->uid); cr_region_header(F, plid, oc[o][0], oc[o][1], uid);
fputs("\"wrap\";visibility\n", F); fputs("\"wrap\";visibility\n", F);
} }
cr_region_header(F, plid, nx, ny, r->uid); cr_region_header(F, plid, nx, ny, uid);
if (r->land) { if (r->land) {
const char * str = rname(r, f->locale); const char * str = rname(r, f->locale);

View File

@ -139,20 +139,21 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, struct ord
int use = use_pooled(src, item2resource(itype), GET_SLACK, n); int use = use_pooled(src, item2resource(itype), GET_SLACK, n);
if (use<n) use += use_pooled(src, item2resource(itype), GET_RESERVE|GET_POOLED_SLACK, n-use); if (use<n) use += use_pooled(src, item2resource(itype), GET_RESERVE|GET_POOLED_SLACK, n-use);
if (dest) { if (dest) {
i_change(&dest->items, itype, n); int q = give_quota(src, dest, itype, n);
i_change(&dest->items, itype, q);
#ifdef RESERVE_GIVE #ifdef RESERVE_GIVE
#ifdef RESERVE_DONATIONS #ifdef RESERVE_DONATIONS
change_reservation(dest, item2resource(itype), n); change_reservation(dest, item2resource(itype), q);
#else #else
if (src->faction==dest->faction) { if (src->faction==dest->faction) {
change_reservation(dest, item2resource(itype), n); change_reservation(dest, item2resource(itype), q);
} }
#endif #endif
#endif #endif
#if MUSEUM_MODULE && defined(TODO) #if MUSEUM_MODULE && defined(TODO)
/* TODO: use a trigger for the museum warden! */ /* TODO: use a trigger for the museum warden! */
if (a_find(dest->attribs, &at_warden)) { if (a_find(dest->attribs, &at_warden)) {
warden_add_give(src, dest, itype, n); warden_add_give(src, dest, itype, q);
} }
#endif #endif
handle_event(dest->attribs, "receive", src); handle_event(dest->attribs, "receive", src);

View File

@ -727,13 +727,25 @@ end
function test_give() function test_give()
free_game() free_game()
local u1, u2 = two_units(region.create(0, 0, "plain"), two_factions()) local u1, u2 = two_units(region.create(0, 0, "plain"), two_factions())
u1:clear_orders() u1.faction.age = 10
u2.faction.age = 10
u1:add_item("money", 500) u1:add_item("money", 500)
local m1, m2 = u1:get_item("money"), u2:get_item("money") local m1, m2 = u1:get_item("money"), u2:get_item("money")
u1:add_order("GIB " .. itoa36(u2.no) .. " 332 Silber") u1:clear_orders()
u1:add_order("GIB " .. itoa36(u2.id) .. " 332 Silber")
u2:clear_orders()
u2:add_order("LERNEN Hiebwaffen")
process_orders()
assert(u1:get_item("money")==m1-10*u1.number)
assert(u2:get_item("money")==m2-10*u2.number)
m1, m2 = u1:get_item("money"), u2:get_item("money")
u1:clear_orders()
u1:add_order("GIB " .. itoa36(u2.id) .. " 332 Silber")
u2:clear_orders()
u2:add_order("HELFE " .. itoa36(u1.faction.id) .. " GIB")
process_orders() process_orders()
assert(u1:get_item("money")==m1-332-10*u1.number) assert(u1:get_item("money")==m1-332-10*u1.number)
print(u2:get_item("money"), m2)
assert(u2:get_item("money")==m2+110-10*u2.number) assert(u2:get_item("money")==m2+110-10*u2.number)
end end