Fix scattering - the splitting code doesn't look right - it will

leave avg 1/2 the object's quantity on the scatter point.
Return count of how many objects actually left the scatter point.
This commit is contained in:
warwick
2002-09-09 05:44:32 +00:00
parent 53f40d2a20
commit 00671608d6
2 changed files with 10 additions and 14 deletions
+1 -1
View File
@@ -582,7 +582,7 @@ E long FDECL(rndexp, (BOOLEAN_P));
/* ### explode.c ### */ /* ### explode.c ### */
E void FDECL(explode, (int,int,int,int,CHAR_P,int)); E void FDECL(explode, (int,int,int,int,CHAR_P,int));
E void FDECL(scatter, (int, int, int, unsigned int, struct obj *)); E int FDECL(scatter, (int, int, int, unsigned int, struct obj *));
E void FDECL(splatter_burning_oil, (int, int)); E void FDECL(splatter_burning_oil, (int, int));
/* ### extralev.c ### */ /* ### extralev.c ### */
+9 -13
View File
@@ -400,7 +400,8 @@ struct scatter_chain {
* MAY_FRACTURE Stone objects can be fractured (statues, boulders) * MAY_FRACTURE Stone objects can be fractured (statues, boulders)
*/ */
void /* returns number of scattered objects */
int
scatter(sx,sy,blastforce,scflags, obj) scatter(sx,sy,blastforce,scflags, obj)
int sx,sy; /* location of objects to scatter */ int sx,sy; /* location of objects to scatter */
int blastforce; /* force behind the scattering */ int blastforce; /* force behind the scattering */
@@ -413,11 +414,11 @@ struct obj *obj; /* only scatter this obj */
uchar typ; uchar typ;
long qtmp; long qtmp;
boolean used_up; boolean used_up;
boolean split_up = FALSE;
boolean individual_object = obj ? TRUE : FALSE; boolean individual_object = obj ? TRUE : FALSE;
struct monst *mtmp; struct monst *mtmp;
struct scatter_chain *stmp, *stmp2 = 0; struct scatter_chain *stmp, *stmp2 = 0;
struct scatter_chain *schain = (struct scatter_chain *)0; struct scatter_chain *schain = (struct scatter_chain *)0;
int total = 0;
while ((otmp = individual_object ? obj : level.objects[sx][sy]) != 0) { while ((otmp = individual_object ? obj : level.objects[sx][sy]) != 0) {
if (otmp->quan > 1L) { if (otmp->quan > 1L) {
@@ -425,17 +426,8 @@ struct obj *obj; /* only scatter this obj */
if (qtmp > LARGEST_INT) qtmp = LARGEST_INT; if (qtmp > LARGEST_INT) qtmp = LARGEST_INT;
qtmp = (long)rnd((int)qtmp); qtmp = (long)rnd((int)qtmp);
otmp = splitobj(otmp, qtmp); otmp = splitobj(otmp, qtmp);
if (rn2(qtmp)) } else {
split_up = TRUE; obj = (struct obj *)0; /* all used */
else
split_up = FALSE;
} else
split_up = FALSE;
if (individual_object) {
if (split_up) {
obj = otmp;
} else
obj = (struct obj *)0;
} }
obj_extract_self(otmp); obj_extract_self(otmp);
used_up = FALSE; used_up = FALSE;
@@ -549,12 +541,16 @@ struct obj *obj; /* only scatter this obj */
stmp2 = stmp->next; stmp2 = stmp->next;
x = stmp->ox; y = stmp->oy; x = stmp->ox; y = stmp->oy;
if (stmp->obj) { if (stmp->obj) {
if ( x!=sx || y!=sy )
total += stmp->obj->quan;
place_object(stmp->obj, x, y); place_object(stmp->obj, x, y);
stackobj(stmp->obj); stackobj(stmp->obj);
} }
free((genericptr_t)stmp); free((genericptr_t)stmp);
newsym(x,y); newsym(x,y);
} }
return total;
} }