Use ef_blank() when extending lost file, and simplify

This commit is contained in:
Markus Armbruster 2008-02-24 18:50:02 +01:00
parent 2da8d0c796
commit da2a0c5ef2

View file

@ -45,20 +45,12 @@ makelost(short type, natid owner, short id, coord x, coord y)
int n; int n;
n = findlost(type, owner, id, x, y, 1); n = findlost(type, owner, id, x, y, 1);
if (n < 0) { ef_blank(EF_LOST, n, &lost);
ef_extend(EF_LOST, 25);
n = findlost(type, owner, id, x, y, 1);
if (n < 0)
return;
}
getlost(n, &lost);
lost.lost_type = type; lost.lost_type = type;
lost.lost_owner = owner; lost.lost_owner = owner;
lost.lost_id = id; lost.lost_id = id;
lost.lost_x = x; lost.lost_x = x;
lost.lost_y = y; lost.lost_y = y;
lost.lost_uid = n;
time(&lost.lost_timestamp); time(&lost.lost_timestamp);
putlost(n, &lost); putlost(n, &lost);
} }
@ -82,8 +74,7 @@ makenotlost(short type, natid owner, short id, coord x, coord y)
/* /*
* Find a suitable slot in the lost file. * Find a suitable slot in the lost file.
* If a record for TYPE, OWNER, ID, X, Y exists, return its index. * If a record for TYPE, OWNER, ID, X, Y exists, return its index.
* Else if FREE is non-zero, return the index of an unused record if * Else if FREE is non-zero, return the index of an unused record.
* there is one.
* Else return -1. * Else return -1.
*/ */
static int static int
@ -94,19 +85,23 @@ findlost(short type, natid owner, short id, coord x, coord y, int free)
int freeslot = -1; int freeslot = -1;
for (n = 0; getlost(n, &lost); n++) { for (n = 0; getlost(n, &lost); n++) {
if (!lost.lost_owner && freeslot == -1 && free == 1) if (!lost.lost_owner && freeslot < 0)
freeslot = n; freeslot = n;
if (!lost.lost_owner) if (!lost.lost_owner)
continue; continue;
if (lost.lost_owner == owner && type == lost.lost_type) { if (lost.lost_owner == owner && type == lost.lost_type) {
if (type == EF_SECTOR && lost.lost_x == x && lost.lost_y == y) { if (type == EF_SECTOR && lost.lost_x == x && lost.lost_y == y)
freeslot = n; return n;
break; else if (lost.lost_id == id)
} else if (lost.lost_id == id) { return n;
freeslot = n;
break;
}
} }
} }
return freeslot;
if (free) {
if (freeslot < 0)
freeslot = n;
return freeslot;
}
return -1;
} }