diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-28 14:50:40 +0200 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2020-05-01 12:36:28 +0200 |
commit | b949bad026c8bab7611998fb0fcf9f6008dbd7e9 (patch) | |
tree | bda7c10206612274a204b31412ae6999b8cc13b0 /core/equipment.c | |
parent | 0c28821d2895e246295884891df02e924eb8e359 (diff) | |
download | subsurface-b949bad026c8bab7611998fb0fcf9f6008dbd7e9.tar.gz |
core: always keep an empty cylinder at the end of the cylinder array
This will be temporarilly used by the planner to mark consumption of
air at the surface. Do this by creating a new function add_cylinder,
which replaces add_to_cylinder_table() and takes care of always adding
a dummy cylinder at the end of the table. Make the original
add_to_cylinder_table() local, so that it cannot be accessed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/equipment.c')
-rw-r--r-- | core/equipment.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/core/equipment.c b/core/equipment.c index 4be46ed1e..8d169d8d2 100644 --- a/core/equipment.c +++ b/core/equipment.c @@ -56,7 +56,7 @@ MAKE_CLEAR_TABLE(weightsystem_table, weightsystems, weightsystem) //static MAKE_GET_IDX(cylinder_table, cylinder_t, cylinders) static MAKE_GROW_TABLE(cylinder_table, cylinder_t, cylinders) //static MAKE_GET_INSERTION_INDEX(cylinder_table, cylinder_t, cylinders, cylinder_less_than) -MAKE_ADD_TO(cylinder_table, cylinder_t, cylinders) +static MAKE_ADD_TO(cylinder_table, cylinder_t, cylinders) MAKE_REMOVE_FROM(cylinder_table, cylinders) //MAKE_SORT(cylinder_table, cylinder_t, cylinders, comp_cylinders) //MAKE_REMOVE(cylinder_table, cylinder_t, cylinder) @@ -144,11 +144,23 @@ cylinder_t clone_cylinder(cylinder_t cyl) return res; } +void add_cylinder(struct cylinder_table *t, int idx, cylinder_t cyl) +{ + add_to_cylinder_table(t, idx, cyl); + /* FIXME: This is a horrible hack: we make sure that at the end of + * every single cylinder table there is an empty cylinder that can + * be used by the planner as "surface air" cylinder. Fix this. + */ + add_to_cylinder_table(t, t->nr, empty_cylinder); + t->nr--; + t->cylinders[t->nr].cylinder_use = NOT_USED; +} + /* Add a clone of a cylinder to the end of a cylinder table. * Cloned in means that the description-string is copied. */ void add_cloned_cylinder(struct cylinder_table *t, cylinder_t cyl) { - add_to_cylinder_table(t, t->nr, clone_cylinder(cyl)); + add_cylinder(t, t->nr, clone_cylinder(cyl)); } bool same_weightsystem(weightsystem_t w1, weightsystem_t w2) @@ -342,7 +354,7 @@ cylinder_t *add_empty_cylinder(struct cylinder_table *t) { cylinder_t cyl = empty_cylinder; cyl.type.description = strdup(""); - add_to_cylinder_table(t, t->nr, cyl); + add_cylinder(t, t->nr, cyl); return &t->cylinders[t->nr - 1]; } |