From aa31d390544fdcfb0d51821b9f92654e2ded0ac7 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Thu, 17 Jan 2008 21:00:39 +0000 Subject: [PATCH] Fix bug in r3395 which made droids on the move explode when savegame was loaded. Also check movement parameters for droids stricter in debug mode. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3502 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/droid.h | 1 + src/game.c | 21 +++++++++++---------- src/move.c | 10 +++------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/droid.h b/src/droid.h index b18e4b54d..ae74e4b12 100644 --- a/src/droid.h +++ b/src/droid.h @@ -520,6 +520,7 @@ do { \ assert(droid->numWeaps <= DROID_MAXWEAPS); \ assert(droid->listSize <= ORDER_LIST_MAX); \ assert(droid->player < MAX_PLAYERS); \ + assert(worldOnMap(droid->sMove.fx, droid->sMove.fy)); \ \ for (i = 0; i < DROID_MAXWEAPS; ++i) \ assert(droid->turretRotation[i] <= 360); \ diff --git a/src/game.c b/src/game.c index 09e38e342..010df9263 100644 --- a/src/game.c +++ b/src/game.c @@ -5674,11 +5674,11 @@ static void SaveDroidMoveControl(SAVE_DROID * const psSaveDroid, DROID const * c psSaveDroid->sMove.targetY = PHYSFS_swapSLE32(psDroid->sMove.targetY); // Little endian floats - psSaveDroid->sMove.fx = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psDroid->sMove.fx); - psSaveDroid->sMove.fy = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psDroid->sMove.fy); - psSaveDroid->sMove.speed = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psDroid->sMove.speed); - psSaveDroid->sMove.moveDir = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psDroid->sMove.moveDir); - psSaveDroid->sMove.fz = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psDroid->sMove.fz); + psSaveDroid->sMove.fx = PHYSFS_swapSLE32(psDroid->sMove.fx); + psSaveDroid->sMove.fy = PHYSFS_swapSLE32(psDroid->sMove.fy); + psSaveDroid->sMove.speed = PHYSFS_swapSLE32(psDroid->sMove.speed); + psSaveDroid->sMove.moveDir = PHYSFS_swapSLE32(psDroid->sMove.moveDir); + psSaveDroid->sMove.fz = PHYSFS_swapSLE32(psDroid->sMove.fz); // Little endian SWORDs psSaveDroid->sMove.boundX = PHYSFS_swapSLE16(psDroid->sMove.boundX); @@ -5742,11 +5742,12 @@ static void LoadDroidMoveControl(DROID * const psDroid, SAVE_DROID const * const psDroid->sMove.targetY = PHYSFS_swapSLE32(psSaveDroid->sMove.targetY); // Little endian floats - psDroid->sMove.fx = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psSaveDroid->sMove.fx); - psDroid->sMove.fy = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psSaveDroid->sMove.fy); - psDroid->sMove.speed = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psSaveDroid->sMove.speed); - psDroid->sMove.moveDir = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psSaveDroid->sMove.moveDir); - psDroid->sMove.fz = PHYSFS_swapSLE32(*(uint32_t*)(void*)&psSaveDroid->sMove.fz); + psDroid->sMove.fx = PHYSFS_swapSLE32(psSaveDroid->sMove.fx); + psDroid->sMove.fy = PHYSFS_swapSLE32(psSaveDroid->sMove.fy); + psDroid->sMove.speed = PHYSFS_swapSLE32(psSaveDroid->sMove.speed); + psDroid->sMove.moveDir = PHYSFS_swapSLE32(psSaveDroid->sMove.moveDir); + psDroid->sMove.fz = PHYSFS_swapSLE32(psSaveDroid->sMove.fz); + assert(worldOnMap(psDroid->sMove.fx, psDroid->sMove.fy)); // Little endian SWORDs psDroid->sMove.boundX = PHYSFS_swapSLE16(psSaveDroid->sMove.boundX); diff --git a/src/move.c b/src/move.c index 34b6470e0..9293506ec 100644 --- a/src/move.c +++ b/src/move.c @@ -2332,15 +2332,11 @@ static void moveUpdateDroidPos( DROID *psDroid, float dx, float dy ) /* impact if about to go off map else update coordinates */ if ( worldOnMap( iX, iY ) == FALSE ) { - if ( psDroid->droidType == DROID_TRANSPORTER ) - { - /* transporter going off-world - trigger next map */ - - } - else + /* transporter going off-world will trigger next map, and is ok */ + ASSERT(psDroid->droidType == DROID_TRANSPORTER, "droid trying to move off the map!") + if (psDroid->droidType != DROID_TRANSPORTER) { /* dreadful last-ditch crash-avoiding hack - sort this! - GJ */ - debug(LOG_ERROR, "**** droid about to go off map - destroying it ****"); destroyDroid( psDroid ); return; }