(ef_ensure_space): New.

(edit): Use it to to fix copying to virgin unit slot.  Closes #896475.
From Ron Koenderink.
This commit is contained in:
Markus Armbruster 2004-02-24 18:19:57 +00:00
parent 5233f7029f
commit c53438e7a0
3 changed files with 17 additions and 0 deletions

View file

@ -102,6 +102,7 @@ extern int ef_close(int);
extern int ef_flush(int);
extern int ef_write(int, int, caddr_t);
extern int ef_extend(int, int);
extern int ef_ensure_space(int, int, int);
extern void ef_zapcache(int);
extern int ef_nelem(int);
extern int ef_flags(int);

View file

@ -210,6 +210,8 @@ edit(void)
case 's':
if ((err = doship(thing[0], arg, ptr, &ship)) != RET_OK)
return err;
if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50))
return RET_FAIL;
if (!putship(ship.shp_uid, &ship))
return RET_FAIL;
break;
@ -217,6 +219,8 @@ edit(void)
if ((err = dounit(thing[0], arg, ptr, &land))
!= RET_OK)
return err;
if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
return RET_FAIL;
if (!putland(land.lnd_uid, &land))
return RET_FAIL;
break;
@ -224,6 +228,8 @@ edit(void)
if ((err = doplane(thing[0], arg, ptr, &plane))
!= RET_OK)
return err;
if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
return RET_FAIL;
if (!putplane(plane.pln_uid, &plane))
return RET_FAIL;
break;

View file

@ -474,3 +474,13 @@ ef_check(int type)
}
return 0;
}
int
ef_ensure_space(int type, int id, int count)
{
while (id >= empfile[type].fids) {
if (!ef_extend(type, count))
return 0;
}
return 1;
}