- vset, vmap and graph are obsolete

- LASTORDER define is dead
This commit is contained in:
Enno Rehling 2008-05-24 16:15:31 +00:00
parent 4793d0fd34
commit fec171d75f
22 changed files with 43 additions and 238 deletions

View File

@ -41,8 +41,6 @@
/* util includes */
#include <util/goodies.h>
#include <util/lists.h>
#include <util/vmap.h>
#include <util/vset.h>
/* libc includes */
#include <assert.h>

View File

@ -826,12 +826,6 @@ cr_output_unit(FILE * F, const region * r,
}
/* default commands */
fprintf(F, "COMMANDS\n");
#ifdef LASTORDER
if (u->lastorder) {
fwriteorder(F, u->lastorder, f->locale);
fputc('\n', F);
}
#else
for (ord = u->old_orders; ord; ord = ord->next) {
/* this new order will replace the old defaults */
if (is_persistent(ord)) {
@ -839,11 +833,7 @@ cr_output_unit(FILE * F, const region * r,
fputc('\n', F);
}
}
#endif
for (ord = u->orders; ord; ord = ord->next) {
#ifdef LASTORDER
if (ord==u->lastorder) continue;
#endif
if (u->old_orders && is_repeated(ord)) continue; /* unit has defaults */
if (is_persistent(ord)) {
fwriteorder(F, ord, f->locale);

View File

@ -157,9 +157,6 @@ restart_race(unit *u, const race * rc)
*ordp = ord->next;
ord->next = NULL;
if (u->thisorder == ord) set_order(&u->thisorder, NULL);
#ifdef LASTORDER
if (u->lastorder == ord) set_order(&u->lastorder, NULL);
#endif
} else {
ordp = &ord->next;
}
@ -3155,21 +3152,13 @@ setdefaults(unit *u)
/* Hungernde Einheiten führen NUR den default-Befehl aus */
set_order(&u->thisorder, default_order(u->faction->locale));
}
#ifdef LASTORDER
else {
/* by default the default long order becomes the new long order. */
u->thisorder = copy_order(u->lastorder);
}
#endif
/* check all orders for a potential new long order this round: */
for (ord = u->orders; ord; ord = ord->next) {
#ifndef LASTORDER
if (u->old_orders && is_repeated(ord)) {
/* this new order will replace the old defaults */
free_orders(&u->old_orders);
if (hunger) break;
}
#endif
if (hunger) continue;
if (is_exclusive(ord)) {
@ -3223,28 +3212,6 @@ setdefaults(unit *u)
/* fset(u, UFL_LONGACTION|UFL_NOTMOVING); */
set_order(&u->thisorder, NULL);
}
/* thisorder kopieren wir nun nach lastorder. in lastorder steht
* der DEFAULT befehl der einheit. da MOVE kein default werden
* darf, wird MOVE nicht in lastorder kopiert. MACHE TEMP wurde ja
* schon gar nicht erst in thisorder kopiert, so dass MACHE TEMP
* durch diesen code auch nicht zum default wird Ebenso soll BIETE
* nicht hierher, da i.A. die Einheit dann ja weg ist (und damit
* die Einheitsnummer ungueltig). Auch Attackiere sollte nie in
* den Default übernommen werden */
#ifdef LASTORDER
switch (get_keyword(u->thisorder)) {
case K_MOVE:
case K_ATTACK:
case K_WEREWOLF:
case NOKEYWORD:
/* these can never be default orders */
break;
default:
set_order(&u->lastorder, copy_order(u->thisorder));
}
#endif
}
static int
@ -3391,9 +3358,7 @@ defaultorders (void)
for (r=regions;r;r=r->next) {
unit *u;
for (u=r->units;u;u=u->next) {
#ifndef LASTORDER
boolean neworders = false;
#endif
order ** ordp = &u->orders;
while (*ordp!=NULL) {
order * ord = *ordp;
@ -3407,9 +3372,6 @@ defaultorders (void)
*ordp = ord->next;
ord->next = NULL;
free_order(ord);
#ifdef LASTORDER
if (new_order) set_order(&u->lastorder, new_order);
#else
if (!neworders) {
/* lange Befehle aus orders und old_orders löschen zu gunsten des neuen */
remove_exclusive(&u->orders);
@ -3418,7 +3380,6 @@ defaultorders (void)
ordp = &u->orders; /* we could have broken ordp */
}
if (new_order) addlist(&u->old_orders, new_order);
#endif
}
else ordp = &ord->next;
}

View File

@ -816,11 +816,7 @@ recruit_dracoids(unit * dragon, int size)
}
if (new_order!=NULL) {
#ifdef LASTORDER
set_order(&un->lastorder, new_order);
#else
addlist(&un->orders, new_order);
#endif
}
}
@ -1022,11 +1018,7 @@ plan_monsters(void)
}
if (long_order) {
set_order(&u->thisorder, copy_order(long_order));
#ifdef LASTORDER
set_order(&u->lastorder, copy_order(long_order));
#else
addlist(&u->orders, long_order);
#endif
}
}
}

View File

@ -676,9 +676,11 @@ volcano_outbreak(region *r)
unit *u, **up;
faction *f;
for (u=r->units; u; u=u->next) {
f = u->faction;
freset(f, FFL_SELECT);
for (f=NULL,u=r->units; u; u=u->next) {
if (f!=u->faction) {
f = u->faction;
freset(f, FFL_SELECT);
}
}
rn = rrandneighbour(r);

View File

@ -1452,7 +1452,6 @@ report_template(const char * filename, report_context * ctx, const char * charse
rps_nowrap(F, buf);
rnl(F);
#ifndef LASTORDER
for (ord = u->old_orders; ord; ord = ord->next) {
/* this new order will replace the old defaults */
strcpy(buf, " ");
@ -1460,7 +1459,6 @@ report_template(const char * filename, report_context * ctx, const char * charse
rps_nowrap(F, buf);
rnl(F);
}
#endif
for (ord = u->orders; ord; ord = ord->next) {
if (u->old_orders && is_repeated(ord)) continue; /* unit has defaults */
if (is_persistent(ord)) {
@ -1473,14 +1471,6 @@ report_template(const char * filename, report_context * ctx, const char * charse
/* If the lastorder begins with an @ it should have
* been printed in the loop before. */
#ifdef LASTORDER
if (u->lastorder && !is_persistent(u->lastorder)) {
strcpy(buf, " ");
write_order(u->lastorder, u->faction->locale, buf+2, sizeof(buf)-2);
rps_nowrap(F, buf);
rnl(F);
}
#endif
}
}
}

View File

@ -48,7 +48,6 @@
#include <util/parser.h>
#include <util/rand.h>
#include <util/rng.h>
#include <util/vset.h>
/* libc includes */
#include <assert.h>
@ -442,21 +441,23 @@ try_destruction(unit * u, unit * u2, const ship *sh, int skilldiff)
}
static void
sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
{
unit **ui;
unit **ui, *u;
region *safety = r;
int i;
direction_t d;
unsigned int index;
double probability = 0.0;
vset informed;
vset survivors;
message * sink_msg = NULL;
message * enemy_discovers_spy_msg = NULL;
faction * f;
vset_init(&informed);
vset_init(&survivors);
for (f=NULL,u=r->units;u;u=u->next) {
/* slight optimization to avoid dereferencing u->faction each time */
if (f!=u->faction) {
f = u->faction;
freset(f, FFL_SELECT);
}
}
/* figure out what a unit's chances of survival are: */
if (!fval(r->terrain, SEA_REGION)) {
@ -475,7 +476,14 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
unit *u = *ui;
/* inform this faction about the sinking ship: */
vset_add(&informed, u->faction);
if (!fval(u->faction, FFL_SELECT)) {
fset(u->faction, FFL_SELECT);
if (sink_msg==NULL) {
sink_msg = msg_message("sink_msg", "ship region", sh, r);
}
add_message(&f->msgs, sink_msg);
}
if (u->ship == sh) {
int dead = 0;
message * msg;
@ -485,10 +493,8 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
if (chance(probability))
++dead;
if (dead != u->number)
if (dead != u->number) {
/* she will live. but her items get stripped */
{
vset_add(&survivors, u);
if (dead > 0) {
msg = msg_message("sink_lost_msg", "dead region unit", dead, safety, u);
} else {
@ -516,59 +522,9 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
}
}
}
/* inform everyone, and reduce money to the absolutely necessary
* amount: */
while (informed.size != 0) {
unit *lastunit = 0;
int money = 0, maintain = 0;
faction * f = (faction *) informed.data[0];
/* find out how much money this faction still has: */
for (index = 0; index != survivors.size; ++index) {
unit *u = (unit *) survivors.data[index];
if (u->faction == f) {
maintain += maintenance_cost(u);
money += get_money(u);
lastunit = u;
}
}
/* 'money' shall be the maintenance-surplus of the survivng
* units: */
money = money - maintain;
for (index = 0; money > 0; ++index) {
int remove;
unit *u = (unit *) survivors.data[index];
assert(index < survivors.size);
if (u->faction == f && playerrace(u->race)) {
remove = min(get_money(u), money);
money -= remove;
change_money(u, -remove);
}
}
/* finally, report to this faction that the ship sank: */
if (sink_msg==NULL) {
sink_msg = msg_message("sink_msg", "ship region", sh, r);
}
add_message(&f->msgs, sink_msg);
vset_erase(&informed, f);
if (spy == 1 && f != saboteur->faction && faction_skill(r, f, SK_PERCEPTION) - eff_skill(saboteur, SK_STEALTH, r) > 0) {
/* the unit is discovered */
ADDMSG(&f->msgs, msg_message("spy_discovered_msg", "unit saboteur ship", lastunit, saboteur, sh));
if (enemy_discovers_spy_msg==NULL) {
enemy_discovers_spy_msg = msg_message("enemy_discovers_spy_msg", "unit ship", saboteur, sh);
}
add_message(&saboteur->faction->msgs, sink_msg);
}
}
if (enemy_discovers_spy_msg) msg_release(enemy_discovers_spy_msg);
if (sink_msg) msg_release(sink_msg);
/* finally, get rid of the ship */
remove_ship(&sh->region->ships, sh);
vset_destroy(&informed);
vset_destroy(&survivors);
}
int
@ -598,7 +554,7 @@ sabotage_cmd(unit * u, struct order * ord)
u2 = shipowner(sh);
skdiff = eff_skill(u, SK_SPY, r)-crew_skill(r, u2->faction, sh, SK_PERCEPTION);
if (try_destruction(u, u2, sh, skdiff)) {
sink_ship(r, sh, buffer, 1, u);
sink_ship(r, sh, buffer, u);
}
break;
default:

View File

@ -437,12 +437,8 @@ teach_cmd(unit * u, struct order * ord)
teaching -= teach_unit(u, u2, teaching, sk, false, &academy);
}
new_order = create_order(K_TEACH, u->faction->locale, "%s", zOrder);
#ifdef LASTORDER
set_order(&u->lastorder, new_order);
#else
replace_order(&u->orders, ord, new_order);
free_order(new_order); /* parse_order & set_order have each increased the refcount */
#endif
}
if (academy && sk!=NOSKILL) {
academy = academy/30; /* anzahl gelehrter wochen, max. 10 */

View File

@ -942,12 +942,8 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
}
if (new_order) {
#ifdef LASTORDER
set_order(&u->lastorder, new_order);
#else
replace_order(&u->orders, ord, new_order);
free_order(new_order);
#endif
}
b->size += built;
@ -1031,12 +1027,8 @@ create_ship(region * r, unit * u, const struct ship_type * newtype, int want, or
}
fset(u, UFL_OWNER);
new_order = create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale, parameters[P_SHIP]), sh->no);
#ifdef LASTORDER
set_order(&u->lastorder, new_order);
#else
replace_order(&u->orders, ord, new_order);
free_order(new_order);
#endif
build_ship(u, sh, want);
}

View File

@ -2459,9 +2459,6 @@ weight(const unit * u)
void
make_undead_unit(unit * u)
{
#ifdef LASTORDER
set_order(&u->lastorder, NULL);
#endif
free_orders(&u->orders);
name_unit(u);
fset(u, UFL_ISNEW);

View File

@ -43,7 +43,7 @@ typedef struct shortpwd {
#define FFL_NOAID (1<<21) /* Hilfsflag Kampf */
#define FFL_MARK (1<<23) /* für markierende algorithmen, die das
* hinterher auch wieder löschen müssen!
* (FL_DH muss man vorher initialisieren,
* (FFL_SELECT muss man vorher initialisieren,
* FL_MARK hinterher löschen) */
#define FFL_NOIDLEOUT (1<<24) /* Partei stirbt nicht an NMRs */
#define FFL_OVERRIDE (1<<27) /* Override-Passwort wurde benutzt */

View File

@ -1016,12 +1016,8 @@ cycle_route(order * ord, unit *u, int gereist)
strcat(neworder, tail);
norder = create_order(K_ROUTE, u->faction->locale, "%s", neworder);
#ifdef LASTORDER
set_order(&u->lastorder, norder);
#else
replace_order(&u->orders, ord, norder);
free_order(norder);
#endif
}
static boolean

View File

@ -532,12 +532,6 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
}
}
}
#ifdef LASTORDER
if (!isbattle && u->lastorder) {
bytes = buforder(bufp, size, u->lastorder, 0);
if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER();
}
#else
if (!isbattle) {
boolean printed = 0;
order * ord;;
@ -558,7 +552,6 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char * buf, siz
}
}
}
#endif
}
i = 0;

View File

@ -619,30 +619,16 @@ write_items(struct storage * store, item *ilist)
int
lastturn(void)
{
char zText[MAX_PATH];
int turn = 0;
#ifdef HAVE_READDIR
DIR *data_dir = NULL;
struct dirent *entry = NULL;
const char * dir = datapath();
data_dir = opendir(dir);
if (data_dir != NULL) {
entry = readdir(data_dir);
FILE * f;
sprintf(zText, "%s/turn", basepath());
f = cfopen(zText, "r");
if (f) {
fscanf(f, "%d\n", &turn);
fclose(f);
}
if (data_dir != NULL && entry != NULL) {
turn = 0;
do {
int i = atoi(entry->d_name);
if (i > turn)
turn = i;
entry = readdir(data_dir);
} while (entry != NULL);
#ifdef HAVE_CLOSEDIR
closedir(data_dir);
#endif
}
#else
# error "requires dirent.h or an equivalent to compile!"
#endif
return turn;
}
@ -800,11 +786,7 @@ readunit(struct storage * store)
store->r_str_buf(store, obuf, sizeof(obuf));
ord = parse_order(obuf, u->faction->locale);
if (ord!=NULL) {
#ifdef LASTORDER
set_order(&u->lastorder, ord);
#else
addlist(&u->orders, ord);
#endif
}
}
set_order(&u->thisorder, NULL);
@ -866,7 +848,6 @@ writeunit(struct storage * store, const unit * u)
store->w_int(store, u->status);
store->w_int(store, u->flags & UFL_SAVEMASK);
store->w_brk(store);
#ifndef LASTORDER
for (ord = u->old_orders; ord; ord=ord->next) {
if (++p<MAXPERSISTENT) {
writeorder(store, ord, u->faction->locale);
@ -875,7 +856,6 @@ writeunit(struct storage * store, const unit * u)
break;
}
}
#endif
for (ord = u->orders; ord; ord=ord->next) {
if (u->old_orders && is_repeated(ord)) continue; /* has new defaults */
if (is_persistent(ord)) {

View File

@ -1017,9 +1017,6 @@ u_setfaction(unit * u, faction * f)
join_group(u, NULL);
free_orders(&u->orders);
set_order(&u->thisorder, NULL);
#ifdef LASTORDER
set_order(&u->lastorder, NULL);
#endif
iunit = &u->faction->units;
while (*iunit && *iunit!=u) {
@ -1409,11 +1406,7 @@ create_unit(region * r, faction * f, int number, const struct race *urace, int i
assert(f->alive);
u_setfaction(u, f);
set_order(&u->thisorder, NULL);
#ifdef LASTORDER
set_order(&u->lastorder, deford);
#else
addlist(&u->orders, deford);
#endif
u_seteffstealth(u, -1);
u->race = urace;
u->irace = urace;

View File

@ -96,11 +96,7 @@ typedef struct unit {
/* orders */
struct order * orders;
struct order * thisorder;
#ifdef LASTORDER
struct order * lastorder;
#else
struct order * old_orders;
#endif
/* race and illusionary race */
const struct race * race;

View File

@ -345,9 +345,6 @@ guardian_faction(plane * pl, int id)
set_string(&u->name, "Igjarjuks Auge");
set_item(u, I_RING_OF_INVISIBILITY, 1);
set_order(&u->thisorder, NULL);
#ifdef LASTORDER
set_order(&u->lastorder, NULL);
#endif
fset(u, UFL_PARTEITARNUNG);
set_money(u, 1000);
}

View File

@ -19,14 +19,12 @@ SOURCES =
filereader.c
functions.c
goodies.c
graph.c
language.c
lists.c
log.c
message.c
nrmessage.c
parser.c
patricia.c
rand.c
resolve.c
sql.c
@ -34,9 +32,6 @@ SOURCES =
translation.c
umlaut.c
unicode.c
vmap.c
vset.c
windir.c
xml.c
;

View File

@ -102,8 +102,6 @@ extern "C" {
#endif
#ifdef WIN32
# include <common/util/windir.h>
# define HAVE_READDIR
# define HAVE__MKDIR_WITHOUT_PERMISSION
# define HAVE__SLEEP_MSEC
#endif
@ -116,9 +114,6 @@ extern "C" {
# define HAVE_ACCESS
# define HAVE_STAT
typedef struct stat stat_type;
# include <dirent.h>
# define HAVE_READDIR
# define HAVE_OPENDIR
# include <string.h>
# define HAVE_STRDUP
# define HAVE_SNPRINTF

View File

@ -68,7 +68,6 @@
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/cvector.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
@ -77,7 +76,6 @@
#include <util/resolve.h>
#include <util/rng.h>
#include <util/sql.h>
#include <util/vset.h>
/* libc includes */
#include <stdio.h>

View File

@ -114,25 +114,14 @@ package.path = "eressea"
package.includepaths = { "..", "../common" }
package.files = { "gmtool.h", "gmtool.c", "editing.c", "editing.h", "curses/listbox.h", "curses/listbox.c", "lua/gm.cpp" }
for k,v in project.configs do
package.config[v].objdir = v
package.config[v].bindir = v
package.config[v].objdir = v .. "/" .. package.name
package.config[v].libdir = v .. "/" .. package.name
table.insert(package.config[v].buildflags, "extra-warnings")
table.insert(package.config[v].buildflags, "no-debug-runtime")
table.insert(package.config[v].buildflags, "singlethread-runtime")
for index, name in c_defines do
table.insert(package.config[v].defines, name)
end
if (windows) then
if target=="vs2005" then
if v=="Debug" then
package.config[v].links = { "lua5.1_d", "luabind_d" }
else
package.config[v].links = { "lua5.1", "luabind" }
end
else
package.config[v].links = { "lua50", "luabind" }
end
end
if v~="Debug" then
table.insert(package.config[v].defines, "NDEBUG")
end

View File

@ -58,13 +58,13 @@ end
function test_realloc()
local t1 = os.clock()
read_game("571.dat.2", "binary")
read_game("571.4.dat", "binary")
print(os.clock() - t1)
free_game()
print(os.clock() - t1)
-- and again
local t2 = os.clock()
read_game("571.dat.2", "binary")
read_game("571.4.dat", "binary")
print(os.clock() - t2)
free_game()
print(os.clock() - t2)
@ -79,14 +79,13 @@ end
loadscript("default.lua")
run_scripts()
-- go
local now = os.clock()
-- test_free()
test_bmark()
-- test_bmark()
test_realloc()
-- test_hse()
-- test_realloc()
local elapsed = os.clock() - now
print(elapsed)
io.stdin:read("*line")
-- text: 50.574
-- bin0: 19.547
-- bin1: 18.953
-- io.stdin:read("*line")
-- bin1: 18.313
-- bin2: 17.938