Skip to content

Commit

Permalink
flying ships (#1048)
Browse files Browse the repository at this point in the history
* attempt fallback for bad encoding headers

* Fix levitation duration

Ship flag was persisted and somehow never cleared.
Resolves https://bugs.eressea.de/view.php?id=2997
  • Loading branch information
ennorehling authored Jan 7, 2024
1 parent efb7262 commit 3a131d5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
20 changes: 13 additions & 7 deletions process/accept-orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,20 @@ def write_part(outfile, part, sender):
payload = payload[3:]

if charset is None:
charset = "latin1"
try:
msg = payload.decode(charset, "ignore")
except:
msg = payload
charset = None
charsets = [ 'utf8', 'latin1' ]
else:
charsets = [ charset, 'utf8', 'latin1']
for cs in charsets:
try:
msg = payload.decode(cs)
break
except:
logger.debug("could not decode %s mesage from %s" % (cs, sender))
if not msg:
msg = payload.decode('utf8', 'ignore')

try:
utf8 = msg.encode("utf-8", "ignore")
utf8 = msg.encode("utf8", "ignore")
outfile.write(utf8)
except:
outfile.write(msg)
Expand Down
3 changes: 2 additions & 1 deletion scripts/tests/e2/e2features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ function test_levitate()
u:add_order("ARBEITE")
levitate_ship(u.ship, u, 2, 1)
assert_equal(32, u.ship.flags)
assert_not_nil(u.ship:get_curse('flyingship'))
process_orders()
assert_equal(0, u.ship.flags)
assert_nil(u.ship:get_curse('flyingship'))
end

function test_levitation_ring()
Expand Down
1 change: 1 addition & 0 deletions src/kernel/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ ship *read_ship(gamedata *data)

if (data->version >= FOSS_VERSION) {
READ_INT(store, &sh->flags);
sh->flags &= SFL_SAVEMASK;
}

/* Attribute rekursiv einlesen */
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct ship_type {
#define SF_FISHING (1<<4) /* was on an ocean, can fish */
#define SF_FLYING (1<<5) /* the ship can fly */

#define SFL_SAVEMASK (SF_FLYING)
#define SFL_SAVEMASK 0
#define INCOME_FISHING 10

typedef struct ship {
Expand Down
18 changes: 2 additions & 16 deletions src/spells/flyingship.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,13 @@ static int flyingship_read(gamedata * data, curse * c, void *target)
{
ship *sh = (ship *)target;
c->data.v = sh;
if (data->version < FOSS_VERSION) {
sh->flags |= SF_FLYING;
return 0;
}
assert(sh->flags & SF_FLYING);
return 0;
}

static int flyingship_age(curse * c)
{
ship *sh = (ship *)c->data.v;
if (sh && c->duration == 1) {
sh->flags &= ~SF_FLYING;
return 1;
}
sh->flags |= SF_FLYING;
return 0;
}

const struct curse_type ct_flyingship = { "flyingship",
CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read,
NULL, NULL, flyingship_age
NULL, NULL, NULL
};

void register_flyingship(void)
Expand Down
Binary file added tests/data/test.dat
Binary file not shown.

0 comments on commit 3a131d5

Please sign in to comment.