You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(48) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(11) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(3) |
Oct
(16) |
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
|
Sep
(109) |
Oct
(39) |
Nov
(3) |
Dec
(45) |
2007 |
Jan
(12) |
Feb
(11) |
Mar
(1) |
Apr
(22) |
May
(1) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2009 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(4) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(5) |
Jun
(12) |
Jul
(64) |
Aug
(49) |
Sep
(52) |
Oct
(58) |
Nov
(48) |
Dec
(7) |
2011 |
Jan
(1) |
Feb
(1) |
Mar
(8) |
Apr
(12) |
May
(26) |
Jun
(61) |
Jul
(96) |
Aug
(7) |
Sep
(12) |
Oct
(16) |
Nov
(2) |
Dec
(16) |
2012 |
Jan
(4) |
Feb
(9) |
Mar
(40) |
Apr
(20) |
May
(16) |
Jun
(6) |
Jul
(9) |
Aug
|
Sep
(23) |
Oct
|
Nov
(3) |
Dec
(4) |
2013 |
Jan
(9) |
Feb
(14) |
Mar
(30) |
Apr
(27) |
May
(10) |
Jun
(18) |
Jul
(13) |
Aug
(5) |
Sep
(1) |
Oct
(3) |
Nov
(2) |
Dec
|
2014 |
Jan
(3) |
Feb
|
Mar
(3) |
Apr
(1) |
May
(2) |
Jun
(4) |
Jul
(8) |
Aug
(3) |
Sep
(4) |
Oct
(1) |
Nov
|
Dec
|
2015 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(3) |
Nov
(3) |
Dec
|
2016 |
Jan
(1) |
Feb
(5) |
Mar
(1) |
Apr
(5) |
May
(5) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(1) |
Dec
|
2017 |
Jan
(2) |
Feb
(1) |
Mar
(2) |
Apr
(2) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: <be...@us...> - 2022-10-22 05:51:52
|
Revision: 1030 http://sourceforge.net/p/freesynd/code/1030 Author: benblan Date: 2022-10-22 05:51:50 +0000 (Sat, 22 Oct 2022) Log Message: ----------- Fixed a handle leak for the Windows port Modified Paths: -------------- freesynd/trunk/src/utils/file.cpp Modified: freesynd/trunk/src/utils/file.cpp =================================================================== --- freesynd/trunk/src/utils/file.cpp 2019-10-10 18:43:59 UTC (rev 1029) +++ freesynd/trunk/src/utils/file.cpp 2022-10-22 05:51:50 UTC (rev 1030) @@ -240,6 +240,7 @@ processSaveFile(File.cFileName, files); } while (FindNextFile(hSearch, &File)); } + FindClose(hSearch); #else DIR * rep = opendir(savePath.c_str()); struct dirent * ent; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2019-10-10 18:44:01
|
Revision: 1029 http://sourceforge.net/p/freesynd/code/1029 Author: benblan Date: 2019-10-10 18:43:59 +0000 (Thu, 10 Oct 2019) Log Message: ----------- Fixed Cmake dependencies Modified Paths: -------------- freesynd/trunk/src/CMakeLists.txt Modified: freesynd/trunk/src/CMakeLists.txt =================================================================== --- freesynd/trunk/src/CMakeLists.txt 2017-08-26 06:45:50 UTC (rev 1028) +++ freesynd/trunk/src/CMakeLists.txt 2019-10-10 18:43:59 UTC (rev 1029) @@ -262,11 +262,13 @@ core/gamesession.cpp core/missionbriefing.cpp core/researchmanager.cpp + model/mod.cpp model/research.cpp model/squad.cpp model/objectivedesc.cpp model/shot.cpp model/weaponholder.cpp + model/weapon.cpp ia/actions.cpp ia/behaviour.cpp mission.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-05-13 11:09:44
|
Revision: 1026 http://sourceforge.net/p/freesynd/code/1026 Author: benblan Date: 2017-05-13 11:09:41 +0000 (Sat, 13 May 2017) Log Message: ----------- Rework of pedpathfinding for better readability Modified Paths: -------------- freesynd/trunk/src/common.h freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/map.cpp freesynd/trunk/src/map.h freesynd/trunk/src/model/position.h freesynd/trunk/src/pathsurfaces.h freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/pedpathfinding.cpp Modified: freesynd/trunk/src/common.h =================================================================== --- freesynd/trunk/src/common.h 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/common.h 2017-05-13 11:09:41 UTC (rev 1026) @@ -162,6 +162,33 @@ static const uint8 kColorBlue = 15; /*! Color constant : Dark Green */ static const uint8 kColorDarkGreen = 16; + + /*! + * Turn bits given by mask on in the given bitfield. + * \param bitfield the bitfield to update + * \param mask The bitmask to apply + */ + inline void setBitsWithMask(uint32 *bitfield, const uint32 mask) { + *bitfield |= mask; + } + + /*! + * Return true is bits identified by mask are set in the bitfield + * \param bitfield the bitfield to query + * \param mask The bitmask to apply + */ + inline bool isBitsOnWithMask(const uint32 bitfield, const uint32 mask) { + return (bitfield & mask) != 0; + } + + /*! + * Return true is bits identified by mask are set in the bitfield + * \param bitfield 8 bits bitfield to query + * \param mask 8 bits bitmask to apply + */ + inline bool isBitsOnWithMask(const uint8 bitfield, const uint8 mask) { + return (bitfield & mask) != 0; + } }; inline void boxify(int &left, int &width, int x1, int x2) @@ -178,7 +205,4 @@ int y; }; -#define IS_FLAG_SET(field, flags) (field & flags) != 0 -#define SET_FLAG(field, flags) field |= flags - #endif Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/ia/actions.cpp 2017-05-13 11:09:41 UTC (rev 1026) @@ -430,7 +430,6 @@ setFailed(); } else { if (pPed->speed() != 0) { - //IS_FLAG_SET(pPed->stateMasks(), PedInstance::pa_smWalking) if (pPed->isCloseTo(pTarget_, kFollowDistance)) { // We reached the target so stop moving temporarily pPed->clearDestination(); Modified: freesynd/trunk/src/map.cpp =================================================================== --- freesynd/trunk/src/map.cpp 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/map.cpp 2017-05-13 11:09:41 UTC (rev 1026) @@ -33,13 +33,9 @@ #include "gfx/tilemanager.h" #include "gfx/screen.h" -#if 0 -#define EXECUTION_SPEED_TIME -#endif - -Map::Map(TileManager * tileManager, uint16 i_id) : tile_manager_(tileManager) +Map::Map(TileManager * tileManager, uint16 anId) : tile_manager_(tileManager) { - i_id_ = i_id; + id_ = anId; a_tiles_ = NULL; } @@ -50,7 +46,7 @@ bool Map::loadMap(uint8 * mapData) { - LOG(Log::k_FLG_GFX, "Map", "loadMap", ("Loading Map %d.", i_id_)); + LOG(Log::k_FLG_GFX, "Map", "loadMap", ("Loading Map %d.", id_)); max_x_ = READ_LE_UINT32(mapData + 0); max_y_ = READ_LE_UINT32(mapData + 4); max_z_ = READ_LE_UINT32(mapData + 8); @@ -130,6 +126,24 @@ } } +void Map::clip(TilePoint *pPoint) { + if (pPoint->tx < 0) { + pPoint->tx = 0; + } else if (pPoint->tx >= maxX()) { + pPoint->tx = maxX() - 1; + } + + if (pPoint->ty < 0) { + pPoint->ty = 0; + } else if (pPoint->ty >= maxY()) { + pPoint->ty = maxY() - 1; + } + + if (pPoint->tz < 0 || pPoint->tz >= maxZ()) { + pPoint->tz = 0; + } +} + float scalexPx = 256.0f; float scalexPy = 256.0f; float scaleyPx = 256.0f; Modified: freesynd/trunk/src/map.h =================================================================== --- freesynd/trunk/src/map.h 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/map.h 2017-05-13 11:09:41 UTC (rev 1026) @@ -28,8 +28,6 @@ #include "common.h" #include "model/position.h" -#define NUM_MAPS 59 - class Tile; class TileManager; class MapObject; @@ -40,12 +38,12 @@ */ class Map { public: - Map(TileManager *tileManager, uint16 i_id); + Map(TileManager *tileManager, uint16 anId); ~Map(); bool loadMap(uint8 *mapData); - uint16 id() { return i_id_; } + uint16 id() { return id_; } int width() { return map_width_; } int height() { return map_height_; } void mapDimensions(int *x, int *y, int *z); @@ -53,6 +51,8 @@ void adjXYZ(int &x, int &y, int &z); //! Clip x and y to map dimensions. void clip(Point2D *point); + //! Clip x, y and z to map dimensions. + void clip(TilePoint *point); //! Converts a Map tile position to a screen position void tileToScreenPoint(int x, int y, int z, int pX, int pY, Point2D *pScp); @@ -74,7 +74,7 @@ protected: /*! Every map has a unique ID which is used to identify the name of the file containing map data.*/ - uint16 i_id_; + uint16 id_; int max_x_, max_y_, max_z_; Tile **a_tiles_; TileManager *tile_manager_; Modified: freesynd/trunk/src/model/position.h =================================================================== --- freesynd/trunk/src/model/position.h 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/model/position.h 2017-05-13 11:09:41 UTC (rev 1026) @@ -28,6 +28,9 @@ #ifndef MODEL_POSITION_H_ #define MODEL_POSITION_H_ +#include <iostream> +#include <sstream> + /*! * This a convenient structure to store a position * in map tile coordinates. @@ -107,6 +110,13 @@ int b = other.tx | (other.ty << 16); return a < b; } + + void toString(std::string *buffer) const { + std::ostringstream out; + + out << "(" << tx << ", " << ty << ", " << tz << " - " << ox << ", " << oy << ", " << oz << ")"; + buffer->append(out.str()); + } }; /*! Modified: freesynd/trunk/src/pathsurfaces.h =================================================================== --- freesynd/trunk/src/pathsurfaces.h 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/pathsurfaces.h 2017-05-13 11:09:41 UTC (rev 1026) @@ -31,7 +31,8 @@ unsigned char twd; }surfaceDesc; - typedef struct { + class floodPointDesc { + public: // mapFloodDesc // 0 - not defined, 0b - base point, 1b - target point, // 2b - link (when base point reaches target point or vice versa), @@ -45,13 +46,42 @@ // 0x10 = (x, y - 1, z); 0x20 = (x - 1, y - 1, z); // 0x40 = (x - 1, y, z); 0x80 = (x - 1, y + 1, z) // can be combined 0x01 | 0x02; 0x01 | 0x10 | 0x40 etc. - unsigned char dirh; - unsigned char dirm; - unsigned char dirl; + uint8 dirh; + uint8 dirm; + uint8 dirl; unsigned short lvl; - }floodPointDesc; + bool isDirectionUpContains(uint8 bmDirection) { + return fs_cmn::isBitsOnWithMask(dirh, bmDirection); + } + + bool isDirectionGroundContains(uint8 bmDirection) { + return fs_cmn::isBitsOnWithMask(dirm, bmDirection); + } + + bool isDirectionDownContains(uint8 bmDirection) { + return fs_cmn::isBitsOnWithMask(dirl, bmDirection); + } + + //! In path finding, identify the direction to North + static const uint8 kBMaskDirNorth; + //! In path finding, identify the direction to North-East + static const uint8 kBMaskDirNorthEast; + //! In path finding, identify the direction to East + static const uint8 kBMaskDirEast; + //! In path finding, identify the direction to South-East + static const uint8 kBMaskDirSouthEast; + //! In path finding, identify the direction to South + static const uint8 kBMaskDirSouth; + //! In path finding, identify the direction to South-West + static const uint8 kBMaskDirSouthWest; + //! In path finding, identify the direction to West + static const uint8 kBMaskDirWest; + //! In path finding, identify the direction to North-West + static const uint8 kBMaskDirNorthWest; + }; + typedef enum { m_fdNotDefined = 0, m_fdBasePoint = 1, Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/ped.cpp 2017-05-13 11:09:41 UTC (rev 1026) @@ -347,7 +347,7 @@ setDrawnAnim(PedInstance::ad_HitAnim); } else if ((state_ & pa_smHitByLaser) != 0) { setDrawnAnim(PedInstance::ad_VaporizeAnim); - } else if (IS_FLAG_SET(state_, pa_smHitByPersuadotron)) { + } else if (fs_cmn::isBitsOnWithMask(state_, pa_smHitByPersuadotron)) { setDrawnAnim(PedInstance::ad_PersuadedAnim); } #ifdef _DEBUG @@ -634,7 +634,7 @@ void PedInstance::setEnergyActivated(bool isActivated) { if (isActivated) { - SET_FLAG(desc_state_, pd_smShieldProtected); + fs_cmn::setBitsWithMask(&desc_state_, pd_smShieldProtected); } else { desc_state_ &= pd_smAll ^ pd_smShieldProtected; } @@ -1616,7 +1616,7 @@ */ void PedInstance::handlePersuadedBy(PedInstance *pAgent) { pAgent->addPersuaded(this); - SET_FLAG(desc_state_, pd_smControlled); + fs_cmn::setBitsWithMask(&desc_state_, pd_smControlled); setObjGroupID(pAgent->objGroupID()); owner_ = pAgent; setPanicImmuned(); Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/ped.h 2017-05-13 11:09:41 UTC (rev 1026) @@ -194,9 +194,9 @@ //! Returns the ped's behaviour Behaviour & behaviour() { return behaviour_; } //! Return true if ped has escaped the map - bool hasEscaped() { return IS_FLAG_SET(desc_state_, pd_smEscaped); } + bool hasEscaped() { return fs_cmn::isBitsOnWithMask(desc_state_, pd_smEscaped); } //! Indicate that the ped has escaped - void escape() { SET_FLAG(desc_state_, pd_smEscaped); } + void escape() { fs_cmn::setBitsWithMask(&desc_state_, pd_smEscaped); } //! Return true if ped don't panic bool isPanicImmuned() { return panicImmuned_; } //! Tells the ped not to panic @@ -364,7 +364,7 @@ void commitSuicide(); //! Return true if ped has activated his energy shield - bool isEnergyShieldActivated() { return IS_FLAG_SET(desc_state_, pd_smShieldProtected); } + bool isEnergyShieldActivated() { return fs_cmn::isBitsOnWithMask(desc_state_, pd_smShieldProtected); } void setEnergyActivated(bool status); //! Return the damage after applying protection of Mod @@ -378,7 +378,7 @@ // Persuasion //************************************* //! Return true if ped is persuaded - bool isPersuaded() { return IS_FLAG_SET(desc_state_, pd_smControlled); } + bool isPersuaded() { return fs_cmn::isBitsOnWithMask(desc_state_, pd_smControlled); } //! Returns true if this ped can persuade that ped bool canPersuade(PedInstance *pOtherPed, const int persuadotronRange); //! Return owner of persuaded @@ -659,7 +659,8 @@ private: inline int getClosestDirs(int dir, int& closest, int& closer); - void buildDestinationPath(Mission *m, std::vector<TilePoint> &cdestpath, int x, int y, int z, int ox, int oy); + void createPath(Mission *m, floodPointDesc *mdpmirror, std::vector<TilePoint> &cdestpath); + void buildFinalDestinationPath(Mission *m, std::vector<TilePoint> &cdestpath, const TilePoint &destinationPt); protected: enum pedDescStateMasks { Modified: freesynd/trunk/src/pedpathfinding.cpp =================================================================== --- freesynd/trunk/src/pedpathfinding.cpp 2017-05-08 13:41:38 UTC (rev 1025) +++ freesynd/trunk/src/pedpathfinding.cpp 2017-05-13 11:09:41 UTC (rev 1026) @@ -29,6 +29,7 @@ #include "ped.h" #include "pathsurfaces.h" #include "gfx/tile.h" +#include "utils/log.h" #if 0 #include "SDL.h" @@ -35,6 +36,15 @@ #define EXECUTION_SPEED_TIME #endif +const uint8 floodPointDesc::kBMaskDirNorth = 0x10; +const uint8 floodPointDesc::kBMaskDirNorthEast = 0x08; +const uint8 floodPointDesc::kBMaskDirEast = 0x04; +const uint8 floodPointDesc::kBMaskDirSouth = 0x01; +const uint8 floodPointDesc::kBMaskDirSouthEast = 0x02; +const uint8 floodPointDesc::kBMaskDirSouthWest = 0x80; +const uint8 floodPointDesc::kBMaskDirWest = 0x40; +const uint8 floodPointDesc::kBMaskDirNorthWest = 0x20; + /*! * Sets a destination point for the ped to reach at given speed. * \param m @@ -42,16 +52,17 @@ * \param newSpeed Speed of movement * \return true if destination has been set correctly. */ -//bool PedInstance::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { bool PedInstance::initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed) { - // if no speed was set, use ped's default speed - speed_ = newSpeed != -1 ? newSpeed : getDefaultSpeed(); - int x = destinationPt.tx; - int y = destinationPt.ty; - int z = destinationPt.tz; - int ox = destinationPt.ox; - int oy = destinationPt.oy; + dest_path_.clear(); + + if (health_ <= 0) { + return false; + } + + TilePoint clippedDestPt(destinationPt); + m->get_map()->clip(&clippedDestPt); + // NOTE: this is a "flood" algorithm, it expands until it reaches other's // flood point, then it removes unrelated points #ifdef EXECUTION_SPEED_TIME @@ -58,13 +69,9 @@ printf("---------------------------"); printf("start time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); #endif - m->get_map()->adjXYZ(x, y, z); - dest_path_.clear(); - if (health_ <= 0) - return false; - floodPointDesc *targetd = &(m->mdpoints_[x + y * m->mmax_x_ + z * m->mmax_m_xy]); + floodPointDesc *targetd = &(m->mdpoints_[clippedDestPt.tx + clippedDestPt.ty * m->mmax_x_ + clippedDestPt.tz * m->mmax_m_xy]); floodPointDesc *based = &(m->mdpoints_[pos_.tx + pos_.ty * m->mmax_x_ + pos_.tz * m->mmax_m_xy]); @@ -90,23 +97,23 @@ #endif #endif - //return; if(targetd->t == m_fdNonWalkable) { - printf("==== unwalk target: x %i; y %i; z %i, ox %i, oy %i\n", - x, y, z, ox, oy); - printf("setDestinationP, Movement to nonwalkable postion\n"); + std::string posAsStr; + clippedDestPt.toString(&posAsStr); + LOG(Log::k_FLG_GAME, "PedInstance", "initMovementToDestination", ("Ped %d : Movement to nonwalkable position %s", id_, posAsStr.c_str())); return false; } if(based->t == m_fdNonWalkable) { - printf("==== unwalk pos: x %i; y %i; z %i, ox %i, oy %i, oz %i\n", - pos_.tx, pos_.ty, pos_.tz, pos_.ox, pos_.oy, pos_.oz); - printf("setDestinationP, Movement from nonwalkable postion\n"); + std::string posAsStr; + position().toString(&posAsStr); + LOG(Log::k_FLG_GAME, "PedInstance", "initMovementToDestination", ("Ped %d : Movement from nonwalkable position %s", id_, posAsStr.c_str())); return false; } - if (pos_.tx == x && pos_.ty == y && pos_.tz == z) { - dest_path_.push_back(TilePoint(x, y, z, ox, oy)); + if (sameTile(clippedDestPt)) { + // TODO : check if this case can be removed to follow the regular + // path finding even if costly return false; } #ifdef EXECUTION_SPEED_TIME @@ -138,11 +145,11 @@ sadd.coords.z = pos_.tz; sadd.p = pfdp; bv.push_back(sadd); - pfdp = &(mdpmirror[x + y * m->mmax_x_ + z * m->mmax_m_xy]); + pfdp = &(mdpmirror[clippedDestPt.tx + clippedDestPt.ty * m->mmax_x_ + clippedDestPt.tz * m->mmax_m_xy]); pfdp->t |= (m_fdTargetPoint | m_fdConstant); - sadd.coords.x = x; - sadd.coords.y = y; - sadd.coords.z = z; + sadd.coords.x = clippedDestPt.tx; + sadd.coords.y = clippedDestPt.ty; + sadd.coords.z = clippedDestPt.tz; sadd.p = pfdp; tv.push_back(sadd); // for setting lvls data @@ -1238,35 +1245,66 @@ #ifdef EXECUTION_SPEED_TIME printf("non-related removed time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); #endif + + // path is created here + std::vector<TilePoint> cdestpath; + cdestpath.reserve(256); + + createPath(m, mdpmirror, cdestpath); + +#ifdef EXECUTION_SPEED_TIME + printf("path creation time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); +#endif + + // TODO: smoother path + // stairs to surface, surface to stairs correction + if (!cdestpath.empty()) { + buildFinalDestinationPath(m, cdestpath, clippedDestPt); + } + + if (dest_path_.empty()) { + // destination was not set -> stop ped + speed_ = 0; + return false; + } else { + // if no speed was set, use ped's default speed + speed_ = newSpeed != -1 ? newSpeed : getDefaultSpeed(); + return true; + } + #if 0 - bn.clear(); - tn.clear(); - bv.clear(); - tv.clear(); + for (std::list <TilePoint>::iterator it = dest_path_.begin(); + it != dest_path_.end(); ++it) { + printf("x %i, y %i, z %i\n", it->tileX(),it->tileY(),it->tileZ()); + } #endif +#ifdef EXECUTION_SPEED_TIME + dest_path_.clear(); + printf("+++++++++++++++++++++++++++"); + printf("end time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); +#endif +} - // path is created here - WorldPoint ctile; - ctile.x = pos_.tx; - ctile.y = pos_.ty; - ctile.z = pos_.tz; +void PedInstance::createPath(Mission *m, floodPointDesc *mdpmirror, std::vector<TilePoint> &pathToDestination) { + TilePoint currentTile(pos_.tx, pos_.ty, pos_.tz); unsigned char ct = m_fdBasePoint; bool tnr = true, np = true; - std::vector<TilePoint> cdestpath; - cdestpath.reserve(256); + floodPointDesc *pfdp; + toSetDesc sadd; + do { unsigned char nt = ct; + char dist = 5; WorldPoint toadd; - char dist = 5; - pfdp = &(mdpmirror[ctile.x + ctile.y * m->mmax_x_ - + ctile.z * m->mmax_m_xy]); + pfdp = &(mdpmirror[currentTile.tx + currentTile.ty * m->mmax_x_ + + currentTile.tz * m->mmax_m_xy]); uint16 lvl_child = ct == m_fdBasePoint ? pfdp->lvl + 1 : pfdp->lvl - 1; if (pfdp->dirh != 0) { - if ((pfdp->dirh & 0x01) == 0x01) { - sadd.coords.x = ctile.x; - sadd.coords.y = ctile.y + 1; - sadd.coords.z = ctile.z + 1; + if (pfdp->isDirectionUpContains(floodPointDesc::kBMaskDirSouth)) { + sadd.coords.x = currentTile.tx; + sadd.coords.y = currentTile.ty + 1; + sadd.coords.z = currentTile.tz + 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1287,10 +1325,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirh & 0x04) == 0x04) { - sadd.coords.x = ctile.x + 1; - sadd.coords.y = ctile.y; - sadd.coords.z = ctile.z + 1; + if (pfdp->isDirectionUpContains(floodPointDesc::kBMaskDirEast)) { + sadd.coords.x = currentTile.tx + 1; + sadd.coords.y = currentTile.ty; + sadd.coords.z = currentTile.tz + 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1311,10 +1349,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirh & 0x10) == 0x10) { - sadd.coords.x = ctile.x; - sadd.coords.y = ctile.y - 1; - sadd.coords.z = ctile.z + 1; + if (pfdp->isDirectionUpContains(floodPointDesc::kBMaskDirNorth)) { + sadd.coords.x = currentTile.tx; + sadd.coords.y = currentTile.ty - 1; + sadd.coords.z = currentTile.tz + 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1335,10 +1373,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirh & 0x40) == 0x40) { - sadd.coords.x = ctile.x - 1; - sadd.coords.y = ctile.y; - sadd.coords.z = ctile.z + 1; + if (pfdp->isDirectionUpContains(floodPointDesc::kBMaskDirWest)) { + sadd.coords.x = currentTile.tx - 1; + sadd.coords.y = currentTile.ty; + sadd.coords.z = currentTile.tz + 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1361,10 +1399,10 @@ } } if (pfdp->dirl != 0) { - if ((pfdp->dirl & 0x01) == 0x01) { - sadd.coords.x = ctile.x; - sadd.coords.y = ctile.y + 1; - sadd.coords.z = ctile.z - 1; + if (pfdp->isDirectionDownContains(floodPointDesc::kBMaskDirSouth)) { + sadd.coords.x = currentTile.tx; + sadd.coords.y = currentTile.ty + 1; + sadd.coords.z = currentTile.tz - 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1385,10 +1423,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirl & 0x04) == 0x04) { - sadd.coords.x = ctile.x + 1; - sadd.coords.y = ctile.y; - sadd.coords.z = ctile.z - 1; + if (pfdp->isDirectionDownContains(floodPointDesc::kBMaskDirEast)) { + sadd.coords.x = currentTile.tx + 1; + sadd.coords.y = currentTile.ty; + sadd.coords.z = currentTile.tz - 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1409,10 +1447,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirl & 0x10) == 0x10) { - sadd.coords.x = ctile.x; - sadd.coords.y = ctile.y - 1; - sadd.coords.z = ctile.z - 1; + if (pfdp->isDirectionDownContains(floodPointDesc::kBMaskDirNorth)) { + sadd.coords.x = currentTile.tx; + sadd.coords.y = currentTile.ty - 1; + sadd.coords.z = currentTile.tz - 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1433,10 +1471,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirl & 0x40) == 0x40) { - sadd.coords.x = ctile.x - 1; - sadd.coords.y = ctile.y; - sadd.coords.z = ctile.z - 1; + if (pfdp->isDirectionDownContains(floodPointDesc::kBMaskDirWest)) { + sadd.coords.x = currentTile.tx - 1; + sadd.coords.y = currentTile.ty; + sadd.coords.z = currentTile.tz - 1; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1459,10 +1497,10 @@ } } if (pfdp->dirm != 0) { - if ((pfdp->dirm & 0x01) == 0x01) { - sadd.coords.x = ctile.x; - sadd.coords.y = ctile.y + 1; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirSouth)) { + sadd.coords.x = currentTile.tx; + sadd.coords.y = currentTile.ty + 1; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1504,10 +1542,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x02) == 0x02) { - sadd.coords.x = ctile.x + 1; - sadd.coords.y = ctile.y + 1; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirSouthEast)) { + sadd.coords.x = currentTile.tx + 1; + sadd.coords.y = currentTile.ty + 1; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1528,10 +1566,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x04) == 0x04) { - sadd.coords.x = ctile.x + 1; - sadd.coords.y = ctile.y; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirEast)) { + sadd.coords.x = currentTile.tx + 1; + sadd.coords.y = currentTile.ty; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1573,10 +1611,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x08) == 0x08) { - sadd.coords.x = ctile.x + 1; - sadd.coords.y = ctile.y - 1; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirNorthEast)) { + sadd.coords.x = currentTile.tx + 1; + sadd.coords.y = currentTile.ty - 1; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1597,10 +1635,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x10) == 0x10) { - sadd.coords.x = ctile.x; - sadd.coords.y = ctile.y - 1; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirNorth)) { + sadd.coords.x = currentTile.tx; + sadd.coords.y = currentTile.ty - 1; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1642,10 +1680,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x20) == 0x20) { - sadd.coords.x = ctile.x - 1; - sadd.coords.y = ctile.y - 1; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirNorthWest)) { + sadd.coords.x = currentTile.tx - 1; + sadd.coords.y = currentTile.ty - 1; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1666,10 +1704,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x40) == 0x40) { - sadd.coords.x = ctile.x - 1; - sadd.coords.y = ctile.y; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirWest)) { + sadd.coords.x = currentTile.tx - 1; + sadd.coords.y = currentTile.ty; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1711,10 +1749,10 @@ if ((sadd.p->t & m_fdConstant) != 0) tnr = false; } - if ((pfdp->dirm & 0x80) == 0x80) { - sadd.coords.x = ctile.x - 1; - sadd.coords.y = ctile.y + 1; - sadd.coords.z = ctile.z; + if (pfdp->isDirectionGroundContains(floodPointDesc::kBMaskDirSouthWest)) { + sadd.coords.x = currentTile.tx - 1; + sadd.coords.y = currentTile.ty + 1; + sadd.coords.z = currentTile.tz; sadd.p = &(mdpmirror[sadd.coords.x + sadd.coords.y * m->mmax_x_ + sadd.coords.z * m->mmax_m_xy]); @@ -1740,50 +1778,17 @@ np = false; ct = nt; } - cdestpath.push_back(TilePoint(toadd.x, toadd.y, toadd.z)); + pathToDestination.push_back(TilePoint(toadd.x, toadd.y, toadd.z)); // this assert might save from memory fill up, - assert(ctile.x != toadd.x || ctile.y != toadd.y || ctile.z != toadd.z); - //if(toadd.x == 49 && toadd.y == 86 && toadd.z == 1) - //toadd.x = 49; - //if(ctile.x == toadd.x && ctile.y == toadd.y && ctile.z == toadd.z) - //ctile = toadd; - ctile = toadd; + assert(currentTile.tx != toadd.x || currentTile.ty != toadd.y || currentTile.tz != toadd.z); + + currentTile.tx = toadd.x; + currentTile.ty = toadd.y; + currentTile.tz = toadd.z; } while (tnr); -#ifdef EXECUTION_SPEED_TIME - printf("path creation time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); -#endif - - // TODO: smoother path - // stairs to surface, surface to stairs correction - if (!cdestpath.empty()) { - buildDestinationPath(m, cdestpath, x, y, z, ox, oy); - } - - if (dest_path_.empty()) { - // destination was not set -> stop ped - speed_ = 0; - return false; - } else { - return true; - } -#ifdef EXECUTION_SPEED_TIME - printf("smoothing time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); -#endif - -#if 0 - for (std::list <TilePoint>::iterator it = dest_path_.begin(); - it != dest_path_.end(); ++it) { - printf("x %i, y %i, z %i\n", it->tileX(),it->tileY(),it->tileZ()); - } -#endif -#ifdef EXECUTION_SPEED_TIME - dest_path_.clear(); - printf("+++++++++++++++++++++++++++"); - printf("end time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); -#endif } -void PedInstance::buildDestinationPath(Mission *m, std::vector<TilePoint> &cdestpath, int x, int y, int z, int ox, int oy) { +void PedInstance::buildFinalDestinationPath(Mission *m, std::vector<TilePoint> &cdestpath, const TilePoint &destinationPt) { TilePoint prvpn = TilePoint(pos_.tx, pos_.ty, pos_.tz, pos_.ox, pos_.oy); for (std::vector <TilePoint>::iterator it = cdestpath.begin(); it != cdestpath.end(); ++it) { @@ -2261,38 +2266,42 @@ dest_path_.push_back(*it); } } - prvpn = *it; - if (fit == cdestpath.end()) { - if (modified) { - dest_path_.push_back(TilePoint(x,y,z,ox,oy)); - } else { - // untill correct smoothing implemented this - // will prevent walking on non-walkable tile - if (xf == -1 && yf == -1) { - dest_path_.back().ox = 0; - dest_path_.back().oy = 0; - dest_path_.push_back(prvpn); - } - if (xf == 1 && yf == -1) { - dest_path_.back().ox = 255; - dest_path_.back().oy = 0; - dest_path_.push_back(prvpn); - } - if (xf == 1 && yf == 1) { - dest_path_.back().ox = 255; - dest_path_.back().oy = 255; - dest_path_.push_back(prvpn); - } - if (xf == -1 && yf == 1) { - dest_path_.back().ox = 0; - dest_path_.back().oy = 255; - dest_path_.push_back(prvpn); - } - dest_path_.back().ox = ox; - dest_path_.back().oy = oy; + prvpn = *it; + if (fit == cdestpath.end()) { + if (modified) { + dest_path_.push_back(TilePoint(destinationPt)); + } else { + // untill correct smoothing implemented this + // will prevent walking on non-walkable tile + if (xf == -1 && yf == -1) { + dest_path_.back().ox = 0; + dest_path_.back().oy = 0; + dest_path_.push_back(prvpn); } + if (xf == 1 && yf == -1) { + dest_path_.back().ox = 255; + dest_path_.back().oy = 0; + dest_path_.push_back(prvpn); + } + if (xf == 1 && yf == 1) { + dest_path_.back().ox = 255; + dest_path_.back().oy = 255; + dest_path_.push_back(prvpn); + } + if (xf == -1 && yf == 1) { + dest_path_.back().ox = 0; + dest_path_.back().oy = 255; + dest_path_.push_back(prvpn); + } + dest_path_.back().ox = destinationPt.ox; + dest_path_.back().oy = destinationPt.oy; } } + } + +#ifdef EXECUTION_SPEED_TIME + printf("smoothing time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); +#endif } bool PedInstance::doMove(int elapsed, Mission *pMission) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-05-08 13:41:40
|
Revision: 1025 http://sourceforge.net/p/freesynd/code/1025 Author: benblan Date: 2017-05-08 13:41:38 +0000 (Mon, 08 May 2017) Log Message: ----------- Rework of pedpathfinding Modified Paths: -------------- freesynd/trunk/src/app.cpp freesynd/trunk/src/app.h freesynd/trunk/src/editor/editorapp.cpp freesynd/trunk/src/editor/editorapp.h freesynd/trunk/src/gfx/tile.cpp freesynd/trunk/src/gfx/tile.h freesynd/trunk/src/mission.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/pedpathfinding.cpp Modified: freesynd/trunk/src/app.cpp =================================================================== --- freesynd/trunk/src/app.cpp 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/app.cpp 2017-05-08 13:41:38 UTC (rev 1025) @@ -306,30 +306,6 @@ return rsp; } -bool App::loadWalkData() { - int size = 0; - uint8 *data; - - // reads data from file - data = File::loadOriginalFile("col01.dat", size); - if (!data) { - return false; - } - - memcpy(walkdata_p_, data, 256); - // little patch to enable full surface description - // and eliminate unnecessary data - // 0x10 - non-surface/non-walkable, always above train stop - // 0x11, 0x12 - train entering surface - walkdata_p_[0x80] = 0x11; - walkdata_p_[0x81] = 0x12; - walkdata_p_[0x8F] = 0x00; - walkdata_p_[0x93] = 0x00; - delete[] data; - - return true; -} - void App::updateIntroFlag() { try { ConfigFile conf(iniPath_); @@ -377,10 +353,6 @@ return false; } - if (!loadWalkData()) { - return false; - } - LOG(Log::k_FLG_INFO, "App", "initialize", ("loading game sprites...")) if (!gameSprites().loaded()) gameSprites().load(); Modified: freesynd/trunk/src/app.h =================================================================== --- freesynd/trunk/src/app.h 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/app.h 2017-05-08 13:41:38 UTC (rev 1025) @@ -64,9 +64,6 @@ //! Initialize application bool initialize(const std::string& iniPath); - // patched version - uint8 walkdata_p_[256]; - void setCheatCode(const char *name); GameSpriteManager &gameSprites() { @@ -130,9 +127,6 @@ //! Tests Syndicate original data for existence and correctness bool testOriginalData(); - //! Loads walk data - bool loadWalkData(); - //! Sets the intro flag to false in the config file void updateIntroFlag(); Modified: freesynd/trunk/src/editor/editorapp.cpp =================================================================== --- freesynd/trunk/src/editor/editorapp.cpp 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/editor/editorapp.cpp 2017-05-08 13:41:38 UTC (rev 1025) @@ -310,30 +310,6 @@ return rsp; } -bool EditorApp::loadWalkData() { - int size = 0; - uint8 *data; - - // reads data from file - data = File::loadOriginalFile("col01.dat", size); - if (!data) { - return false; - } - - memcpy(walkdata_p_, data, 256); - // little patch to enable full surface description - // and eliminate unnecessary data - // 0x10 - non-surface/non-walkable, always above train stop - // 0x11, 0x12 - train entering surface - walkdata_p_[0x80] = 0x11; - walkdata_p_[0x81] = 0x12; - walkdata_p_[0x8F] = 0x00; - walkdata_p_[0x93] = 0x00; - delete[] data; - - return true; -} - void EditorApp::updateIntroFlag() { try { ConfigFile conf(iniPath_); Modified: freesynd/trunk/src/editor/editorapp.h =================================================================== --- freesynd/trunk/src/editor/editorapp.h 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/editor/editorapp.h 2017-05-08 13:41:38 UTC (rev 1025) @@ -54,9 +54,6 @@ //! Initialize application bool initialize(const std::string& iniPath); - // patched version - uint8 walkdata_p_[256]; - GameSpriteManager &gameSprites() { return game_sprites_; } @@ -113,9 +110,6 @@ //! Tests Syndicate original data for existence and correctness bool testOriginalData(); - //! Loads walk data - bool loadWalkData(); - //! Sets the intro flag to false in the config file void updateIntroFlag(); Modified: freesynd/trunk/src/gfx/tile.cpp =================================================================== --- freesynd/trunk/src/gfx/tile.cpp 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/gfx/tile.cpp 2017-05-08 13:41:38 UTC (rev 1025) @@ -39,7 +39,7 @@ not_alpha_ = not_alpha; } -Tile::~Tile() +Tile::~Tile() { delete[] a_pixels_; } @@ -81,3 +81,23 @@ { return drawTo((uint8*) g_Screen.pixels(), g_Screen.gameScreenWidth(), g_Screen.gameScreenHeight(), x, y); } + +uint8 Tile::getWalkData() { + // little patch to enable full surface description + // and eliminate unnecessary data + // 0x10 - non-surface/non-walkable, always above train stop + // 0x11, 0x12 - train entering surface + switch (i_id_) { + case 0x80 : + return 0x11; + case 0x81 : + return 0x12; + case 0x8F : + return 0x00; + case 0x93 : + return 0x00; + default: + // else return the type of the tile + return e_type_; + } +} Modified: freesynd/trunk/src/gfx/tile.h =================================================================== --- freesynd/trunk/src/gfx/tile.h 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/gfx/tile.h 2017-05-08 13:41:38 UTC (rev 1025) @@ -55,10 +55,10 @@ */ enum EType { kNone = 0x00, // non-surface/non-walkable(if above surface is walkable) - kSlopeSN = 0x01, - kSlopeNS = 0x02, - kSlopeEW = 0x03, - kSlopeWE = 0x04, + kSlopeSN = 0x01, // stairs that climbs along the Y axis from left to right + kSlopeNS = 0x02, // stairs that climbs along the Y axis from right to left + kSlopeEW = 0x03, // stairs that climbs along the X axis from left to right + kSlopeWE = 0x04, // stairs that climbs along the X axis from right to left kGround = 0x05, kRoadSideEW = 0x06, kRoadSideWE = 0x07, @@ -77,7 +77,7 @@ Tile(uint8 id_set, uint8 *tile_Data, bool not_alpha, EType type_set); ~Tile(); - //! Returns the tile id + //! Returns the tile id uint8 id() { return i_id_; } //! Returns the tile type EType type() { return e_type_; } @@ -91,6 +91,8 @@ return e_type_ > kNone && e_type_ < kGround; } + uint8 getWalkData(); + //! Draws the tile to the given surface bool drawTo(uint8 *screen, int swidth, int sheight, int x, int y); //! Draws the tile to the screen Modified: freesynd/trunk/src/mission.cpp =================================================================== --- freesynd/trunk/src/mission.cpp 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/mission.cpp 2017-05-08 13:41:38 UTC (rev 1025) @@ -443,7 +443,7 @@ mdpoints_cp_ = (floodPointDesc *)malloc(mmax_m_all * sizeof(floodPointDesc)); if(mtsurfaces_ == NULL || mdpoints_ == NULL || mdpoints_cp_ == NULL) { clrSurfaces(); - printf("ERROR: memory allocation failed in Mission::setSurfaces"); + FSERR(Log::k_FLG_GAME, "Mission", "setSurfaces", ("Memory allocation error\n")); return false; } mmax_m_xy = mmax_x_ * mmax_y_; @@ -453,7 +453,7 @@ for (int iy = 0; iy < mmax_y_; ++iy) { for (int iz = 0; iz < mmax_z_; ++iz) { mtsurfaces_[ix + iy * mmax_x_ + iz * mmax_m_xy].twd = - g_App.walkdata_p_[p_map_->tileAt(ix, iy, iz)]; + p_map_->getTileAt(ix, iy, iz)->getWalkData(); } } } Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/ped.h 2017-05-08 13:41:38 UTC (rev 1025) @@ -659,6 +659,7 @@ private: inline int getClosestDirs(int dir, int& closest, int& closer); + void buildDestinationPath(Mission *m, std::vector<TilePoint> &cdestpath, int x, int y, int z, int ox, int oy); protected: enum pedDescStateMasks { Modified: freesynd/trunk/src/pedpathfinding.cpp =================================================================== --- freesynd/trunk/src/pedpathfinding.cpp 2017-04-08 08:26:34 UTC (rev 1024) +++ freesynd/trunk/src/pedpathfinding.cpp 2017-05-08 13:41:38 UTC (rev 1025) @@ -28,6 +28,7 @@ #include "mission.h" #include "ped.h" #include "pathsurfaces.h" +#include "gfx/tile.h" #if 0 #include "SDL.h" @@ -60,7 +61,7 @@ m->get_map()->adjXYZ(x, y, z); dest_path_.clear(); - if (map_ == -1 || health_ <= 0) + if (health_ <= 0) return false; floodPointDesc *targetd = &(m->mdpoints_[x + y * m->mmax_x_ + z * m->mmax_m_xy]); @@ -90,7 +91,7 @@ #endif //return; - if(targetd->t == m_fdNonWalkable || map_ == -1 || health_ <= 0) { + if(targetd->t == m_fdNonWalkable) { printf("==== unwalk target: x %i; y %i; z %i, ox %i, oy %i\n", x, y, z, ox, oy); printf("setDestinationP, Movement to nonwalkable postion\n"); @@ -1755,26 +1756,54 @@ // TODO: smoother path // stairs to surface, surface to stairs correction if (!cdestpath.empty()) { - TilePoint prvpn = TilePoint(pos_.tx, pos_.ty, pos_.tz, pos_.ox, pos_.oy); - for (std::vector <TilePoint>::iterator it = cdestpath.begin(); + buildDestinationPath(m, cdestpath, x, y, z, ox, oy); + } + + if (dest_path_.empty()) { + // destination was not set -> stop ped + speed_ = 0; + return false; + } else { + return true; + } +#ifdef EXECUTION_SPEED_TIME + printf("smoothing time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); +#endif + +#if 0 + for (std::list <TilePoint>::iterator it = dest_path_.begin(); + it != dest_path_.end(); ++it) { + printf("x %i, y %i, z %i\n", it->tileX(),it->tileY(),it->tileZ()); + } +#endif +#ifdef EXECUTION_SPEED_TIME + dest_path_.clear(); + printf("+++++++++++++++++++++++++++"); + printf("end time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); +#endif +} + +void PedInstance::buildDestinationPath(Mission *m, std::vector<TilePoint> &cdestpath, int x, int y, int z, int ox, int oy) { + TilePoint prvpn = TilePoint(pos_.tx, pos_.ty, pos_.tz, pos_.ox, pos_.oy); + for (std::vector <TilePoint>::iterator it = cdestpath.begin(); it != cdestpath.end(); ++it) { - std::vector <TilePoint>::iterator fit = it + 1; - bool modified = false; - unsigned char twd = m->mtsurfaces_[prvpn.tx - + prvpn.ty * m->mmax_x_ - + prvpn.tz * m->mmax_m_xy].twd; - unsigned char twdn = m->mtsurfaces_[it->tx - + it->ty * m->mmax_x_ - + it->tz * m->mmax_m_xy].twd; - char xf = prvpn.tx - it->tx; - char yf = prvpn.ty - it->ty; - char zf = prvpn.tz - it->tz; + std::vector <TilePoint>::iterator fit = it + 1; + bool modified = false; + unsigned char twd = m->mtsurfaces_[prvpn.tx + + prvpn.ty * m->mmax_x_ + + prvpn.tz * m->mmax_m_xy].twd; + unsigned char twdn = m->mtsurfaces_[it->tx + + it->ty * m->mmax_x_ + + it->tz * m->mmax_m_xy].twd; + char xf = prvpn.tx - it->tx; + char yf = prvpn.ty - it->ty; + char zf = prvpn.tz - it->tz; if (twd > 0x0 && twd < 0x05) { if (twdn > 0x0 && twdn < 0x05) { dest_path_.push_back(*it); } else { switch (twd) { - case 0x01: + case Tile::kSlopeSN: if (zf == -1) { if (xf == 0) { dest_path_.push_back(*it); @@ -2264,30 +2293,6 @@ } } } - } - - if (dest_path_.empty()) { - // destination was not set -> stop ped - speed_ = 0; - return false; - } else { - return true; - } -#ifdef EXECUTION_SPEED_TIME - printf("smoothing time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); -#endif - -#if 0 - for (std::list <TilePoint>::iterator it = dest_path_.begin(); - it != dest_path_.end(); ++it) { - printf("x %i, y %i, z %i\n", it->tileX(),it->tileY(),it->tileZ()); - } -#endif -#ifdef EXECUTION_SPEED_TIME - dest_path_.clear(); - printf("+++++++++++++++++++++++++++"); - printf("end time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); -#endif } bool PedInstance::doMove(int elapsed, Mission *pMission) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-04-08 08:26:37
|
Revision: 1024 http://sourceforge.net/p/freesynd/code/1024 Author: benblan Date: 2017-04-08 08:26:34 +0000 (Sat, 08 Apr 2017) Log Message: ----------- - Removed unused code - Energy shield activation is now taken into account Modified Paths: -------------- freesynd/trunk/NEWS freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/menus/squadselection.cpp freesynd/trunk/src/model/weapon.h freesynd/trunk/src/model/weaponholder.cpp freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/pedmanager.cpp Modified: freesynd/trunk/NEWS =================================================================== --- freesynd/trunk/NEWS 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/NEWS 2017-04-08 08:26:34 UTC (rev 1024) @@ -19,6 +19,7 @@ * Trains now moves and player agents can get on/off * Persuaded peds follow their leader in cars and trains * When player agents shoot on a vehicle, the driver is ejected + * Energy Shield is now fully usable Known issues with this release ------------------------------ Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/ia/actions.cpp 2017-04-08 08:26:34 UTC (rev 1024) @@ -734,6 +734,9 @@ } else if (pPed->type() == PedInstance::kPedTypePolice && pTarget_->selectedWeapon() == NULL) { // Police man don't shoot on peds that don't have gun out setFailed(); + } else if (pTarget_->isEnergyShieldActivated()) { + // Don't shoot if target has an energy shield + setFailed(); } else { WorldPoint targetLocW(pTarget_->position()); Modified: freesynd/trunk/src/menus/squadselection.cpp =================================================================== --- freesynd/trunk/src/menus/squadselection.cpp 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/menus/squadselection.cpp 2017-04-08 08:26:34 UTC (rev 1024) @@ -193,10 +193,11 @@ for (SquadSelection::Iterator it = begin(); it != end(); ++it) { PedInstance *ped = *it; + ped->stopUsingWeapon(); if (pLeader == ped) { // Forces selection of the weapon for the leader pLeader->selectWeapon(weapon_idx); - } else if (pLeaderWeapon->getClass()->canShoot()) { + } else if (pLeaderWeapon->canShoot()) { ped->selectShootingWeaponWithSameTypeFirst(pLeaderWeapon); } else if (applySelectionToAll) { ped->selectMedikitOrShield(pLeaderWeapon->getClass()->getType()); Modified: freesynd/trunk/src/model/weapon.h =================================================================== --- freesynd/trunk/src/model/weapon.h 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/model/weapon.h 2017-04-08 08:26:34 UTC (rev 1024) @@ -336,11 +336,6 @@ void reload() { ammo_remaining_ = pWeaponClass_->ammo(); } - bool operator==(WeaponInstance wi) { - // TODO : check if this method is necessary - return hasSameTypeAs(wi); - } - //! Plays the weapon's sound. void playSound(); Modified: freesynd/trunk/src/model/weaponholder.cpp =================================================================== --- freesynd/trunk/src/model/weaponholder.cpp 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/model/weaponholder.cpp 2017-04-08 08:26:34 UTC (rev 1024) @@ -245,20 +245,18 @@ // If the selected weapon was a shooting one // select a shooting weapon for the agent, choosing // first a weapon of same type then any shooting weapon - if (selected_weapon_ == kNoWeaponSelected) { - for (uint8 i = 0; i < sz; ++i) { - WeaponInstance *pWI = weapons_[i]; - if (pWI->canShoot() && pWI->ammoRemaining() > 0) - { - if (*pWI == *(criteria.criteria.wi)) { - found_weapons.clear(); - found_weapons.push_back(std::make_pair(pWI->rank(), i)); - break; - } else { - // We found a loaded weapon of different type - // save it for after - found_weapons.push_back(std::make_pair(pWI->rank(), i)); - } + for (uint8 i = 0; i < sz; ++i) { + WeaponInstance *pWI = weapons_[i]; + if (pWI->canShoot() && pWI->ammoRemaining() > 0) + { + if (pWI->hasSameTypeAs(*(criteria.criteria.wi))) { + found_weapons.clear(); + found_weapons.push_back(std::make_pair(pWI->rank(), i)); + break; + } else { + // We found a loaded weapon of different type + // save it for after + found_weapons.push_back(std::make_pair(pWI->rank(), i)); } } } Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/ped.cpp 2017-04-08 08:26:34 UTC (rev 1024) @@ -934,11 +934,6 @@ * \param previousWeapon The previous selected weapon (can be null if no weapon was selected) */ void PedInstance::handleWeaponSelected(WeaponInstance * wi, WeaponInstance * previousWeapon) { - if (wi->doesPhysicalDmg()) - desc_state_ |= pd_smArmed; - else - desc_state_ &= pd_smAll ^ pd_smArmed; - switch(wi->getClass()->getType()) { case Weapon::EnergyShield: addActionUseEnergyShield(wi); @@ -978,6 +973,9 @@ * \return the instance of dropped weapon */ WeaponInstance * PedInstance::dropWeapon(uint8 index) { + if (selected_weapon_ == index) { + stopUsingWeapon(); + } WeaponInstance *pWeapon = removeWeaponAtIndex(index); if(pWeapon) { Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/ped.h 2017-04-08 08:26:34 UTC (rev 1024) @@ -180,24 +180,6 @@ kPedTypeCriminal = 0x10 } ; - enum pedDescStateMasks { - pd_smUndefined = 0x0, - pd_smControlled = 0x0001, - pd_smArmed = 0x0002, - // no active action should be done, ex. persuaded ped will shoot target - // of persuader only if persuader shoots at it - pd_smSupporter = 0x0004, - pd_smEnemyInSight = 0x0008, - //! Energy shield protects the ped - pd_smShieldProtected = 0x0010, - // all non-player controllled peds should have this set - pd_smAutoAction = 0x0020, - /*! When a mission's objective is to kill a ped and this ped has - escaped, this value is used to indicate he's escaped.*/ - pd_smEscaped = 0x0080, - pd_smAll = 0xFFFF - }; - PedInstance(Ped *ped, uint16 id, int m, bool isOur); ~PedInstance(); @@ -679,6 +661,17 @@ inline int getClosestDirs(int dir, int& closest, int& closer); protected: + enum pedDescStateMasks { + pd_smUndefined = 0x0, + //! Set when a ped has been persuaded + pd_smControlled = 0x0001, + //! Energy shield protects the ped + pd_smShieldProtected = 0x0010, + /*! When a mission's objective is to kill a ped and this ped has + escaped, this value is used to indicate he's escaped.*/ + pd_smEscaped = 0x0080, + pd_smAll = 0xFFFF + }; Ped *ped_; //! Type of Ped Modified: freesynd/trunk/src/pedmanager.cpp =================================================================== --- freesynd/trunk/src/pedmanager.cpp 2017-04-08 06:48:06 UTC (rev 1023) +++ freesynd/trunk/src/pedmanager.cpp 2017-04-08 08:26:34 UTC (rev 1024) @@ -250,7 +250,6 @@ pPed->setObjGroupDef(PedInstance::og_dmAgent); pPed->addEnemyGroupDef(2); pPed->addEnemyGroupDef(3); - pPed->setHostileDesc(PedInstance::pd_smArmed); pPed->setSightRange(7 * 256); pPed->setBaseSpeed(256); pPed->setTimeBeforeCheck(400); @@ -315,7 +314,6 @@ LOG(Log::k_FLG_GAME, "PedManager","initPolice", ("Create police with id %d", pPed->id())) pPed->setObjGroupID(4); - pPed->setHostileDesc(PedInstance::pd_smArmed); pPed->setBaseSpeed(160); pPed->setTimeBeforeCheck(400); pPed->setBaseModAcc(0.4); @@ -334,7 +332,6 @@ pPed->setObjGroupID(5); pPed->addEnemyGroupDef(6); - pPed->setHostileDesc(PedInstance::pd_smArmed); pPed->setBaseSpeed(128); pPed->setTimeBeforeCheck(600); pPed->setBaseModAcc(0.2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-04-08 06:48:09
|
Revision: 1023 http://sourceforge.net/p/freesynd/code/1023 Author: benblan Date: 2017-04-08 06:48:06 +0000 (Sat, 08 Apr 2017) Log Message: ----------- - Fix error in dump build - rework energy shield activation - fixed a crash when using Medikit - rework around weapon selection Modified Paths: -------------- freesynd/trunk/README freesynd/trunk/src/CMakeLists.txt freesynd/trunk/src/agent.h freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/ia/actions.h freesynd/trunk/src/ia/behaviour.cpp freesynd/trunk/src/mapobject.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/squadselection.cpp freesynd/trunk/src/menus/squadselection.h freesynd/trunk/src/model/weapon.cpp freesynd/trunk/src/model/weapon.h freesynd/trunk/src/model/weaponholder.cpp freesynd/trunk/src/model/weaponholder.h freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/pedactions.cpp Modified: freesynd/trunk/README =================================================================== --- freesynd/trunk/README 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/README 2017-04-08 06:48:06 UTC (rev 1023) @@ -75,6 +75,8 @@ * F5 - F12 : each key selects/deselects one item in the inventory. Pressing CTRL-Fx to select a Medikit will apply Medikit on all selected agents that own one. + Pressing CTRL-Fx to select an EnergyShield will select an Energy Shield on all selected agents + that own one. * 1-4 : Numeric key selects the corresponding agent. * 0 : Key 0 selects all agents or selects only the leader. * Left,Right,Up,Down : Scrolls the map. Modified: freesynd/trunk/src/CMakeLists.txt =================================================================== --- freesynd/trunk/src/CMakeLists.txt 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/CMakeLists.txt 2017-04-08 06:48:06 UTC (rev 1023) @@ -252,19 +252,17 @@ ped.cpp pedactions.cpp pedpathfinding.cpp - mod.cpp modmanager.cpp missionmanager.cpp model/vehicle.cpp model/train.cpp - weapon.cpp weaponmanager.cpp core/gamecontroller.cpp core/gamesession.cpp core/missionbriefing.cpp core/researchmanager.cpp - core/research.cpp - core/squad.cpp + model/research.cpp + model/squad.cpp model/objectivedesc.cpp model/shot.cpp model/weaponholder.cpp Modified: freesynd/trunk/src/agent.h =================================================================== --- freesynd/trunk/src/agent.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/agent.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -36,8 +36,6 @@ #include "modowner.h" #include "utils/portablefile.h" -class WeaponInstance; - /*! * Stores information about agent health, weapons inventory and modifications. */ Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/ia/actions.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -694,21 +694,6 @@ pTarget_ = pPed; } -/*! - * Select a weapon for the ped if he has no weapon out. - * \param pPed The police man. - */ -void WaitBeforeShootingAction::selectWeaponIfNecessary(PedInstance *pPed) { - WeaponInstance *pWeapon = pPed->selectedWeapon(); - if (pWeapon == NULL) { - // Select a loaded weapon for ped - WeaponHolder::WeaponSelectCriteria crit; - crit.desc = WeaponHolder::WeaponSelectCriteria::kCritLoadedShoot; - crit.use_ranks = true; - pPed->selectRequiredWeapon(&crit); - } -} - void WaitBeforeShootingAction::doStart(Mission *pMission, PedInstance *pPed) { if (pTarget_->isDead()) { setFailed(); @@ -715,7 +700,7 @@ } else { waitTimer_.reset(); pPed->clearDestination(); - selectWeaponIfNecessary(pPed); + pPed->selectShootingWeaponWithAmmo(); } } @@ -1125,3 +1110,41 @@ return update; } + +/*! + * Execute the Use medikit action. + * \param elapsed Time since last frame. + * \param pMission Mission data + * \param pPed The ped executing the action. + * \return true to redraw + */ +bool UseEnergyShieldAction::execute(int elapsed, Mission *pMission, PedInstance *pPed) { + if (status_ == kActStatusNotStarted) { + status_ = kActStatusRunning; + + if (!pWeapon_->isInstanceOf(Weapon::EnergyShield)) { + setFailed(); + return false; + } else { + //pWeapon_->playSound(); + ShootableMapObject::DamageInflictType dmg; + pWeapon_->fire(pMission, dmg, elapsed); + } + } else if (status_ == kActStatusRunning) { + if (pWeapon_->consumeAmmoForEnergyShield(elapsed)) { + // no more ammo + pPed->setEnergyActivated(false); + setSucceeded(); + } + } + + return true; +} + +void UseEnergyShieldAction::stop() { + if (status_ == kActStatusRunning) { + PedInstance *pPed = pWeapon_->owner(); + pPed->setEnergyActivated(false); + setSucceeded(); + } +} Modified: freesynd/trunk/src/ia/actions.h =================================================================== --- freesynd/trunk/src/ia/actions.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/ia/actions.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -529,8 +529,6 @@ void doStart(Mission *pMission, PedInstance *pPed); bool doExecute(int elapsed, Mission *pMission, PedInstance *pPed); - void selectWeaponIfNecessary(PedInstance *pPed); - protected: /*! The ped watched by this ped.*/ PedInstance *pTarget_; @@ -721,7 +719,7 @@ */ class UseMedikitAction : public UseWeaponAction { public: - UseMedikitAction() : UseWeaponAction(NULL) {} + UseMedikitAction(WeaponInstance *pMedikit) : UseWeaponAction(pMedikit) {} //! Entry point to execute the action bool execute(int elapsed, Mission *pMission, PedInstance *pPed); @@ -730,4 +728,18 @@ int timeToWait_; }; +/*! + * This action is used when player activates an energy shield. + */ +class UseEnergyShieldAction : public UseWeaponAction { +public: + UseEnergyShieldAction(WeaponInstance *pEnergyShield) : UseWeaponAction(pEnergyShield) {} + + //! Entry point to execute the action + bool execute(int elapsed, Mission *pMission, PedInstance *pPed); + void stop(); +protected: + +}; + #endif // IA_ACTIONS_H_ Modified: freesynd/trunk/src/ia/behaviour.cpp =================================================================== --- freesynd/trunk/src/ia/behaviour.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/ia/behaviour.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -439,7 +439,7 @@ // our target has dropped his weapon if (status_ == kPoliceStatusFollowAndShootTarget && pTarget_ == pCtxt) { status_ = kPoliceStatusPendingEndFollow; - pPed->stopUsingWeapon(); + pPed->stopShooting(); // just wait a few time before engaging another target or simply // continue with default behavior @@ -562,7 +562,7 @@ } else if (status_ == kHostileStatusFollowAndShoot && pTarget_->isDead()) { status_ = kHostileStatusPendingEndFollow; pTarget_ = NULL; - pPed->stopUsingWeapon(); + pPed->stopShooting(); // just wait a few time before engaging another target or simply // continue with default behavior WaitAction *pWait = new WaitAction(WaitAction::kWaitWeapon); Modified: freesynd/trunk/src/mapobject.h =================================================================== --- freesynd/trunk/src/mapobject.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/mapobject.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -65,7 +65,7 @@ const char* natureName(); //! Return the object's id - uint16 id() { return id_; } + uint16 id() const { return id_; } void setDrawable(bool drawable) { isDrawable_ = drawable; Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -643,7 +643,7 @@ g_System.usePointerYellowCursor(); } - if (x < 129) { + if (x < 129 && isPlayerShooting_) { stopShootingEvent(); } @@ -877,7 +877,7 @@ for (SquadSelection::Iterator it = selection_.begin(); it != selection_.end(); ++it) { PedInstance *pAgent = *it; - pAgent->stopUsingWeapon(); + pAgent->stopShooting(); } } @@ -1435,16 +1435,16 @@ /*! * */ -void GameplayMenu::handleWeaponSelection(uint8 weapon_idx, bool ctrl) { +void GameplayMenu::handleWeaponSelection(uint8 selectorIndex, bool ctrl) { PedInstance *pLeader = selection_.leader(); - if (weapon_idx < pLeader->numWeapons()) { - WeaponInstance *wi = pLeader->weapon(weapon_idx); + if (selectorIndex < pLeader->numWeapons()) { + WeaponInstance *wi = pLeader->weapon(selectorIndex); if (pLeader->selectedWeapon() == wi) { // Player clicked on an already selected weapon -> deselect - selection_.deselectAllWeapons(); + selection_.deselectWeaponOfSameCategory(wi->getClass()); } else { - selection_.selectWeaponFromLeader(weapon_idx, ctrl); + selection_.selectWeaponFromLeader(selectorIndex, ctrl); } } g_App.gameSounds().play(snd::SPEECH_SELECTED); Modified: freesynd/trunk/src/menus/squadselection.cpp =================================================================== --- freesynd/trunk/src/menus/squadselection.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/menus/squadselection.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -161,12 +161,22 @@ } /*! - * Deselects all selected agents selected weapon. + * Deselects the leader selected weapon and for the other agents, it depends + * on the leader's weapon. */ -void SquadSelection::deselectAllWeapons() { +void SquadSelection::deselectWeaponOfSameCategory(Weapon *pWeaponFromLeader) { + bool categoryShooting = pWeaponFromLeader->canShoot(); for (SquadSelection::Iterator it = begin(); it != end(); ++it) { PedInstance *pAgent = *it; - pAgent->deselectWeapon(); + WeaponInstance *pWeaponToDeselect = pAgent->selectedWeapon(); + if (pWeaponToDeselect != NULL) { + if (pAgent == leader() || + (categoryShooting && pWeaponToDeselect->getClass()->canShoot()) || + (pWeaponToDeselect->isInstanceOf(pWeaponFromLeader->getType()))) { + pAgent->stopUsingWeapon(); + pAgent->deselectWeapon(); + } + } } } @@ -176,12 +186,9 @@ * \param weapon_idx The index in the leader inventory of the weapon to select. * \param apply_to_all In case of Medikit, all selected agents must use one. */ -void SquadSelection::selectWeaponFromLeader(int weapon_idx, bool apply_to_all) { +void SquadSelection::selectWeaponFromLeader(int weapon_idx, bool applySelectionToAll) { PedInstance *pLeader = leader(); - PedInstance::WeaponSelectCriteria pw_to_use; - pw_to_use.desc = WeaponHolder::WeaponSelectCriteria::kCritPlayerSelection; - pw_to_use.criteria.wi = pLeader->weapon(weapon_idx); - pw_to_use.apply_to_all = apply_to_all; + WeaponInstance *pLeaderWeapon = pLeader->weapon(weapon_idx); for (SquadSelection::Iterator it = begin(); it != end(); ++it) { @@ -189,9 +196,10 @@ if (pLeader == ped) { // Forces selection of the weapon for the leader pLeader->selectWeapon(weapon_idx); - } else { - // For other agents, it depends on their actual selection - ped->selectRequiredWeapon(&pw_to_use); + } else if (pLeaderWeapon->getClass()->canShoot()) { + ped->selectShootingWeaponWithSameTypeFirst(pLeaderWeapon); + } else if (applySelectionToAll) { + ped->selectMedikitOrShield(pLeaderWeapon->getClass()->getType()); } } // end for } Modified: freesynd/trunk/src/menus/squadselection.h =================================================================== --- freesynd/trunk/src/menus/squadselection.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/menus/squadselection.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -167,7 +167,7 @@ // Action on multiple agents //************************************* //! Deselects all selected agents weapons - void deselectAllWeapons(); + void deselectWeaponOfSameCategory(Weapon *pWeaponFromLeader); //! Select a weapon for the leader and for all selected agents void selectWeaponFromLeader(int weapon_idx, bool apply_to_all); //! Go and pick up weapon Modified: freesynd/trunk/src/model/weapon.cpp =================================================================== --- freesynd/trunk/src/model/weapon.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/model/weapon.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -286,13 +286,7 @@ bool WeaponInstance::animate(int elapsed) { if (activated_) { - if (isInstanceOf(Weapon::EnergyShield)) { - if (ammo_remaining_ && consumeAmmoForEnergyShield(elapsed)) { - // no more ammo so deselect shield - pOwner_->deselectWeapon(); - } - return true; - } else if (isInstanceOf(Weapon::TimeBomb)) { + if (isInstanceOf(Weapon::TimeBomb)) { if (bombSoundTimer.update(elapsed)) { g_App.gameSounds().play(snd::TIMEBOMB); } @@ -312,11 +306,17 @@ return false; } +/** + * Calculate amount of ammo consummed in the elapsed time + * \param elapsed int + * \return bool return true if there is no more ammo + * + */ bool WeaponInstance::consumeAmmoForEnergyShield(int elapsed) { int timeForShot = pWeaponClass_->timeForShot(); shieldTimeUsed_ += elapsed; - if (shieldTimeUsed_ >= timeForShot) { + if (ammo_remaining_ > 0 && shieldTimeUsed_ >= timeForShot) { // here time for shot is the unit of time for spending ammo // there's no time for reloading @@ -356,7 +356,6 @@ void WeaponInstance::activate() { activated_ = true; - shieldTimeUsed_ = 0; } void WeaponInstance::deactivate() { @@ -428,6 +427,11 @@ deactivate(); Explosion::createExplosion(pMission, this, (double)pWeaponClass_->rangeDmg(), pWeaponClass_->damagePerShot()); + } else if (isInstanceOf(Weapon::EnergyShield)) { + pOwner_->setEnergyActivated(true); + shieldTimeUsed_ = 0; + // return now because ammo is decreased in UseEnergyShieldAction + return; } else { // For other weapons, damage are done immediatly because projectile speed // is too high to draw them Modified: freesynd/trunk/src/model/weapon.h =================================================================== --- freesynd/trunk/src/model/weapon.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/model/weapon.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -355,7 +355,6 @@ //! Use weapon void fire(Mission *pMission, ShootableMapObject::DamageInflictType &dmg, int elapsed); -protected: bool consumeAmmoForEnergyShield(int elapsed); protected: Modified: freesynd/trunk/src/model/weaponholder.cpp =================================================================== --- freesynd/trunk/src/model/weaponholder.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/model/weaponholder.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -37,7 +37,6 @@ WeaponHolder::WeaponHolder() { // -1 means no weapon is selected selected_weapon_ = kNoWeaponSelected; - updtPreferedWeapon(); } WeaponHolder::~WeaponHolder() { @@ -126,10 +125,24 @@ selected_weapon_ = n; handleWeaponSelected(pNewWeapon, prevSelectedWeapon); - updtPreferedWeapon(); } } +/** + * Selects the given weapon if it is in the inventory. + * \param weapon The weapon to select + * \return void + * + */ +void WeaponHolder::selectWeapon(const WeaponInstance &weaponToSelect) { + for (uint8 i = 0; i < numWeapons(); ++i) { + if (weaponToSelect.id() == weapons_[i]->id()) { + selectWeapon(i); + return; + } + } +} + /*! * Deselects a selected weapon if any. * Calls onWeaponDeselected(). @@ -141,7 +154,6 @@ wi = weapons_[selected_weapon_]; selected_weapon_ = kNoWeaponSelected; handleWeaponDeselected(wi); - updtPreferedWeapon(); } return wi; @@ -148,41 +160,20 @@ } /*! - * Updates the prefered weapon criteria based on current selection. - */ -void WeaponHolder::updtPreferedWeapon() { - if (selected_weapon_ != kNoWeaponSelected) { - WeaponInstance *wi = weapons_[selected_weapon_]; - prefered_weapon_.desc = WeaponSelectCriteria::kCritPointer; - prefered_weapon_.criteria.wi = wi; - } else { - prefered_weapon_.desc = WeaponSelectCriteria::kCritDamageNonStrict; - prefered_weapon_.criteria.dmg_type = MapObject::dmg_Physical; - } -} - -/*! * Selects a weapon based on given criteria. - * \param pw_to_use The criteria. + * \param criteria The criteria. * \return True if selection has changed */ -bool WeaponHolder::selectRequiredWeapon(WeaponSelectCriteria *pw_to_use) { +bool WeaponHolder::selectRequiredWeapon(const WeaponSelectCriteria &criteria) { WeaponInstance *wi = selectedWeapon(); // pair <rank, indx> std::vector < std::pair<int, int> > found_weapons; uint8 sz = weapons_.size(); - if (!pw_to_use) { - pw_to_use = &prefered_weapon_; - } else if (prefered_weapon_.desc != WeaponHolder::WeaponSelectCriteria::kCritDamageNonStrict) { - // overriding selection to respect users choice - pw_to_use = &prefered_weapon_; - } - bool found = false; - switch (pw_to_use->desc) { + switch (criteria.desc) { case WeaponSelectCriteria::kCritPointer: - if (pw_to_use->criteria.wi == wi) { + if (criteria.criteria.wi == wi) { found = true; } else { for (uint8 i = 0; i < sz; ++i) { @@ -197,7 +188,7 @@ case WeaponSelectCriteria::kCritWeaponType: for (uint8 i = 0; i < sz; ++i) { WeaponInstance *pWI = weapons_[i]; - if (pWI->isInstanceOf(pw_to_use->criteria.wpn_type)) { + if (pWI->isInstanceOf(criteria.criteria.wpn_type)) { if (pWI->usesAmmo()) { if (pWI->ammoRemaining()) { found = true; @@ -216,7 +207,7 @@ for (uint8 i = 0; i < sz; ++i) { WeaponInstance *pWI = weapons_[i]; if (pWI->canShoot() - && pWI->doesDmgStrict(pw_to_use->criteria.dmg_type)) + && pWI->doesDmgStrict(criteria.criteria.dmg_type)) { if (pWI->usesAmmo()) { if (pWI->ammoRemaining()) { @@ -235,7 +226,7 @@ for (uint8 i = 0; i < sz; ++i) { WeaponInstance *pWI = weapons_[i]; if (pWI->canShoot() - && pWI->doesDmgNonStrict(pw_to_use->criteria.dmg_type)) + && pWI->doesDmgNonStrict(criteria.criteria.dmg_type)) { if (pWI->usesAmmo()) { if (pWI->ammoRemaining()) { @@ -250,7 +241,7 @@ } break; case WeaponSelectCriteria::kCritPlayerSelection: - if (pw_to_use->criteria.wi->canShoot()) { + if (criteria.criteria.wi->canShoot()) { // If the selected weapon was a shooting one // select a shooting weapon for the agent, choosing // first a weapon of same type then any shooting weapon @@ -259,7 +250,7 @@ WeaponInstance *pWI = weapons_[i]; if (pWI->canShoot() && pWI->ammoRemaining() > 0) { - if (*pWI == *(pw_to_use->criteria.wi)) { + if (*pWI == *(criteria.criteria.wi)) { found_weapons.clear(); found_weapons.push_back(std::make_pair(pWI->rank(), i)); break; @@ -271,15 +262,6 @@ } } } - } else if (pw_to_use->criteria.wi->isInstanceOf(Weapon::MediKit) && - pw_to_use->apply_to_all) { - for (uint8 i = 0; i < sz; ++i) { - WeaponInstance *pWI = weapons_[i]; - if (pWI->isInstanceOf(Weapon::MediKit) && pWI->ammoRemaining() > 0) { - found_weapons.push_back(std::make_pair(pWI->rank(), i)); - break; - } - } } break; case WeaponSelectCriteria::kCritLoadedShoot: @@ -297,7 +279,7 @@ if (!found_weapons.empty()) { int best_rank = -1; int indx = found_weapons[0].second; - if (pw_to_use->use_ranks) { + if (criteria.use_ranks) { sz = found_weapons.size(); for (uint8 i = 0; i < sz; ++i) { if (best_rank < found_weapons[i].first) { @@ -312,56 +294,34 @@ return found; } -void WeaponHolder::selectNextWeapon() { - int nextWeapon = -1; - WeaponInstance *cur_sel_weapon = weapon(selected_weapon_); +/*! + * Select a weapon for the ped if he has no weapon out. + */ +void WeaponHolder::selectShootingWeaponWithAmmo() { + if (selected_weapon_ == kNoWeaponSelected) { + // Select a loaded weapon for ped + WeaponSelectCriteria crit; + crit.desc = WeaponSelectCriteria::kCritLoadedShoot; + crit.use_ranks = true; + selectRequiredWeapon(crit); + } +} - if (cur_sel_weapon) { - // first, search a weapon of same type with the highest ammo - // don't bother looking for a weapon of same type if current weapon - // is not shooting weapon (for example a Medikit) - if (cur_sel_weapon->canShoot()) { - for (int i = 0; i < numWeapons(); ++i) { - WeaponInstance * wi = weapons_[i]; - if (i != selected_weapon_ && wi->ammoRemaining() - && wi->hasSameTypeAs(*cur_sel_weapon)) - { - if (nextWeapon == -1) - nextWeapon = i; - else { - if (wi->ammoRemaining() - < weapon(nextWeapon)->ammoRemaining()) - { - nextWeapon = i; - } - } - } - } - } +void WeaponHolder::selectShootingWeaponWithSameTypeFirst(WeaponInstance *pLeaderWeapon) { + WeaponSelectCriteria criteria; + criteria.desc = WeaponSelectCriteria::kCritPlayerSelection; + criteria.criteria.wi = pLeaderWeapon; + selectRequiredWeapon(criteria); +} - // Next, search a weapon who can shoot with highest ammo - if (nextWeapon == -1) { - for (int i = 0; i < numWeapons(); ++i) { - WeaponInstance * wi = weapons_[i]; - if (i != selected_weapon_ && wi->canShoot() && wi->ammoRemaining()) - { - if (nextWeapon == -1) - nextWeapon = i; - else { - if (wi->ammoRemaining() - < weapon(nextWeapon)->ammoRemaining()) - { - nextWeapon = i; - } - } - } +void WeaponHolder::selectMedikitOrShield(Weapon::WeaponType weaponType) { + if (weaponType == Weapon::MediKit || weaponType == Weapon::EnergyShield) { + for (uint8 i = 0; i < numWeapons(); ++i) { + WeaponInstance *pWI = weapons_[i]; + if (pWI->isInstanceOf(weaponType) && pWI->ammoRemaining() > 0) { + selectWeapon(i); + break; } } } - - if (nextWeapon == -1) { - selectRequiredWeapon(); - } else { - selectWeapon(nextWeapon); - } } Modified: freesynd/trunk/src/model/weaponholder.h =================================================================== --- freesynd/trunk/src/model/weaponholder.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/model/weaponholder.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -38,40 +38,6 @@ */ class WeaponHolder { public: - struct WeaponSelectCriteria { - union { - //! weapon index from weapons_ in mission_ - uint32 indx; - //! use only this weapon for attack - WeaponInstance *wi; - //! use only this type of weapon - Weapon::WeaponType wpn_type; - //! use weapon that inflicts this type of damage - //! MapObject::DamageType - uint32 dmg_type; - } criteria; - - enum CriteriaType { - kCritNotSet = 0, // No criteria is set - kCritIndex = 1, // indx - kCritPointer = 2, // wi - kCritWeaponType = 3, // wpn_type - kCritDamageStrict = 4, // type == dmg_type - kCritDamageNonStrict = 5, // type & dmg_type != 0 - kCritPlayerSelection = 6, // Manage selection from weapon selector - kCritLoadedShoot = 7 // select weapon who can shoot and has ammo - }; - //! Union descriptor - CriteriaType desc; - bool use_ranks; - /*! - * When in kCritPlayerSelection mode and a medikit was selected for an agent, - * if this field is true, all selected agent will use a medikit. - */ - bool apply_to_all; - }; - -public: //! This constat indicates that there is no weapon selected. static const int kNoWeaponSelected; /*! Defines the maximum number of weapons an agent can carry.*/ @@ -99,6 +65,8 @@ //! Selects the weapon at given index in the inventory void selectWeapon(uint8 n); + //! Selects the weapon in the inventory + void selectWeapon(const WeaponInstance &weaponToSelect); //! Deselects a selected weapon if any WeaponInstance * deselectWeapon(); @@ -109,12 +77,40 @@ ? weapons_[selected_weapon_] : NULL; } - //! Selects a weapon based on the given criteria - bool selectRequiredWeapon(WeaponSelectCriteria *pw_to_use = NULL); - //! Called when a weapon has no ammo to select another one - void selectNextWeapon(); + //! Select any shooting weapon with ammo + void selectShootingWeaponWithAmmo(); + //! Select a shooting weapon of same type or another type if there is no of first type + void selectShootingWeaponWithSameTypeFirst(WeaponInstance *pLeaderWeapon); + void selectMedikitOrShield(Weapon::WeaponType weaponType); protected: + struct WeaponSelectCriteria { + union { + //! weapon index from weapons_ in mission_ + uint32 indx; + //! use only this weapon for attack + WeaponInstance *wi; + //! use only this type of weapon + Weapon::WeaponType wpn_type; + //! use weapon that inflicts this type of damage + //! MapObject::DamageType + uint32 dmg_type; + } criteria; + + enum CriteriaType { + kCritPointer = 2, // wi + kCritWeaponType = 3, // wpn_type + kCritDamageStrict = 4, // type == dmg_type + kCritDamageNonStrict = 5, // type & dmg_type != 0 + kCritPlayerSelection = 6, // Manage selection from weapon selector + kCritLoadedShoot = 7 // select weapon who can shoot and has ammo + }; + //! Union descriptor + CriteriaType desc; + //! Search weapon based on the rank attribute + bool use_ranks; + }; + /*! * Called before a weapon is selected to check if weapon can be selected. * \param wi The weapon to select @@ -131,8 +127,9 @@ * \param previousWeapon The previous selected weapon (can be null if no weapon was selected) */ virtual void handleWeaponSelected(WeaponInstance * wi, WeaponInstance * previousWeapon) {} - //! Updates the prefered weapon criteria based on current selection - void updtPreferedWeapon(); + + //! Selects a weapon based on the given criteria + bool selectRequiredWeapon(const WeaponSelectCriteria &criteria); protected: /*! * The list of weapons carried by the holder. Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/ped.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -425,11 +425,6 @@ } } - WeaponInstance *pWeapon = selectedWeapon(); - if (pWeapon && pWeapon->isInstanceOf(Weapon::EnergyShield)) { - pWeapon->animate(elapsed); - } - return update; } @@ -509,24 +504,14 @@ // execute action updated |= pUseWeaponAction_->execute(elapsed, pMission, this); if (pUseWeaponAction_->isFinished()) { - if (selectedWeapon() && selectedWeapon()->ammoRemaining() == 0) { - // when weapon is empty persuaded will drop weapon - if (isPersuaded()) { - // we should be able to suspend as by default it should be a follow action - currentAction_->suspend(this); - PutdownWeaponAction *pDrop = new PutdownWeaponAction(0); - pDrop->setWarnBehaviour(true); - // - pDrop->link(currentAction_); - currentAction_ = pDrop; - } else { - // others will use another weapon - selectNextWeapon(); - } - } // erase action delete pUseWeaponAction_; pUseWeaponAction_ = NULL; + + // then select another weapon maybe + if (selectedWeapon() && selectedWeapon()->ammoRemaining() == 0) { + handleSelectedWeaponHasNoAmmo(); + } } } @@ -533,6 +518,35 @@ return updated; } +void PedInstance::handleSelectedWeaponHasNoAmmo() { + // when weapon is empty persuaded will drop weapon + if (isPersuaded()) { + // we should be able to suspend as by default it should be a follow action + currentAction_->suspend(this); + PutdownWeaponAction *pDrop = new PutdownWeaponAction(0); + pDrop->setWarnBehaviour(true); + // + pDrop->link(currentAction_); + currentAction_ = pDrop; + } else { + // first deselect empty weapon + WeaponInstance *pDeselectedWeapon = deselectWeapon(); + // selection was a shooting weapon so replace with the same type + // or something else + if (pDeselectedWeapon->canShoot()) { + selectShootingWeaponWithSameTypeFirst(pDeselectedWeapon); + } else if (pDeselectedWeapon->isInstanceOf(Weapon::EnergyShield)) { + // Use another energy shield + selectMedikitOrShield(Weapon::EnergyShield); + } else if (pDeselectedWeapon->isInstanceOf(Weapon::MediKit)) { + if (pSelectedWeaponBeforeMedikit_ != NULL) { + selectWeapon(*pSelectedWeaponBeforeMedikit_); + pSelectedWeaponBeforeMedikit_ = NULL; + } + } + } +} + /*! * Return true if : * - is not doing something that prevents him from using weapon @@ -557,6 +571,15 @@ */ void PedInstance::stopUsingWeapon() { if (isUsingWeapon()) { + pUseWeaponAction_->stop(); + } +} + +/*! + * Terminate the current action of using weapon that shoots. + */ +void PedInstance::stopShooting() { + if (isUsingWeapon()&& pUseWeaponAction_->type() == Action::kActTypeShoot) { // stop shooting in case of automatic shooting pUseWeaponAction_->stop(); } @@ -609,6 +632,14 @@ } } +void PedInstance::setEnergyActivated(bool isActivated) { + if (isActivated) { + SET_FLAG(desc_state_, pd_smShieldProtected); + } else { + desc_state_ &= pd_smAll ^ pd_smShieldProtected; + } +} + bool isOnScreen(int scrollX, int scrollY, int x, int y) { return x >= scrollX && y >= scrollY && x < scrollX + GAME_SCREEN_WIDTH - 129 @@ -701,6 +732,7 @@ pUseWeaponAction_ = NULL; panicImmuned_ = false; totalPersuasionPoints_ = 0; + pSelectedWeaponBeforeMedikit_ = NULL; } PedInstance::~PedInstance() @@ -884,12 +916,9 @@ * \param wi The deselected weapon */ void PedInstance::handleWeaponDeselected(WeaponInstance * wi) { - if (wi->isInstanceOf(Weapon::EnergyShield)) { - wi->deactivate(); - } else if (wi->isInstanceOf(Weapon::AccessCard)) { + if (wi->isInstanceOf(Weapon::AccessCard)) { rmEmulatedGroupDef(4, og_dmPolice); } - desc_state_ &= (pd_smAll ^ (pd_smArmed | pd_smNoAmmunition)); if (wi->isInstanceOf(Weapon::Persuadatron)) { behaviour_.handleBehaviourEvent(Behaviour::kBehvEvtPersuadotronDeactivated); @@ -905,17 +934,6 @@ * \param previousWeapon The previous selected weapon (can be null if no weapon was selected) */ void PedInstance::handleWeaponSelected(WeaponInstance * wi, WeaponInstance * previousWeapon) { - if (wi->usesAmmo()) { - if (wi->ammoRemaining() == 0) { - desc_state_ |= pd_smNoAmmunition; - return; - } else { - desc_state_ &= pd_smAll ^ pd_smNoAmmunition; - } - } else { - desc_state_ &= pd_smAll ^ pd_smNoAmmunition; - } - if (wi->doesPhysicalDmg()) desc_state_ |= pd_smArmed; else @@ -923,13 +941,18 @@ switch(wi->getClass()->getType()) { case Weapon::EnergyShield: - wi->activate(); + addActionUseEnergyShield(wi); break; case Weapon::AccessCard: addEmulatedGroupDef(4, og_dmPolice); break; case Weapon::MediKit: - addActionUseMedikit(); + if (previousWeapon != NULL && + previousWeapon->getClass()->canShoot() && + previousWeapon->ammoRemaining() > 0) { + pSelectedWeaponBeforeMedikit_ = previousWeapon; + } + addActionUseMedikit(wi); break; case Weapon::Persuadatron: behaviour_.handleBehaviourEvent(Behaviour::kBehvEvtPersuadotronActivated); Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/ped.h 2017-04-08 06:48:06 UTC (rev 1023) @@ -188,9 +188,8 @@ // of persuader only if persuader shoots at it pd_smSupporter = 0x0004, pd_smEnemyInSight = 0x0008, - // only if all weapon has no ammunition, persuadatron excludes this - // should not be used for hostile_desc_ - pd_smNoAmmunition = 0x0010, + //! Energy shield protects the ped + pd_smShieldProtected = 0x0010, // all non-player controllled peds should have this set pd_smAutoAction = 0x0020, /*! When a mission's objective is to kill a ped and this ped has @@ -341,7 +340,9 @@ //! Adds action to shoot somewhere uint8 addActionShootAt(const WorldPoint &aimedPt); //! Adds action to use medikit - void addActionUseMedikit(); + void addActionUseMedikit(WeaponInstance *pMedikit); + //! Adds action to use Energy Shield + void addActionUseEnergyShield(WeaponInstance *pMedikit); //! Creates and insert a HitAction for the ped void insertHitAction(DamageInflictType &d); @@ -366,8 +367,10 @@ //************************************* //! Return true if ped is currently using a weapon (ie there's an active action) bool isUsingWeapon() { return pUseWeaponAction_ != NULL; } - //! Make the ped stop using weapon (mainly for automatic weapon) + //! Make the ped stop using weapon void stopUsingWeapon(); + //! Make the ped stop using a weapon that shoots + void stopShooting(); //! Update the ped's shooting target void updateShootingTarget(const WorldPoint &aimedPt); //! Adjust aimed point with user accuracy and weapon max range @@ -378,6 +381,10 @@ //! Forces agent to kill himself void commitSuicide(); + //! Return true if ped has activated his energy shield + bool isEnergyShieldActivated() { return IS_FLAG_SET(desc_state_, pd_smShieldProtected); } + void setEnergyActivated(bool status); + //! Return the damage after applying protection of Mod int getRealDamage(ShootableMapObject::DamageInflictType &d); //! Method called when object is hit by a weapon shot. @@ -641,7 +648,7 @@ bool hasAccessCard(); void cpyEnemyDefs(Mmuu32_t &eg_defs) { eg_defs = enemy_group_defs_; } - bool isArmed() { return (desc_state_ & pd_smArmed) != 0; } + bool isArmed() { return selectedWeapon() != NULL; } IPAStim *adrenaline_; IPAStim *perception_; @@ -660,10 +667,17 @@ //! See WeaponHolder::handleWeaponSelected() void handleWeaponSelected(WeaponInstance * wi, WeaponInstance * previousWeapon); + //! Called when a weapon has no ammo to select another one + void handleSelectedWeaponHasNoAmmo(); + //! Returns the number of points an agent must have to persuade a ped of given type uint16 getRequiredPointsToPersuade(PedType type); //! When a ped dies, changes the persuaded owner/persuaded_group relation. void updatePersuadedRelations(Squad *pSquad); + +private: + inline int getClosestDirs(int dir, int& closest, int& closer); + protected: Ped *ped_; @@ -730,9 +744,8 @@ std::set <PedInstance *> persuadedSet_; //! Tells whether the panic can react to panic or not bool panicImmuned_; - -private: - inline int getClosestDirs(int dir, int& closest, int& closer); + //! This field is used to select a weapon after medikit was used + WeaponInstance *pSelectedWeaponBeforeMedikit_; }; #endif Modified: freesynd/trunk/src/pedactions.cpp =================================================================== --- freesynd/trunk/src/pedactions.cpp 2017-03-25 07:43:48 UTC (rev 1022) +++ freesynd/trunk/src/pedactions.cpp 2017-04-08 06:48:06 UTC (rev 1023) @@ -365,6 +365,13 @@ /*! * Adds an action to use the medikit on the owner. */ -void PedInstance::addActionUseMedikit() { - pUseWeaponAction_ = new UseMedikitAction(); +void PedInstance::addActionUseMedikit(WeaponInstance *pMedikit) { + pUseWeaponAction_ = new UseMedikitAction(pMedikit); } + +/*! + * Adds an action to use the energy shield on the owner. + */ +void PedInstance::addActionUseEnergyShield(WeaponInstance *pEnergyShield) { + pUseWeaponAction_ = new UseEnergyShieldAction(pEnergyShield); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-03-19 18:25:58
|
Revision: 1021 http://sourceforge.net/p/freesynd/code/1021 Author: benblan Date: 2017-03-19 18:25:55 +0000 (Sun, 19 Mar 2017) Log Message: ----------- Rework on weapons : gameplaymenu now animate only weapons that have no owner Modified Paths: -------------- freesynd/trunk/src/agent.cpp freesynd/trunk/src/agent.h freesynd/trunk/src/agentmanager.cpp freesynd/trunk/src/agentmanager.h freesynd/trunk/src/app.cpp freesynd/trunk/src/core/gamecontroller.cpp freesynd/trunk/src/core/gamecontroller.h freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/ia/behaviour.cpp freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/maprenderer.cpp freesynd/trunk/src/menus/minimaprenderer.cpp freesynd/trunk/src/mission.cpp freesynd/trunk/src/mission.h freesynd/trunk/src/missionmanager.cpp freesynd/trunk/src/missionmanager.h freesynd/trunk/src/model/shot.cpp freesynd/trunk/src/model/weaponholder.cpp freesynd/trunk/src/model/weaponholder.h freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/weapon.cpp freesynd/trunk/src/weapon.h Modified: freesynd/trunk/src/agent.cpp =================================================================== --- freesynd/trunk/src/agent.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/agent.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -47,10 +47,6 @@ is_alive_ = true; } -Agent::~Agent() { - removeAllWeapons(); -} - bool Agent::saveToFile(PortableFile &file) { // id file.write32(id_); @@ -91,7 +87,7 @@ bool Agent::loadFromFile(PortableFile &infile, const FormatVersion& v) { // if this instance has already been populated reset it clearSlots(); - removeAllWeapons(); + destroyAllWeapons(); // id id_ = infile.read32(); // update counter Modified: freesynd/trunk/src/agent.h =================================================================== --- freesynd/trunk/src/agent.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/agent.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -44,7 +44,7 @@ class Agent : public WeaponHolder, public ModOwner { public: Agent(const char *agent_name, bool male); - ~Agent(); + ~Agent() {} int getId() { return id_;} const char *getName() { return name_.c_str(); } Modified: freesynd/trunk/src/agentmanager.cpp =================================================================== --- freesynd/trunk/src/agentmanager.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/agentmanager.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -118,31 +118,25 @@ agents_.add(NULL); } -AgentManager::~AgentManager() { +void AgentManager::loadAgents() { + // TODO : load names from file +} + +void AgentManager::destroy() { for (int i = 0; i != MAX_AGENT; ++i) { if (agents_.get(i)) { delete agents_.get(i); + agents_.setAt(i, NULL); } } - agents_.clear(); clearSquad(); } -void AgentManager::loadAgents() { - // TODO : load names from file -} - void AgentManager::reset(bool onlyWomen) { nextName_ = 0; // First delete existing agents - clearSquad(); - for (int i = 0; i < MAX_AGENT; i++) { - if (agents_.get(i)) { - delete agents_.get(i); - agents_.setAt(i, NULL); - } - } + destroy(); // Then recreate the first 8 available agents for (size_t i = 0; i < 8; i++) { @@ -160,8 +154,6 @@ void AgentManager::destroyAgentSlot(size_t squadSlot) { Agent *p_agent = squadMember(squadSlot); - p_agent->removeAllWeapons(); - p_agent->clearSlots(); setSquadMember(squadSlot, NULL); for (int inc = 0; inc < AgentManager::MAX_AGENT; inc++) { if (agent(inc) == p_agent) { Modified: freesynd/trunk/src/agentmanager.h =================================================================== --- freesynd/trunk/src/agentmanager.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/agentmanager.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -43,7 +43,7 @@ * Provides methods for managing player's agents and squad. * The Squad is the team of agent selected for a mission. It holds up to 4 agents. * An agent can be selected for a squad but not active : in this case, he will not - * participate + * participate */ class AgentManager { public: @@ -61,8 +61,10 @@ static const size_t kSlot4; AgentManager(); - ~AgentManager(); + ~AgentManager() {} + void destroy(); + void setWeaponManager(WeaponManager *pWeaponManager) { pWeaponManager_ = pWeaponManager; } @@ -94,7 +96,7 @@ * \param n The agent's index in the team (from 0 to 3) * \param a The new agent */ - void setSquadMember(size_t slotId, Agent *pAgent) { + void setSquadMember(size_t slotId, Agent *pAgent) { assert(slotId < kMaxSlot); a_squad_[slotId] = pAgent; } Modified: freesynd/trunk/src/app.cpp =================================================================== --- freesynd/trunk/src/app.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/app.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -79,13 +79,6 @@ App::~App() { } -/*! - * Destory the application. - */ -void App::destroy() { - menus_.destroy(); -} - static void addMissingSlash(string& str) { if (str[str.length() - 1] != '/') str.push_back('/'); } @@ -474,7 +467,7 @@ void App::cheatEquipFancyWeapons() { for (int i = 0; i < AgentManager::MAX_AGENT; i++) { if (g_gameCtrl.agents().agent(i)) { - g_gameCtrl.agents().agent(i)->removeAllWeapons(); + g_gameCtrl.agents().agent(i)->destroyAllWeapons(); #ifdef _DEBUG g_gameCtrl.agents().agent(i)->addWeapon( WeaponInstance::createInstance(g_gameCtrl.weaponManager().getWeapon(Weapon::Minigun))); @@ -489,7 +482,7 @@ g_gameCtrl.agents().agent(i)->addWeapon( WeaponInstance::createInstance(g_gameCtrl.weaponManager().getWeapon(Weapon::Persuadatron))); g_gameCtrl.agents().agent(i)->addWeapon( - WeaponInstance::createInstance(g_gameCtrl.weaponManager().getWeapon(Weapon::Laser))); + WeaponInstance::createInstance(g_gameCtrl.weaponManager().getWeapon(Weapon::EnergyShield))); g_gameCtrl.agents().agent(i)->addWeapon( WeaponInstance::createInstance(g_gameCtrl.weaponManager().getWeapon(Weapon::AccessCard))); #else @@ -582,6 +575,16 @@ return true; } +/*! + * Destroy the application. + */ +void App::destroy() { + game_ctlr_->clearAllListeners(); + menus_.destroy(); + + game_ctlr_->destroy(); +} + void App::waitForKeyPress() { while (running_) { Modified: freesynd/trunk/src/core/gamecontroller.cpp =================================================================== --- freesynd/trunk/src/core/gamecontroller.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/core/gamecontroller.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -36,9 +36,10 @@ agents_.setWeaponManager(&weaponMgr_); } -GameController::~GameController() { - game_listeners_.clear(); - mission_listeners_.clear(); +GameController::~GameController() {} + +void GameController::destroy() { + agents_.destroy(); } bool GameController::reset() { @@ -50,6 +51,11 @@ return true; } +void GameController::clearAllListeners() { + game_listeners_.clear(); + mission_listeners_.clear(); +} + /*! * Adds a listener to the list of listeners for a stream. * \param pListener The listener Modified: freesynd/trunk/src/core/gamecontroller.h =================================================================== --- freesynd/trunk/src/core/gamecontroller.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/core/gamecontroller.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -54,6 +54,9 @@ */ bool reset(); + //! Delete all ressources. Called by App:destroy() + void destroy(); + //************************************* // Event management //************************************* @@ -63,6 +66,8 @@ void removeListener(GameEventListener *pListener, GameEvent::EEventStream stream); //! Sends the event to the listeners void fireGameEvent(GameEvent & evt); + //! Removes all listeners from every stream + void clearAllListeners(); //************************************* // Managers Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/ia/actions.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -567,6 +567,7 @@ pWeapon_->setOwner(pPed); pWeapon_->deactivate(); pPed->addWeapon(pWeapon_); + pMission->removeWeaponOnGround(pWeapon_); setSucceeded(); } Modified: freesynd/trunk/src/ia/behaviour.cpp =================================================================== --- freesynd/trunk/src/ia/behaviour.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/ia/behaviour.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -256,9 +256,9 @@ WeaponInstance *pWeaponFound = NULL; double currentDistance = kMaxRangeForSearchingWeapon; - int numweapons = pMission->numWeapons(); + int numweapons = pMission->numWeaponsOnGround(); for (int32 i = 0; i < numweapons; ++i) { - WeaponInstance *w = pMission->weapon(i); + WeaponInstance *w = pMission->weaponOnGround(i); if (!w->hasOwner() && w->canShoot() && w->ammoRemaining() > 0) { double length = 0; if (pMission->getPathLengthBetween(pPed, w, kMaxRangeForSearchingWeapon, &length) == 0) { Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -371,8 +371,8 @@ for (size_t i = 0; i < mission_->numVehicles(); i++) change |= mission_->vehicle(i)->animate(diff); - for (size_t i = 0; i < mission_->numWeapons(); i++) - change |= mission_->weapon(i)->animate(diff); + for (size_t i = 0; i < mission_->numWeaponsOnGround(); i++) + change |= mission_->weaponOnGround(i)->animate(diff); for (size_t i = 0; i < mission_->numStatics(); i++) change |= mission_->statics(i)->animate(diff, mission_); @@ -585,8 +585,8 @@ } } - for (size_t i = 0; mission_ && i < mission_->numWeapons(); ++i) { - WeaponInstance *w = mission_->weapon(i); + for (size_t i = 0; mission_ && i < mission_->numWeaponsOnGround(); ++i) { + WeaponInstance *w = mission_->weaponOnGround(i); if (w->map() != -1) { Point2D scPt; Modified: freesynd/trunk/src/menus/maprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/maprenderer.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/menus/maprenderer.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -168,8 +168,8 @@ } // weapons - for (size_t i = 0; i < pMission_->numWeapons(); i++) { - WeaponInstance *pWeapon = pMission_->weapon(i); + for (size_t i = 0; i < pMission_->numWeaponsOnGround(); i++) { + WeaponInstance *pWeapon = pMission_->weaponOnGround(i); if (pWeapon->isDrawable() && isObjectInsideDrawingArea(pWeapon, viewport)) { addObjectToDraw(pWeapon); } Modified: freesynd/trunk/src/menus/minimaprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/minimaprenderer.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/menus/minimaprenderer.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -526,9 +526,9 @@ void GamePlayMinimapRenderer::drawWeapons(uint8 * a_minimap) { const size_t weapon_size = 2; - for (size_t i = 0; i < p_mission_->numWeapons(); i++) + for (size_t i = 0; i < p_mission_->numWeaponsOnGround(); i++) { - WeaponInstance * w = p_mission_->weapon(i); + WeaponInstance * w = p_mission_->weaponOnGround(i); // we draw weapons that have no owner ie that are on the ground // and are not destroyed if (w->map() == -1) Modified: freesynd/trunk/src/mission.cpp =================================================================== --- freesynd/trunk/src/mission.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/mission.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -281,17 +281,10 @@ { while (p->numWeapons()) { WeaponInstance *wi = p->removeWeaponAtIndex(0); - std::vector < WeaponInstance * >::iterator it = - weaponsOnGround_.begin(); - while (it != weaponsOnGround_.end() && *it != wi) - it++; - assert(it != weaponsOnGround_.end()); - weaponsOnGround_.erase(it); wi->deactivate(); // auto-reload for pistol if (wi->isInstanceOf(Weapon::Pistol)) wi->reload(); - wi->resetWeaponUsedTime(); pAg->addWeapon(wi); } } @@ -357,7 +350,7 @@ p_squad_->clear(); } -void Mission::addWeapon(WeaponInstance * w) +void Mission::addWeaponToGround(WeaponInstance * w) { for (unsigned int i = 0; i < weaponsOnGround_.size(); i++) { // TODO : check if == operator is used correctly (see == in WeaponInstance) @@ -367,6 +360,14 @@ weaponsOnGround_.push_back(w); } +void Mission::removeWeaponOnGround(WeaponInstance *pWeapon) { + for (unsigned int i = 0; i < weaponsOnGround_.size(); i++) { + if (weaponsOnGround_[i] == pWeapon) { + weaponsOnGround_.erase(weaponsOnGround_.begin() + i); + } + } +} + MapObject * Mission::findObjectWithNatureAtPos(int tilex, int tiley, int tilez, MapObject::ObjectNature *nature, int *searchIndex, bool only) { Modified: freesynd/trunk/src/mission.h =================================================================== --- freesynd/trunk/src/mission.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/mission.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -193,9 +193,10 @@ Vehicle *vehicle(size_t i) { return vehicles_[i]; } void addVehicle(Vehicle *pVehicle) { vehicles_.push_back(pVehicle); } - size_t numWeapons() { return weaponsOnGround_.size(); } - WeaponInstance *weapon(size_t i) { return weaponsOnGround_[i]; } - void addWeapon(WeaponInstance *w); + size_t numWeaponsOnGround() { return weaponsOnGround_.size(); } + WeaponInstance *weaponOnGround(size_t i) { return weaponsOnGround_[i]; } + void addWeaponToGround(WeaponInstance *w); + void removeWeaponOnGround(WeaponInstance *pWeapon); size_t numStatics() { return statics_.size(); } Static *statics(size_t i) { return statics_[i]; } Modified: freesynd/trunk/src/missionmanager.cpp =================================================================== --- freesynd/trunk/src/missionmanager.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/missionmanager.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -329,8 +329,8 @@ memset(di.vindx, 0xFF, 2*64); memset(di.pindx, 0xFF, 2*256); memset(di.driverindx, 0xFF, 2*256); - memset(di.windx, 0xFF, 2*512); + try { createVehicles(level_data, di, p_mission); @@ -402,13 +402,12 @@ if (offset_owner != 0) { offset_owner = (offset_owner - 2) / 92; // 92 = ped data size if (offset_owner > 7 && di.pindx[offset_owner] != 0xFFFF) { - // TODO: still there is a problem of weapons setup + // NOTE: still there is a problem of weapons setup // some police officers can have more then 1 weapon // others none (pacific Rim) pMission->ped(di.pindx[offset_owner])->addWeapon(w); w->setOwner(pMission->ped(di.pindx[offset_owner])); - di.windx[i] = pMission->numWeapons(); - pMission->addWeapon(w); + di.weapons[i] = w; } else { delete w; } @@ -417,9 +416,8 @@ } } else { w->setMap(pMission->mapId()); - w->setOwner(NULL); - di.windx[i] = pMission->numWeapons(); - pMission->addWeapon(w); + di.weapons[i] = w; + pMission->addWeaponToGround(w); } } } @@ -427,6 +425,7 @@ WeaponInstance * MissionManager::create_weapon_instance(const LevelData::Weapons &gamdata) { Weapon::WeaponType wType = Weapon::Unknown; + WeaponInstance *pNewWeapon = NULL; switch (gamdata.sub_type) { case 0x01: @@ -472,20 +471,19 @@ wType = Weapon::EnergyShield; break; default: - wType = Weapon::Unknown; - break; + FSERR(Log::k_FLG_GAME, "Mission", "create_weapon_instance", ("unknown weapon type : %d", gamdata.sub_type)); + return NULL; } Weapon *pWeapon = g_gameCtrl.weaponManager().getWeapon(wType); if (pWeapon) { - WeaponInstance *wi = WeaponInstance::createInstance(pWeapon); - wi->setPosition(gamdata.mapposx[1], gamdata.mapposy[1], + pNewWeapon = WeaponInstance::createInstance(pWeapon); + pNewWeapon->setPosition(gamdata.mapposx[1], gamdata.mapposy[1], READ_LE_UINT16(gamdata.mapposz) >> 7, gamdata.mapposx[0], gamdata.mapposy[0], gamdata.mapposz[0] & 0x7F); - return wi; } - return NULL; + return pNewWeapon; } @@ -669,10 +667,6 @@ } if (p->isOurAgent()) { - // adds all agent's weapons to the mission weapons - for (int wi=0; wi<p->numWeapons(); wi++) { - pMission->addWeapon(p->weapon(wi)); - } // adds the agent to the mission squad pMission->getSquad()->setMember(i, p); } else { @@ -901,12 +895,14 @@ if (bindx >= 0x9562 && bindx < 0xDD62) { bindx -= 0x9562; cindx = bindx / 36; - if ((cindx * 36) == bindx && di.windx[cindx] != 0xFFFF) { - objd = new ObjTakeWeapon(pMission->weapon(di.windx[cindx])); - } else - printf("0x05 incorrect offset"); - } else - printf("0x05 type not matched %X", bindx); + if ((cindx * 36) == bindx && di.weapons[cindx] != NULL) { + objd = new ObjTakeWeapon(di.weapons[cindx]); + } else { + FSERR(Log::k_FLG_GAME, "Mission", "createObjectives", ("Error creating Take Weapon objective(0x05) : incorrect offset %d", cindx)); + } + } else { + FSERR(Log::k_FLG_GAME, "Mission", "createObjectives", ("Error creating Take Weapon objective(0x05) : type not matched %X", bindx)); + } break; case 0x0A: Modified: freesynd/trunk/src/missionmanager.h =================================================================== --- freesynd/trunk/src/missionmanager.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/missionmanager.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -63,7 +63,10 @@ uint16 pindx[256]; // contains indexes for driver's vehicle uint16 driverindx[256]; - uint16 windx[512]; + //uint16 windx[512]; + WeaponInstance * weapons[512]; + + DataIndex() : weapons() {} }; private: Modified: freesynd/trunk/src/model/shot.cpp =================================================================== --- freesynd/trunk/src/model/shot.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/model/shot.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -364,8 +364,8 @@ } // look at all bombs on the ground except the weapon that generated the shot - for (size_t i = 0; i < pMission->numWeapons(); ++i) { - WeaponInstance *w = pMission->weapon(i); + for (size_t i = 0; i < pMission->numWeaponsOnGround(); ++i) { + WeaponInstance *w = pMission->weaponOnGround(i); if (w->isInstanceOf(Weapon::TimeBomb) && w != dmg_.pWeapon && !w->hasOwner() && w->isAlive()) { WorldPoint weaponPosW(w->position()); if (pMission->checkBlockedByTile(originLocW, &weaponPosW, false, dmg_.range) == 1) { Modified: freesynd/trunk/src/model/weaponholder.cpp =================================================================== --- freesynd/trunk/src/model/weaponholder.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/model/weaponholder.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -40,6 +40,10 @@ updtPreferedWeapon(); } +WeaponHolder::~WeaponHolder() { + destroyAllWeapons(); +} + /*! * Adds the givent weapon to the inventory. * Weapon is placed at the end of the inventory. @@ -46,10 +50,10 @@ * \param w The weapon to add */ void WeaponHolder::addWeapon(WeaponInstance *w) { - assert(w); - assert(weapons_.size() < kMaxHoldedWeapons); - w->setDrawable(false); - weapons_.push_back(w); + if (w != NULL && weapons_.size() < kMaxHoldedWeapons) { + w->setDrawable(false); + weapons_.push_back(w); + } } /*! @@ -102,10 +106,9 @@ } /*! - * Removes all weapons from the inventory. - * Caller is responsible for freeing the removed instances. + * Removes and delete all weapons from the inventory. */ -void WeaponHolder::removeAllWeapons() { +void WeaponHolder::destroyAllWeapons() { while (weapons_.size()) delete removeWeaponAtIndex(0); } Modified: freesynd/trunk/src/model/weaponholder.h =================================================================== --- freesynd/trunk/src/model/weaponholder.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/model/weaponholder.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -78,7 +78,7 @@ static const uint8 kMaxHoldedWeapons; WeaponHolder(); - virtual ~WeaponHolder() {} + virtual ~WeaponHolder(); uint8 numWeapons() { return weapons_.size(); } @@ -94,8 +94,8 @@ //! Removes the given weapon from the inventory. void removeWeapon(WeaponInstance *w); - //! Removes all weapons in the inventory - void removeAllWeapons(); + //! Removes and delete all weapons in the inventory + void destroyAllWeapons(); //! Selects the weapon at given index in the inventory void selectWeapon(uint8 n); Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/ped.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -426,6 +426,11 @@ } } + WeaponInstance *pWeapon = selectedWeapon(); + if (pWeapon && pWeapon->isInstanceOf(Weapon::EnergyShield)) { + pWeapon->animate(elapsed); + } + return update; } @@ -533,7 +538,6 @@ * Return true if : * - is not doing something that prevents him from using weapon * - is not already using a weapon - * - has a weapon in hand * - weapon is usable (ie a shooting weapon or a medikit) */ bool PedInstance::canAddUseWeaponAction(WeaponInstance *pWeapon) { @@ -546,9 +550,7 @@ } WeaponInstance *pWi = pWeapon != NULL ? pWeapon : selectedWeapon(); - return (pWi != NULL && - (pWi->canShoot() || pWi->isInstanceOf(Weapon::MediKit)) && - pWi->ammoRemaining() > 0); + return pWi != NULL && pWi->usesAmmo() && pWi->ammoRemaining() > 0; } /*! @@ -582,7 +584,7 @@ int PedInstance::getTimeBetweenShoots(WeaponInstance *pWeapon) { // TODO : Add IPA and mods influence return kDefaultShootReactionTime + - pWeapon->getClass()->timeReload(); + pWeapon->getClass()->reloadTime(); } /*! @@ -871,6 +873,8 @@ // we cas use medikit only if ped is hurt return health() != startHealth() && canAddUseWeaponAction(pNewWeapon); + } else if (pNewWeapon->isInstanceOf(Weapon::EnergyShield)) { + return canAddUseWeaponAction(pNewWeapon); } return true; @@ -956,7 +960,9 @@ if(pWeapon) { pWeapon->setMap(map_); + pWeapon->setDrawable(true); pWeapon->setPosition(pos_); + g_Session.getMission()->addWeaponToGround(pWeapon); } return pWeapon; @@ -983,14 +989,6 @@ } } -void PedInstance::destroyAllWeapons() { - while (!weapons_.empty()) { - WeaponInstance * w = removeWeaponAtIndex(0); - // TODO : Delete weapon - w->setDrawable(false); - } -} - bool PedInstance::wePickupWeapon() { return (state_ & pa_smPickUp) != 0; } @@ -1226,7 +1224,6 @@ } else { setDrawnAnim(PedInstance::ad_NoAnimation); } - destroyAllWeapons(); break; case MapObject::dmg_Explosion: case MapObject::dmg_Burn: @@ -1238,7 +1235,6 @@ // was burning because not enough protected or suicide // so die burning setDrawnAnim(PedInstance::ad_DieBurnAnim); - destroyAllWeapons(); } break; default: Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/ped.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -359,7 +359,6 @@ //************************************* WeaponInstance * dropWeapon(uint8 index); void dropAllWeapons(); - void destroyAllWeapons(); bool wePickupWeapon(); //************************************* Modified: freesynd/trunk/src/weapon.cpp =================================================================== --- freesynd/trunk/src/weapon.cpp 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/weapon.cpp 2017-03-19 18:25:55 UTC (rev 1021) @@ -265,14 +265,12 @@ WeaponInstance::WeaponInstance(Weapon * pWeaponClass, uint16 anId, int remainingAmmo) : ShootableMapObject(anId, -1, MapObject::kNatureWeapon), - bombSoundTimer(pWeaponClass->timeReload()), bombExplosionTimer(pWeaponClass->timeForShot()), + bombSoundTimer(pWeaponClass->reloadTime()), bombExplosionTimer(pWeaponClass->timeForShot()), flamerTimer_(180) { pWeaponClass_ = pWeaponClass; ammo_remaining_ = remainingAmmo == -1 ? pWeaponClass->ammo() : remainingAmmo; - weapon_used_time_ = 0; pOwner_ = NULL; activated_ = false; - time_consumed_ = false; if (pWeaponClass->getType() == Weapon::TimeBomb || pWeaponClass->getType() == Weapon::Flamer) { @@ -289,15 +287,10 @@ if (activated_) { if (isInstanceOf(Weapon::EnergyShield)) { - if (ammo_remaining_ == 0) - return false; - int tm_left = elapsed; - int ammoused = getShots(&tm_left) * pWeaponClass_->ammoPerShot(); - if (ammoused >= ammo_remaining_) { - ammo_remaining_ = 0; - pOwner_->selectNextWeapon(); - } else - ammo_remaining_ -= ammoused; + if (ammo_remaining_ && consumeAmmoForEnergyShield(elapsed)) { + // no more ammo so deselect shield + pOwner_->deselectWeapon(); + } return true; } else if (isInstanceOf(Weapon::TimeBomb)) { if (bombSoundTimer.update(elapsed)) { @@ -309,12 +302,7 @@ fire(g_Session.getMission(), dmg, elapsed); return true; } - time_consumed_ = true; } - - updtWeaponUsedTime(elapsed); - } else if (weapon_used_time_ != 0) { - updtWeaponUsedTime(elapsed); } if (isDrawable()) { @@ -324,6 +312,36 @@ return false; } +bool WeaponInstance::consumeAmmoForEnergyShield(int elapsed) { + int timeForShot = pWeaponClass_->timeForShot(); + shieldTimeUsed_ += elapsed; + + if (shieldTimeUsed_ >= timeForShot) { + // here time for shot is the unit of time for spending ammo + // there's no time for reloading + + int remainingShots = ammo_remaining_ / pWeaponClass_->ammoPerShot(); + if (ammo_remaining_ % pWeaponClass_->ammoPerShot()) { + remainingShots++; + } + + // effective shots is the number of shot we have to do due to elapsed time + int effectiveShots = shieldTimeUsed_ / timeForShot; + shieldTimeUsed_ %= timeForShot; + + if (effectiveShots > remainingShots) { + effectiveShots = remainingShots; + shieldTimeUsed_ = 0; + } + + ammo_remaining_ -= effectiveShots * pWeaponClass_->ammoPerShot(); + if (ammo_remaining_ < 0) { + ammo_remaining_ = 0; + } + } + return ammo_remaining_ == 0; +} + void WeaponInstance::draw(int x, int y) { addOffs(x, y); g_App.gameSprites().drawFrame(pWeaponClass_->anim(), frame_, x, y); @@ -336,87 +354,13 @@ g_App.gameSounds().play(pWeaponClass_->getSound()); } -int WeaponInstance::getShots(int *elapsed, uint32 make_shots) { - int time_for_shot = pWeaponClass_->timeForShot(); - int time_reload = pWeaponClass_->timeReload(); -#if 0 - // TODO: if owner exists these two values should change(IPA, mods) - if (pOwner_) -#endif - // TODO check in weaponinstance animate double consuming of elapsed - int time_full_shot = time_for_shot + time_reload; - int elapsed_l = *elapsed; - *elapsed = 0; - time_consumed_ = true; - if (weapon_used_time_ >= time_for_shot) { - weapon_used_time_ += elapsed_l; - if (weapon_used_time_ >= time_full_shot) { - // reloading after previous shot - weapon_used_time_ -= time_full_shot; - } else { - // reload consumed all time, no time for shooting - return 0; - } - } else - weapon_used_time_ += elapsed_l; - - if (weapon_used_time_ == 0) { - return 0; - } - elapsed_l = 0; - - uint32 shots_can_do = 0xFFFFFFFF; - if (shotProperty() & Weapon::spe_UsesAmmo) { - shots_can_do = ammo_remaining_ / pWeaponClass_->ammoPerShot(); - if (ammo_remaining_ % pWeaponClass_->ammoPerShot()) - shots_can_do++; - } - uint32 shots = weapon_used_time_ / time_full_shot; - weapon_used_time_ %= time_full_shot; - bool adjusted = false; - if (weapon_used_time_ >= time_for_shot) { - shots++; - adjusted = true; - } - // Adjusting time consumed and shots done to ammo - // that can be used - if (shots_can_do < shots) { - if (adjusted) { - shots--; - adjusted = false; - } - if (shots_can_do < shots) { - elapsed_l = time_full_shot * (shots - shots_can_do); - shots = shots_can_do; - } else - elapsed_l = weapon_used_time_; - weapon_used_time_ = 0; - } - - if (make_shots != 0 && shots != 0 && make_shots < shots) { - // we might have some time left here - if (adjusted) - shots--; - if (make_shots < shots) { - *elapsed = time_full_shot * (shots - make_shots) + elapsed_l; - *elapsed += weapon_used_time_; - shots = make_shots; - } else - *elapsed = elapsed_l + weapon_used_time_; - weapon_used_time_ = 0; - } else - *elapsed = elapsed_l; - return shots; -} - void WeaponInstance::activate() { activated_ = true; + shieldTimeUsed_ = 0; } void WeaponInstance::deactivate() { activated_ = false; - if (isInstanceOf(Weapon::TimeBomb)) - weapon_used_time_ = 0; } /*! @@ -514,16 +458,3 @@ fire(g_Session.getMission(), d, 0); } } - -void WeaponInstance::updtWeaponUsedTime(int elapsed) { - if (time_consumed_) { - time_consumed_ = false; - } else if (weapon_used_time_ != 0 ) { - weapon_used_time_ += elapsed; - if (weapon_used_time_ >= (pWeaponClass_->timeForShot() - + pWeaponClass_->timeReload())) - { - weapon_used_time_ = 0; - } - } -} Modified: freesynd/trunk/src/weapon.h =================================================================== --- freesynd/trunk/src/weapon.h 2017-03-18 11:18:10 UTC (rev 1020) +++ freesynd/trunk/src/weapon.h 2017-03-19 18:25:55 UTC (rev 1021) @@ -115,7 +115,7 @@ int ammoPerShot() { return ammo_per_shot_; } int timeForShot() { return time_for_shot_; } - int timeReload() { return time_reload_; } + int reloadTime() { return time_reload_; } bool wasSubmittedToSearch() { return submittedToSearch_; } void submitToSearch() { submittedToSearch_ = true; } @@ -275,12 +275,13 @@ static WeaponInstance *createInstance(Weapon *pWeaponClass, int remainingAmmo = -1); WeaponInstance(Weapon *w, uint16 id, int remainingAmmo = -1); + ~WeaponInstance() {}; + //************************************* + // Properties + //************************************* Weapon *getClass() const { return pWeaponClass_; } - bool isInstanceOf(Weapon::WeaponType weaponType) { return pWeaponClass_->getType() == weaponType; } - bool hasSameTypeAs(const WeaponInstance & otherWeapon) { return pWeaponClass_->getType() == otherWeapon.getClass()->getType();} - /*! Sets the owner of the weapon. */ void setOwner(PedInstance *pOwner) { pOwner_ = pOwner; } /*! Return the owner of the weapon.*/ @@ -289,36 +290,19 @@ bool hasOwner() { return pOwner_ != NULL; } int ammoRemaining() { return ammo_remaining_; } - void reload() { ammo_remaining_ = pWeaponClass_->ammo(); } - bool animate(int elapsed); - void draw(int x, int y); - + const char * name() { return pWeaponClass_->getName(); } int range() { return pWeaponClass_->range(); } int ammo() { return pWeaponClass_->ammo(); } int rank() { return pWeaponClass_->rank(); } + int getWeight() { return pWeaponClass_->weight(); } uint32 shotProperty() { return pWeaponClass_->shotProperty(); } - const char * name() { return pWeaponClass_->getName(); } - Weapon::WeaponAnimIndex index() { return pWeaponClass_->index(); } - bool operator==(WeaponInstance wi) { - // TODO : check if this method is necessary - return hasSameTypeAs(wi); + bool usesAmmo() { + return (shotProperty() & Weapon::spe_UsesAmmo) != 0; } - //! Plays the weapon's sound. - void playSound(); - - void resetWeaponUsedTime() { weapon_used_time_ = 0; } - - int getShots(int *elapsed = NULL, uint32 make_shots = 0); - - void activate(); - void deactivate(); - - void handleHit(ShootableMapObject::DamageInflictType & d); - bool canShoot() { return pWeaponClass_->canShoot(); } @@ -327,14 +311,6 @@ return pWeaponClass_->doesPhysicalDmg(); } - bool needsReloading() { - return pWeaponClass_->ammo() > ammo_remaining_; - } - - bool usesAmmo() { - return (shotProperty() & Weapon::spe_UsesAmmo) != 0; - } - bool doesDmgStrict(uint32 dmg_type) { return pWeaponClass_->dmgType() == dmg_type; } @@ -344,35 +320,58 @@ MapObject::DamageType dmgType() { return pWeaponClass_->dmgType(); } - int getWeight() { return pWeaponClass_->weight(); } - void updtWeaponUsedTime(int elapsed); + //************************************* + // Behaviour + //************************************* + bool isInstanceOf(Weapon::WeaponType weaponType) { return pWeaponClass_->getType() == weaponType; } + bool hasSameTypeAs(const WeaponInstance & otherWeapon) { return pWeaponClass_->getType() == otherWeapon.getClass()->getType();} + + bool needsReloading() { + return pWeaponClass_->ammo() > ammo_remaining_; + } + + void reload() { ammo_remaining_ = pWeaponClass_->ammo(); } + + bool operator==(WeaponInstance wi) { + // TODO : check if this method is necessary + return hasSameTypeAs(wi); + } + + //! Plays the weapon's sound. + void playSound(); + + void activate(); + void deactivate(); + + bool animate(int elapsed); + void draw(int x, int y); + + void handleHit(ShootableMapObject::DamageInflictType & d); + //! Use weapon void fire(Mission *pMission, ShootableMapObject::DamageInflictType &dmg, int elapsed); protected: + bool consumeAmmoForEnergyShield(int elapsed); + +protected: static uint16 weaponIdCnt; Weapon *pWeaponClass_; /*! Owner of the weapon.*/ PedInstance *pOwner_; int ammo_remaining_; - /*! if this value is smaller time_for_shot_ shot cannot be done - * if is greater then time_for_shot_ reload is in execution - * if is greater then time_for_shot_ + time_reload_ then full shot is done - * */ - int weapon_used_time_; - // used for timebomb sound effect + /*! used for timebomb sound effect.*/ fs_utils::Timer bombSoundTimer; /*! Timer used for bomb explosion.*/ fs_utils::Timer bombExplosionTimer; /*! Timer used for rotating flamer direction.*/ fs_utils::Timer flamerTimer_; + /*! counter for tracking time for ammo consumption for shields.*/ + int shieldTimeUsed_; + /*! TimeBomb, Shield are activated on specific events.*/ bool activated_; - /*! used to avoid double consuming of same elapsed time, - * if ped shoots, time is consumed and should not be reused by weapon, - * NOTE: ped animate executed before weapon animate - */ - bool time_consumed_; + FlamerShot *pFlamerShot_; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-03-11 19:05:52
|
Revision: 1019 http://sourceforge.net/p/freesynd/code/1019 Author: benblan Date: 2017-03-11 19:05:49 +0000 (Sat, 11 Mar 2017) Log Message: ----------- - Fix some compilation warnings - When player agents shoot on a vehicle, the driver is ejected Modified Paths: -------------- freesynd/trunk/NEWS freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/ia/behaviour.cpp freesynd/trunk/src/ia/behaviour.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/model/vehicle.cpp freesynd/trunk/src/pedactions.cpp Modified: freesynd/trunk/NEWS =================================================================== --- freesynd/trunk/NEWS 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/NEWS 2017-03-11 19:05:49 UTC (rev 1019) @@ -17,6 +17,7 @@ ---------- * Trains now moves and player agents can get on/off * Persuaded peds follow their leader in cars and trains + * When player agents shoot on a vehicle, the driver is ejected Known issues with this release ------------------------------ Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/src/ia/actions.cpp 2017-03-11 19:05:49 UTC (rev 1019) @@ -761,10 +761,8 @@ } bool FireWeaponAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) { - if (shootType_ == ShootAction::kShootActionSingleShoot) { - if (!pPed->isUsingWeapon()) { - setSucceeded(); - } + if (!pPed->isUsingWeapon()) { + setSucceeded(); } return true; Modified: freesynd/trunk/src/ia/behaviour.cpp =================================================================== --- freesynd/trunk/src/ia/behaviour.cpp 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/src/ia/behaviour.cpp 2017-03-11 19:05:49 UTC (rev 1019) @@ -120,6 +120,8 @@ doRegenerates_ = true; } break; + default: + break; } } @@ -151,6 +153,9 @@ break; case Behaviour::kBehvEvtPersuadotronDeactivated: doUsePersuadotron_ = false; + break; + default: + break; } } @@ -314,8 +319,14 @@ } switch(evtType) { + case Behaviour::kBehvEvtEjectedFromVehicle: + // reacting to ejection from vehicle is the same as when a gun is out + // -> panic! + pCivil->destroyAllActions(true); + pCivil->addToDefaultActions(new WalkToDirectionAction()); case Behaviour::kBehvEvtWeaponOut: - if (!isEnabled()) { + // civilian in cars do not panic + if (pCivil->inVehicle() == NULL && !isEnabled()) { setEnabled(true); status_ = kPanicStatusAlert; } @@ -339,6 +350,8 @@ backFromPanic_ = true; } break; + default: + break; } } @@ -385,23 +398,17 @@ PoliceBehaviourComponent::PoliceBehaviourComponent(): BehaviourComponent(), scoutTimer_(200) { - status_ = kPoliceStatusOnPatrol; + status_ = kPoliceStatusDefault; pTarget_ = NULL; } void PoliceBehaviourComponent::execute(int elapsed, Mission *pMission, PedInstance *pPed) { if (status_ == kPoliceStatusAlert && scoutTimer_.update(elapsed)) { - PedInstance *pArmedGuy = findArmedPedNotPolice(pMission, pPed); - if (pArmedGuy != NULL) { - status_ = kPoliceStatusFollowAndShoot; - followAndShootTarget(pPed, pArmedGuy); - } - } else if (status_ == kPoliceStatusCheckForDefault) { + findAndEngageNewTarget(pMission, pPed); + } else if (status_ == kPoliceStatusCheckReengageOrDefault) { // check if there is a nearby enemy - if (findArmedPedNotPolice(pMission, pPed) != NULL) { - status_ = kPoliceStatusAlert; - scoutTimer_.setToMax(); // don't waste time waiting - } else if (!pPed->isCurrentActionFromSource(Action::kActionDefault)) { + bool foundNewTarget = findAndEngageNewTarget(pMission, pPed); + if ( !foundNewTarget && !pPed->isCurrentActionFromSource(Action::kActionDefault)) { // there is no one around so go back to patrol if it's not already the case pPed->deselectWeapon(); pPed->setCurrentActionWithSource(Action::kActionDefault); @@ -409,7 +416,7 @@ // There are still some armed peds so keep on alert status_ = kPoliceStatusAlert; } else { - status_ = kPoliceStatusOnPatrol; + status_ = kPoliceStatusDefault; } } } @@ -417,8 +424,11 @@ void PoliceBehaviourComponent::handleBehaviourEvent(PedInstance *pPed, Behaviour::BehaviourEvent evtType, void *pCtxt) { switch(evtType) { + case Behaviour::kBehvEvtEjectedFromVehicle: + handleEjectionFromVehicle(pPed, pCtxt); + break; case Behaviour::kBehvEvtWeaponOut: - if (status_ == kPoliceStatusOnPatrol && !pPed->inVehicle()) { + if (status_ == kPoliceStatusDefault && !pPed->inVehicle()) { // When someone get his weapon out, police is on alert status_ = kPoliceStatusAlert; } @@ -425,28 +435,59 @@ break; case Behaviour::kBehvEvtWeaponCleared: // our target has dropped his weapon - if (pTarget_ == pCtxt) { - if (status_ == kPoliceStatusFollowAndShoot) { - status_ = kPoliceStatusPendingEndFollow; - pPed->stopUsingWeapon(); - // just wait a few time before engaging another target or simply - // continue with default behavior - WaitAction *pWait = new WaitAction(WaitAction::kWaitWeapon, kPolicePendingTime); - pWait->setWarnBehaviour(true); - pPed->addMovementAction(pWait, false); - } - } else if (status_ != kPoliceStatusFollowAndShoot) { - status_ = kPoliceStatusCheckForDefault; + if (status_ == kPoliceStatusFollowAndShootTarget && pTarget_ == pCtxt) { + status_ = kPoliceStatusPendingEndFollow; + pPed->stopUsingWeapon(); + + // just wait a few time before engaging another target or simply + // continue with default behavior + WaitAction *pWait = new WaitAction(WaitAction::kWaitWeapon, kPolicePendingTime); + pWait->setWarnBehaviour(true); + pPed->addMovementAction(pWait, false); + } else if (status_ == kPoliceStatusAlert) { + status_ = kPoliceStatusCheckReengageOrDefault; } break; case Behaviour::kBehvEvtActionEnded: - // We are at the end of waiting period so check if we need to engage right now - // of if we can go back on patrol - status_ = kPoliceStatusCheckForDefault; + { + Action::ActionType *pType = static_cast<Action::ActionType *> (pCtxt); + if (*pType == Action::kActTypeWait) { + // We are at the end of waiting period so check if we need to engage right now + // of if we can go back on patrol + status_ = kPoliceStatusCheckReengageOrDefault; + } else { + status_ = kPoliceStatusAlert; + } + } + break; + default: + break; } } +void PoliceBehaviourComponent::handleEjectionFromVehicle(PedInstance *pPed, void *pCtxt) { + pPed->destroyAllActions(true); + pPed->addToDefaultActions(new WalkToDirectionAction()); + PedInstance *pShooter = static_cast<PedInstance *>(pCtxt); + pPed->setDirectionTowardObject(*pShooter); + // Add a walk action just to get away from the vehicle so that the ped can shoot + // without being blocked by the vehicle + WalkToDirectionAction *outOfCarAction = new WalkToDirectionAction(); + outOfCarAction->setMaxDistanceToWalk(20); + outOfCarAction->setWarnBehaviour(true); + pPed->addMovementAction(outOfCarAction, true); + status_ = kPoliceStatusOutOfVehicle; +} + +bool PoliceBehaviourComponent::findAndEngageNewTarget(Mission *pMission, PedInstance *pPed) { + PedInstance *pArmedGuy = findArmedPedNotPolice(pMission, pPed); + if (pArmedGuy != NULL) { + followAndShootTarget(pPed, pArmedGuy); + } + return pArmedGuy != NULL; +} + /*! * Return a ped that has his weapon out and is not a police man and is close to this policeman. */ @@ -462,6 +503,7 @@ void PoliceBehaviourComponent::followAndShootTarget(PedInstance *pPed, PedInstance *pArmedGuy) { pTarget_ = pArmedGuy; + status_ = kPoliceStatusFollowAndShootTarget; // Set new actions if (pPed->altAction() == NULL) { // the first time Modified: freesynd/trunk/src/ia/behaviour.h =================================================================== --- freesynd/trunk/src/ia/behaviour.h 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/src/ia/behaviour.h 2017-03-11 19:05:49 UTC (rev 1019) @@ -60,7 +60,9 @@ //! An action has ended kBehvEvtActionEnded, //! An agent is getting into a vehicle so do his persuadeds - kBehvEvtEnterVehicle + kBehvEvtEnterVehicle, + //! Car driver has been shot so he is ejected from the car + kBehvEvtEjectedFromVehicle, }; virtual ~Behaviour(); @@ -234,6 +236,9 @@ void handleBehaviourEvent(PedInstance *pPed, Behaviour::BehaviourEvent evtType, void *pCtxt); private: + void handleEjectionFromVehicle(PedInstance *pPed, void *pCtxt); + //! Find a nearby armed Ped and follow and shoot him + bool findAndEngageNewTarget(Mission *pMission, PedInstance *pPed); //! Checks whether there is an armed ped next to the ped : returns that ped PedInstance * findArmedPedNotPolice(Mission *pMission, PedInstance *pPed); //! Initiate the process of following and shooting at a target @@ -245,16 +250,18 @@ * Status of police behaviour. */ enum PoliceStatus { - //! Default status - kPoliceStatusOnPatrol, + //! Police is walking or driving car + kPoliceStatusDefault, //! Search for someone who pulled his gun kPoliceStatusAlert, //! Move closer from target to shoot at him - kPoliceStatusFollowAndShoot, + kPoliceStatusFollowAndShootTarget, //! When target drops his weapon, wait some time kPoliceStatusPendingEndFollow, //! after waiting, check if police should go on patrol again - kPoliceStatusCheckForDefault + kPoliceStatusCheckReengageOrDefault, + //! Police ped is going away from vehicle + kPoliceStatusOutOfVehicle }; PoliceStatus status_; Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2017-03-11 19:05:49 UTC (rev 1019) @@ -1357,11 +1357,14 @@ void GameplayMenu::updateMarkersPosition() { for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { if (mission_->sfxObjects(i + 4)->isDrawable()) { - TilePoint agentPos = mission_->getSquad()->member(i)->position(); - agentPos.ox -= 16; - agentPos.oz += 256; + PedInstance *pAgent = mission_->getSquad()->member(i); + if (pAgent != NULL && pAgent->isAlive()) { + TilePoint agentPos = pAgent->position(); + agentPos.ox -= 16; + agentPos.oz += 256; - mission_->sfxObjects(i + 4)->setPosition(agentPos); + mission_->sfxObjects(i + 4)->setPosition(agentPos); + } } } } Modified: freesynd/trunk/src/model/vehicle.cpp =================================================================== --- freesynd/trunk/src/model/vehicle.cpp 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/src/model/vehicle.cpp 2017-03-11 19:05:49 UTC (rev 1019) @@ -816,8 +816,17 @@ } Explosion::createExplosion(g_Session.getMission(), this, 512.0); - } else {// NOTE: maybe reduce speed on hit? - // TODO: let passengers know that vehicle is attacked + } else if (pDriver_ != NULL && !pDriver_->isOurAgent()) { + // in case the car is drived by someone else than our agents + // and one of our agent shot the car then + // the driver is ejected from the car + // Usually he is alone in the car so don't bother with any passengers + PedInstance *pShooter = dynamic_cast<PedInstance *>(d.d_owner); + if (pShooter && pShooter->isOurAgent()) { + PedInstance *pPed = pDriver_; + dropPassenger(pPed); + pPed->behaviour().handleBehaviourEvent(Behaviour::kBehvEvtEjectedFromVehicle, pShooter); + } } } Modified: freesynd/trunk/src/pedactions.cpp =================================================================== --- freesynd/trunk/src/pedactions.cpp 2017-02-25 15:21:49 UTC (rev 1018) +++ freesynd/trunk/src/pedactions.cpp 2017-03-11 19:05:49 UTC (rev 1019) @@ -170,18 +170,16 @@ * \param source */ void PedInstance::resetActions(Action::ActionSource source) { - MovementAction *pAction = (source == Action::kActionDefault) ? + currentAction_ = (source == Action::kActionDefault) ? defaultAction_ : altAction_; - if (pAction) { + if (currentAction_) { // reset all scripted actions - MovementAction *pActionToReset = pAction; + MovementAction *pActionToReset = currentAction_; while (pActionToReset != NULL) { pActionToReset->reset(); pActionToReset = pActionToReset->next(); } - - currentAction_ = pAction; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-02-06 15:13:58
|
Revision: 1015 http://sourceforge.net/p/freesynd/code/1015 Author: benblan Date: 2017-02-06 15:13:56 +0000 (Mon, 06 Feb 2017) Log Message: ----------- - Train movement implementation #1 - Remove unused variable in MapRenderer - Renamed some method for clarity Modified Paths: -------------- freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/ia/actions.h freesynd/trunk/src/mapobject.cpp freesynd/trunk/src/mapobject.h freesynd/trunk/src/menus/maprenderer.h freesynd/trunk/src/missionmanager.cpp freesynd/trunk/src/model/train.cpp freesynd/trunk/src/model/train.h freesynd/trunk/src/model/vehicle.cpp freesynd/trunk/src/model/vehicle.h freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/pedpathfinding.cpp Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/ia/actions.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -30,6 +30,7 @@ #include "ped.h" #include "weapon.h" #include "model/vehicle.h" +#include "model/train.h" #include "mission.h" #include "agentmanager.h" #include "core/squad.h" @@ -250,7 +251,7 @@ * \param pPed The ped executing the action. */ bool WalkAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) { - bool updated = pPed->updatePosition(elapsed, pMission); + bool updated = pPed->doMove(elapsed, pMission); if (!pPed->hasDestination()) { // Ped has arrived at destination setSucceeded(); @@ -434,7 +435,7 @@ pPed->clearDestination(); pPed->leaveState(targetState_); } else { - updated = pPed->updatePosition(elapsed, pMission); + updated = pPed->doMove(elapsed, pMission); } } @@ -509,7 +510,7 @@ setSucceeded(); pPed->clearDestination(); } else { - updated = pPed->updatePosition(elapsed, pMission); + updated = pPed->doMove(elapsed, pMission); } } @@ -617,13 +618,36 @@ return true; } +DriveTrainAction::DriveTrainAction(TrainHead *pTrain, const TilePoint &dest) : + MovementAction(kActTypeUndefined, false, true) { + pTrain_ = pTrain; + dest_ = dest; +} + +void DriveTrainAction::doStart(Mission *pMission, PedInstance *pPed) { + if (!pTrain_->containsPed(pPed)) { + setFailed(); + } + + if (!pTrain_->initMovementToDestination(pMission, dest_, 1024)) { + setFailed(); + } +} + +bool DriveTrainAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) { + if (!pTrain_->hasDestination()) { + setSucceeded(); + } + return true; +} + WaitAction::WaitAction(WaitEnum waitFor, uint32 duration) : -MovementAction(kActTypeWait, true), waitTimer_(duration) { +MovementAction(kActTypeWait, true, true), waitTimer_(duration) { waitType_ = waitFor; } WaitAction::WaitAction(WaitEnum waitFor) : -MovementAction(kActTypeWait, true), waitTimer_(0) { +MovementAction(kActTypeWait, true, true), waitTimer_(0) { waitType_ = waitFor; } Modified: freesynd/trunk/src/ia/actions.h =================================================================== --- freesynd/trunk/src/ia/actions.h 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/ia/actions.h 2017-02-06 15:13:56 UTC (rev 1015) @@ -33,6 +33,7 @@ class WeaponInstance; class Vehicle; class GenericCar; +class TrainHead; /*! @@ -469,6 +470,23 @@ }; /*! + * This action is used to drive a train to a point. + */ +class DriveTrainAction : public MovementAction { +public: + DriveTrainAction(TrainHead *pTrain, const TilePoint &dest); + +protected: + void doStart(Mission *pMission, PedInstance *pPed); + bool doExecute(int elapsed, Mission *pMission, PedInstance *pPed); +protected: + /*! Train to drive.*/ + TrainHead *pTrain_; + /*! Destination point.*/ + TilePoint dest_; +}; + +/*! * This action is used to make a ped wait. */ class WaitAction : public MovementAction { Modified: freesynd/trunk/src/mapobject.cpp =================================================================== --- freesynd/trunk/src/mapobject.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/mapobject.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -583,11 +583,11 @@ * \param nOffX amount to add to offX * \param nOffY amount to add to offY */ -bool ShootableMovableMapObject::updatePlacement(int nOffX, int nOffY) +bool ShootableMovableMapObject::addOffsetToPosition(int nOffX, int nOffY) { - pos_.ox = nOffX; - pos_.oy = nOffY; + pos_.ox += nOffX; + pos_.oy += nOffY; bool changed = false; while (pos_.ox < 0) { Modified: freesynd/trunk/src/mapobject.h =================================================================== --- freesynd/trunk/src/mapobject.h 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/mapobject.h 2017-02-06 15:13:56 UTC (rev 1015) @@ -80,6 +80,8 @@ return map_ != -1; } + int map() { return map_; } + void setMap(int new_map) { map_ = new_map; } virtual void draw(int x, int y) = 0; enum DamageType { @@ -158,9 +160,6 @@ void setSizeY(int size_y) { size_y_ = size_y;} void setSizeZ(int size_z) { size_z_ = size_z;} - virtual int map() { return map_; } - void setMap(int new_map) { map_ = new_map; } - /*! * */ @@ -541,7 +540,7 @@ * \return True if the position has been updated. * */ - virtual bool updatePosition(int elapsed, Mission *m) = 0; + virtual bool doMove(int elapsed, Mission *m) = 0; //! Return true if the ped is moving bool isMoving() { return speed_ != 0 || !dest_path_.empty();} @@ -551,12 +550,13 @@ FreeWay hold_on_; protected: + bool addOffsetToPosition(int nOffX, int nOffY); + +protected: int speed_, base_speed_; //! on reaching this distance object should stop int dist_to_pos_; std::list<TilePoint> dest_path_; - - bool updatePlacement(int nOffX, int nOffY); }; /*! Modified: freesynd/trunk/src/menus/maprenderer.h =================================================================== --- freesynd/trunk/src/menus/maprenderer.h 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/menus/maprenderer.h 2017-02-06 15:13:56 UTC (rev 1015) @@ -176,15 +176,6 @@ Map *pMap_; SquadSelection *pSelection_; - std::vector<Vehicle *> cache_vehicles_; - std::vector<PedInstance *> cache_peds_; - std::vector<WeaponInstance *> cache_weapons_; - std::vector<Static *> cache_statics_; - std::vector<SFXObject *> cache_sfx_objects_; - - std::set<int> fast_vehicle_cache_, fast_ped_cache_, fast_weapon_cache_, - fast_statics_cache_, fast_sfx_objects_cache_; - Pool<ObjectToDraw> pool_; /*! This map contains for each tile the list of objects to draw.*/ std::map<int, ObjectToDraw *> objectsByTile_; Modified: freesynd/trunk/src/missionmanager.cpp =================================================================== --- freesynd/trunk/src/missionmanager.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/missionmanager.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -490,6 +490,7 @@ void MissionManager::createVehicles(const LevelData::LevelDataAll &level_data, DataIndex &di, Mission *pMission) { + TrainHead *pTrainHead = NULL; for (uint16 i = 0; i < 64; i++) { const LevelData::Cars & car = level_data.cars[i]; // car.sub_type 0x09 - train @@ -505,6 +506,17 @@ { di.driverindx[(car.offset_of_driver - 2) / 92] = di.vindx[i]; } + + if (v->getType() == Vehicle::kVehicleTypeTrainHead) { + TrainHead *pHead = dynamic_cast<TrainHead *>(v); + if (pTrainHead == NULL) { + pTrainHead = pHead; + } else { + pTrainHead->appendTrainBody(pHead); + } + } else if (v->getType() == Vehicle::kVehicleTypeTrainBody) { + pTrainHead->appendTrainBody(dynamic_cast<TrainBody *>(v)); + } } } } @@ -523,10 +535,10 @@ Vehicle *pVehicle = NULL; if (gamdata.sub_type == Vehicle::kVehicleTypeTrainHead) { LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Head %d", id)) - pVehicle = new TrainHead(id, Vehicle::kVehicleTypeTrainHead, vehicleanim); + pVehicle = new TrainHead(id, Vehicle::kVehicleTypeTrainHead, vehicleanim, hp); } else if (gamdata.sub_type == Vehicle::kVehicleTypeTrainBody) { LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Body %d", id)) - pVehicle = new TrainBody(id, Vehicle::kVehicleTypeTrainHead, vehicleanim); + pVehicle = new TrainBody(id, Vehicle::kVehicleTypeTrainBody, vehicleanim, hp); } else { // standard car LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create generic car %d", id)) @@ -719,8 +731,9 @@ GenericCar *pCar = dynamic_cast<GenericCar *>(v); pPed->addToDefaultActions(new DriveVehicleAction(pCar, locT)); } else { - LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train %d to (%d, %d, %d) (%d, %d)", v->id(), locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) - // TODO : add drive train action + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train (a) %d to (%d, %d, %d) (%d, %d)", v->id(), locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) + TrainHead *pTrain = dynamic_cast<TrainHead *>(v); + pPed->addToDefaultActions(new DriveTrainAction(pTrain, locT)); } } else { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Walk toward location (%d, %d, %d)", locT.tx, locT.ty, locT.tz)) @@ -752,7 +765,8 @@ pPed->addToDefaultActions( new DriveVehicleAction(pCar, v->position())); } else { - LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train %d to (%d, %d, %d) (%d, %d)", v->id(), v->tileX(), v->tileY(), v->tileZ(), v->offX(), v->offY())) + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train (b) %d to (%d, %d, %d) (%d, %d)", v->id(), v->tileX(), v->tileY(), v->tileZ(), v->offX(), v->offY())) + // NOTE : this action is redundant with action of type 1 } } } else if (sc.type == LevelData::kScenarioTypeEscape) { @@ -763,6 +777,10 @@ pPed->addToDefaultActions(new ResetScriptedAction(Action::kActionDefault)); } else if (sc.type == 10) { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" scenario type 10")) + if (offset_nxt == 0) { + // on the last action, add a reset + pPed->addToDefaultActions(new ResetScriptedAction(Action::kActionDefault)); + } } else { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - unknown type %d", sc.type)) } Modified: freesynd/trunk/src/model/train.cpp =================================================================== --- freesynd/trunk/src/model/train.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/model/train.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -1,28 +1,111 @@ #include "train.h" -TrainHead::TrainHead(uint16 anId, uint8 aType, VehicleAnimation *pAnimation) : TrainBody(anId, aType, pAnimation) { +TrainBody::TrainBody(uint16 anId, uint8 aType, VehicleAnimation *pAnimation, int startHp) : + Vehicle(anId, aType, -1, pAnimation) { + + setHealth(startHp); + setStartHealth(startHp); + + pNextBody_ = NULL; } -TrainHead::~TrainHead() { +TrainBody::~TrainBody() { +} +void TrainBody::changeTrainAndPassengersPosition(int distanceX, int distanceY) { + addOffsetToPosition(distanceX, distanceY); + + if (!passengers_.empty()) { + for (std::set<PedInstance *>::iterator it = passengers_.begin(); + it != passengers_.end(); it++ + ) { + (*it)->setPosition(pos_); + } + } + + if (pNextBody_ != NULL) { + pNextBody_->changeTrainAndPassengersPosition(distanceX, distanceY); + } } -bool TrainHead::animate(int elapsed) { - return false; +TrainHead::TrainHead(uint16 anId, uint8 aType, VehicleAnimation *pAnimation, int startHp) : + TrainBody(anId, aType, pAnimation, startHp) { + moveOnXaxis_ = true; } -TrainBody::TrainBody(uint16 anId, uint8 aType, VehicleAnimation *pAnimation) : Vehicle(anId, aType, -1, pAnimation) { +TrainHead::~TrainHead() { } -TrainBody::~TrainBody() { +//! Set the destination to reach at given speed +bool TrainHead::initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed) { + clearDestination(); + + dest_path_.push_front(destinationPt); + speed_ = newSpeed; + + moveOnXaxis_ = (destinationPt.ty == pos_.ty); + return true; } /*! * Moves a vehicle on the map. * \param elapsed Elapsed time sine last frame. */ -bool TrainBody::updatePosition(int elapsed, Mission *m) +bool TrainHead::doMove(int elapsed, Mission *m) { - return false; + bool updated = false; + int remainingTime = elapsed; + + while ((!dest_path_.empty()) && remainingTime != 0) { + + // Get distance between vehicle and next NodePath + WorldPoint destination(dest_path_.front()); + + double distanceToNextNode = distanceToPosition(destination); + // This is the time for all the remaining distance to the next node in the path + double availableTimeToNextNode = (distanceToNextNode / (double)speed_) * 1000.0; + // We cannot spend more time than the time remaining + if (availableTimeToNextNode > remainingTime) + availableTimeToNextNode = remainingTime; + + // computes distance travelled by vehicle in the available time + WorldPoint currentPos(pos_); + int distanceX = 0, distanceY = 0; + if (isMovementOnXAxis()) { + int diffx = destination.x - currentPos.x; + distanceX = (int)((diffx * (speed_ * availableTimeToNextNode) / distanceToNextNode) / 1000); + } else { + int diffy = destination.y - currentPos.y; + distanceY = (int)((diffy * (speed_ * availableTimeToNextNode) / distanceToNextNode) / 1000); + } + + // Updates the remaining time + remainingTime -= availableTimeToNextNode; + + // Moves vehicle + changeTrainAndPassengersPosition(distanceX, distanceY); + + stopIfDestinationReached(destination); + + updated = true; + } + + return updated; } + +void TrainHead::stopIfDestinationReached(const WorldPoint &destinationPt) { + WorldPoint currentPos(pos_); + if(abs(destinationPt.y - currentPos.y) < 4) { + dest_path_.pop_front(); + speed_ = 0; + } +} + +void TrainHead::appendTrainBody(TrainBody *pTrainBodyToAdd) { + TrainBody *pBody = this; + while (pBody->getNext() != NULL) { + pBody = pBody->getNext(); + } + pBody->setNext(pTrainBodyToAdd); +} Modified: freesynd/trunk/src/model/train.h =================================================================== --- freesynd/trunk/src/model/train.h 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/model/train.h 2017-02-06 15:13:56 UTC (rev 1015) @@ -33,19 +33,35 @@ #include "vehicle.h" /*! - * . + * A train is composed of TrainBody chained together. + * The train head contains the driver and moves. The other parts + * of the train move along with the TrainHead. */ class TrainBody : public Vehicle { public: - TrainBody(uint16 id, uint8 aType, VehicleAnimation *pAnimation); + TrainBody(uint16 id, uint8 aType, VehicleAnimation *pAnimation, int startHp); ~TrainBody(); - bool updatePosition(int elapsed, Mission *m); + TrainBody * getNext() { return pNextBody_; } + void setNext(TrainBody *pNext) { pNextBody_ = pNext; } + //! Set the destination to reach at given speed bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1) { return false; } + + bool doMove(int elapsed, Mission *m) { + return false; + } + +protected: + //! add given amount to train position and updates passengers position + void changeTrainAndPassengersPosition(int distanceX, int distanceY); + +protected: + //! Next part of the train + TrainBody *pNextBody_; }; /*! @@ -53,13 +69,25 @@ */ class TrainHead : public TrainBody { public: - TrainHead(uint16 id, uint8 aType, VehicleAnimation *pAnimation); + TrainHead(uint16 id, uint8 aType, VehicleAnimation *pAnimation, int startHp); ~TrainHead(); - //! Animates the train - bool animate(int elapsed); + //! Set the destination to reach at given speed + bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1); + + bool doMove(int elapsed, Mission *m); + + void appendTrainBody(TrainBody *pTrainBody); private: + bool isMovementOnXAxis() { + return moveOnXaxis_; + } + // If the destination is reached the train stops + void stopIfDestinationReached(const WorldPoint &destinationPt); +private: + //! True means this train is moving on the X axis, else on the Y axis + bool moveOnXaxis_; }; #endif // MODEL_TRAIN_H_ Modified: freesynd/trunk/src/model/vehicle.cpp =================================================================== --- freesynd/trunk/src/model/vehicle.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/model/vehicle.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -88,7 +88,7 @@ bool updated = false; if (health_ > 0) { - updated = updatePosition(elapsed, NULL); + updated = doMove(elapsed, NULL); } if (animation_->animation_type() == VehicleAnimation::kOnFireAnim) { @@ -389,10 +389,9 @@ // NOTE: we will be using lower tiles, later will restore Z coord z = pos_.tz - 1; - dest_path_.clear(); - setSpeed(0); + clearDestination(); - if (map_ == -1 || health_ <= 0 || !(pMap->isTileWalkableByCar(x, y, z))) { + if (!isVisible() || isDead() || !(pMap->isTileWalkableByCar(x, y, z))) { #if 0 #if _DEBUG if (!(map_ == -1 || health_ <= 0)) { @@ -407,86 +406,11 @@ } if (!pMap->isTileWalkableByCar(pos_.tx, pos_.ty, z)) { - int dBest = 100000, dCur; - std::vector < TilePoint > path2wtile; - path2wtile.reserve(16); - // we got somewhere we shouldn't, we need to find somewhere that is walkable - TilePoint pntile(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); - for (int i = 1; i < 16; i++) { - if (pos_.tx + i >= pMap->maxX()) - break; - pntile.tx = pos_.tx + i; - path2wtile.push_back(pntile); - if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, z)) { - dCur = i * i; - if(dCur < dBest) { - dBest = dCur; - path2add = path2wtile; - basex = pos_.tx + i; - basey = pos_.ty; - break; - } - } - } + TilePoint currentPos(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); - path2wtile.clear(); - pntile = TilePoint(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); - for (int i = -1; i > -16; --i) { - if (pos_.tx + i < 0) - break; - pntile.tx = (pos_.tx + i); - path2wtile.push_back(pntile); - if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, z)) { - dCur = i * i; - if(dCur < dBest) { - dBest = dCur; - path2add = path2wtile; - basex = pos_.tx + i; - basey = pos_.ty; - break; - } - } + if(!findPathToNearestWalkableTile(pMap, currentPos, &basex, &basey, &path2add)) { + return false; } - - path2wtile.clear(); - pntile = TilePoint(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); - for (int i = -1; i > -16; --i) { - if (pos_.ty + i < 0) - break; - pntile.ty = (pos_.ty + i); - path2wtile.push_back(pntile); - if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, z)) { - dCur = i * i; - if(dCur < dBest) { - dBest = dCur; - path2add = path2wtile; - basex = pos_.tx; - basey = pos_.ty + i; - break; - } - } - } - - path2wtile.clear(); - pntile = TilePoint(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); - for (int i = 1; i < 16; i++) { - if (pos_.ty + i >= pMap->maxY()) - break; - pntile.ty = pos_.ty + i; - path2wtile.push_back(pntile); - if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, z)) { - dCur = i * i; - if(dCur < dBest) { - dBest = dCur; - path2add = path2wtile; - basex = pos_.tx; - basey = pos_.ty + i; - break; - } - } - } - if(dBest == 100000) - return false; } TilePoint closest; @@ -662,11 +586,97 @@ return !dest_path_.empty(); } +bool GenericCar::findPathToNearestWalkableTile(Map *pMap, const TilePoint &startPt, int *basex, int *basey, std::vector < TilePoint > *path2add) { + int dBest = 100000, dCur; + std::vector < TilePoint > path2wtile; + path2wtile.reserve(16); + // we got somewhere we shouldn't, we need to find somewhere that is walkable + TilePoint pntile = startPt; + for (int i = 1; i < 16; i++) { + if (pos_.tx + i >= pMap->maxX()) + break; + pntile.tx = pos_.tx + i; + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, startPt.tz)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + //path2add = path2wtile; + path2add->assign(path2wtile.begin(), path2wtile.end()); + *basex = pos_.tx + i; + *basey = pos_.ty; + break; + } + } + } + + path2wtile.clear(); + pntile = startPt; + for (int i = -1; i > -16; --i) { + if (pos_.tx + i < 0) + break; + pntile.tx = (pos_.tx + i); + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, startPt.tz)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + //path2add = path2wtile; + path2add->assign(path2wtile.begin(), path2wtile.end()); + *basex = pos_.tx + i; + *basey = pos_.ty; + break; + } + } + } + + path2wtile.clear(); + pntile = startPt; + for (int i = -1; i > -16; --i) { + if (pos_.ty + i < 0) + break; + pntile.ty = (pos_.ty + i); + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, startPt.tz)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + //path2add = path2wtile; + path2add->assign(path2wtile.begin(), path2wtile.end()); + *basex = pos_.tx; + *basey = pos_.ty + i; + break; + } + } + } + + path2wtile.clear(); + pntile = startPt; + for (int i = 1; i < 16; i++) { + if (pos_.ty + i >= pMap->maxY()) + break; + pntile.ty = pos_.ty + i; + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, startPt.tz)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + //path2add = path2wtile; + path2add->assign(path2wtile.begin(), path2wtile.end()); + *basex = pos_.tx; + *basey = pos_.ty + i; + break; + } + } + } + return (dBest != 100000); +} + /*! * Moves a vehicle on the map. * \param elapsed Elapsed time sine last frame. */ -bool GenericCar::updatePosition(int elapsed, Mission *m) +bool GenericCar::doMove(int elapsed, Mission *m) { bool updated = false; int used_time = elapsed; @@ -735,9 +745,9 @@ used_time = 0; // Moves vehicle - updatePlacement(pos_.ox + dx, pos_.oy + dy); + addOffsetToPosition(dx, dy); #if 0 - if (updatePlacement(pos_.ox + dx, pos_.oy + dy)) { + if (addOffsetToPosition(dx, dy)) { ; } else { // TODO: avoid obstacles. Modified: freesynd/trunk/src/model/vehicle.h =================================================================== --- freesynd/trunk/src/model/vehicle.h 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/model/vehicle.h 2017-02-06 15:13:56 UTC (rev 1015) @@ -150,8 +150,8 @@ speed_ = new_speed; } - //! See ShootableMovableMapObject::updatePosition() - bool updatePosition(int elapsed, Mission *m); + //! See ShootableMovableMapObject::doMove() + bool doMove(int elapsed, Mission *m); //! Adds the given ped to the list of passengers void addPassenger(PedInstance *p); @@ -175,7 +175,7 @@ void handleHit(ShootableMapObject::DamageInflictType &d); protected: - bool move_vehicle(int elapsed); + bool findPathToNearestWalkableTile(Map *pMap, const TilePoint &startPt, int *basex, int *basey, std::vector < TilePoint > *path2add); uint16 tileDir(int x, int y, int z); bool dirWalkable(TilePoint *p, int x, int y, int z); Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/ped.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -437,6 +437,7 @@ */ bool PedInstance::executeAction(int elapsed, Mission *pMission) { bool updated = false; + while(currentAction_ != NULL) { // execute action updated |= currentAction_->execute(elapsed, pMission, this); @@ -1012,11 +1013,6 @@ switchActionStateFrom(state_ & PedInstance::pa_smInCar); } -int PedInstance::map() { - - return map_; -} - PedInstance::AnimationDrawn PedInstance::drawnAnim(void) { return drawn_anim_; } Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/ped.h 2017-02-06 15:13:56 UTC (rev 1015) @@ -351,8 +351,8 @@ //! See ShootableMovableMapObject::initMovementToDestination() bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1); - //! See ShootableMovableMapObject::updatePosition() - bool updatePosition(int elapsed, Mission *pMission); + //! See ShootableMovableMapObject::doMove() + bool doMove(int elapsed, Mission *pMission); //************************************* // Weapon management @@ -410,7 +410,6 @@ void putInVehicle(Vehicle *v); void leaveVehicle(); - int map(); AnimationDrawn drawnAnim(void); void setDrawnAnim(AnimationDrawn drawn_anim); bool handleDrawnAnim(int elapsed); Modified: freesynd/trunk/src/pedpathfinding.cpp =================================================================== --- freesynd/trunk/src/pedpathfinding.cpp 2017-01-23 20:58:44 UTC (rev 1014) +++ freesynd/trunk/src/pedpathfinding.cpp 2017-02-06 15:13:56 UTC (rev 1015) @@ -2290,7 +2290,7 @@ #endif } -bool PedInstance::updatePosition(int elapsed, Mission *pMission) +bool PedInstance::doMove(int elapsed, Mission *pMission) { bool updated = false; int used_time = elapsed; @@ -2381,11 +2381,11 @@ } else used_time = 0; - updatePlacement(pos_.ox + dx, pos_.oy + dy); + addOffsetToPosition(dx, dy); // TODO : what obstacles? cars? doors are already // setting stop signal, reuse it? #if 0 - if (updatePlacement(pos_.ox + dx, pos_.oy + dy)) { + if (addOffsetToPosition(dx, dy)) { ; } else { // TODO: avoid obstacles. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-01-23 20:58:46
|
Revision: 1014 http://sourceforge.net/p/freesynd/code/1014 Author: benblan Date: 2017-01-23 20:58:44 +0000 (Mon, 23 Jan 2017) Log Message: ----------- renamed methods around movableobject's movement Modified Paths: -------------- freesynd/trunk/NEWS freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/mapobject.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/maprenderer.cpp freesynd/trunk/src/model/train.cpp freesynd/trunk/src/model/train.h freesynd/trunk/src/model/vehicle.cpp freesynd/trunk/src/model/vehicle.h freesynd/trunk/src/ped.h freesynd/trunk/src/pedpathfinding.cpp Modified: freesynd/trunk/NEWS =================================================================== --- freesynd/trunk/NEWS 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/NEWS 2017-01-23 20:58:44 UTC (rev 1014) @@ -7,11 +7,11 @@ Changes ------- - * + * German translation has been updated (thanks to Maik Wagner) Fixed Bugs ---------- - * + * In mission Siberia, train was wrongly displayed Features added ---------- Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/ia/actions.cpp 2017-01-23 20:58:44 UTC (rev 1014) @@ -234,7 +234,7 @@ void WalkAction::doStart(Mission *pMission, PedInstance *pPed) { // Go to given location at given speed - if (!pPed->setDestination(pMission, destLocT_, newSpeed_)) { + if (!pPed->initMovementToDestination(pMission, destLocT_, newSpeed_)) { setFailed(); return; } @@ -250,7 +250,7 @@ * \param pPed The ped executing the action. */ bool WalkAction::doExecute(int elapsed, Mission *pMission, PedInstance *pPed) { - bool updated = pPed->movementP(pMission, elapsed); + bool updated = pPed->updatePosition(elapsed, pMission); if (!pPed->hasDestination()) { // Ped has arrived at destination setSucceeded(); @@ -408,7 +408,7 @@ updateLastTargetPos(); // If target is not too close, then initiate movement. if (!pPed->isCloseTo(pTarget_, kFollowDistance)) { - if (!pPed->setDestination(pMission, targetLastPos_)) { + if (!pPed->initMovementToDestination(pMission, targetLastPos_)) { setFailed(); } } else { @@ -434,7 +434,7 @@ pPed->clearDestination(); pPed->leaveState(targetState_); } else { - updated = pPed->movementP(pMission, elapsed); + updated = pPed->updatePosition(elapsed, pMission); } } @@ -443,7 +443,7 @@ if (!pTarget_->sameTile(targetLastPos_)) { // resetting target position updateLastTargetPos(); - if (pPed->setDestination(pMission, targetLastPos_)) { + if (pPed->initMovementToDestination(pMission, targetLastPos_)) { targetState_ = PedInstance::pa_smWalking; pPed->goToState(targetState_); } else { @@ -494,7 +494,7 @@ if (!pTarget_->isCloseTo(targetLastPosW_, 128)) { // resetting target position targetLastPosW_.convertFromTilePoint(pTarget_->position()); - if (!pPed->setDestination(pMission, pTarget_->position())) { + if (!pPed->initMovementToDestination(pMission, pTarget_->position())) { setFailed(); return true; } @@ -509,7 +509,7 @@ setSucceeded(); pPed->clearDestination(); } else { - updated = pPed->movementP(pMission, elapsed); + updated = pPed->updatePosition(elapsed, pMission); } } @@ -605,7 +605,7 @@ setFailed(); } - if (!pVehicle_->setDestination(pMission, dest_, 1024)) { + if (!pVehicle_->initMovementToDestination(pMission, dest_, 1024)) { setFailed(); } } Modified: freesynd/trunk/src/mapobject.h =================================================================== --- freesynd/trunk/src/mapobject.h 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/mapobject.h 2017-01-23 20:58:44 UTC (rev 1014) @@ -522,9 +522,27 @@ speed_ = 0; } - //! Set the destination to reach at given speed - virtual bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1) = 0; + /** + * Compute a path from the object current position to given destination using given speed. + * Subclasses must implement this method. + * \param m Mission* Mission data + * \param locT Destination for the movement + * \param newSpeed The speed at which the object will move. If speed is -1, use default speed. + * \return true if there is a path towards given destination + */ + virtual bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1) = 0; + + /** + * Update position of the object using the current path and speed. + * Subclasses must implement this method. + * \param elapsed int + * \param m Mission* Mission data + * \return True if the position has been updated. + * + */ + virtual bool updatePosition(int elapsed, Mission *m) = 0; + //! Return true if the ped is moving bool isMoving() { return speed_ != 0 || !dest_path_.empty();} //! Returns true if object currently has a destination point (ie it's arrived) Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2017-01-23 20:58:44 UTC (rev 1014) @@ -465,7 +465,7 @@ last_time = current_time; } sprintf(tmp, "FPS : %.2f FRAMES PER SEC", fps); - gameFont()->drawText(10, g_Screen.gameScreenHeight() - 15, tmp, 14); + gameFont()->drawText(10, Screen::kScreenHeight - 15, tmp, 14); #endif } @@ -904,9 +904,9 @@ std::string str_paused = getMessage("GAME_PAUSED"); MenuFont *font_used = getMenuFont(FontManager::SIZE_1); int txt_width = font_used->textWidth(str_paused.c_str(), false); - int txt_posx = g_Screen.gameScreenWidth() / 2 - txt_width / 2; + int txt_posx = Screen::kScreenWidth / 2 - txt_width / 2; int txt_height = font_used->textHeight(false); - int txt_posy = g_Screen.gameScreenHeight() / 2 - txt_height / 2; + int txt_posy = Screen::kScreenHeight / 2 - txt_height / 2; g_Screen.drawRect(txt_posx - 10, txt_posy - 5, txt_width + 20, txt_height + 10); Modified: freesynd/trunk/src/menus/maprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/maprenderer.cpp 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/menus/maprenderer.cpp 2017-01-23 20:58:44 UTC (rev 1014) @@ -50,8 +50,8 @@ // - Some advert panels lack a corner TilePoint mtp = pMap_->screenToTilePoint(viewport.x, viewport.y); int sw = mtp.tx; - int chk = g_Screen.gameScreenWidth() / (TILE_WIDTH / 2) + 2 - + g_Screen.gameScreenHeight() / (TILE_HEIGHT / 3) + pMap_->maxZ() * 2; + int chk = Screen::kScreenWidth / (TILE_WIDTH / 2) + 2 + + Screen::kScreenHeight / (TILE_HEIGHT / 3) + pMap_->maxZ() * 2; int sh = mtp.ty - 8; int shm = sh + chk; @@ -60,10 +60,10 @@ listObjectsToDraw(viewport); - int cmw = viewport.x + g_Screen.gameScreenWidth() - - g_Screen.gameScreenLeftMargin() + 128; - int cmh = viewport.y + g_Screen.gameScreenHeight() + 128; - int cmx = viewport.x - g_Screen.gameScreenLeftMargin(); + int cmw = viewport.x + Screen::kScreenWidth - + Screen::kScreenPanelWidth + 128; + int cmh = viewport.y + Screen::kScreenHeight + 128; + int cmx = viewport.x - Screen::kScreenPanelWidth; // z = 0 - is minimap data and mapdata int chky = sh < 0 ? 0 : sh; int zr = shm + pMap_->maxZ() + 1; Modified: freesynd/trunk/src/model/train.cpp =================================================================== --- freesynd/trunk/src/model/train.cpp 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/model/train.cpp 2017-01-23 20:58:44 UTC (rev 1014) @@ -22,7 +22,7 @@ * Moves a vehicle on the map. * \param elapsed Elapsed time sine last frame. */ -bool TrainBody::move_vehicle(int elapsed) +bool TrainBody::updatePosition(int elapsed, Mission *m) { return false; } Modified: freesynd/trunk/src/model/train.h =================================================================== --- freesynd/trunk/src/model/train.h 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/model/train.h 2017-01-23 20:58:44 UTC (rev 1014) @@ -40,10 +40,10 @@ TrainBody(uint16 id, uint8 aType, VehicleAnimation *pAnimation); ~TrainBody(); - bool move_vehicle(int elapsed); + bool updatePosition(int elapsed, Mission *m); //! Set the destination to reach at given speed - bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1) { + bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1) { return false; } }; Modified: freesynd/trunk/src/model/vehicle.cpp =================================================================== --- freesynd/trunk/src/model/vehicle.cpp 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/model/vehicle.cpp 2017-01-23 20:58:44 UTC (rev 1014) @@ -30,6 +30,7 @@ #include <assert.h> #include "app.h" +#include "mission.h" #include "core/gamesession.h" #include "gfx/screen.h" #include "vehicle.h" @@ -87,7 +88,7 @@ bool updated = false; if (health_ > 0) { - updated = move_vehicle(elapsed); + updated = updatePosition(elapsed, NULL); } if (animation_->animation_type() == VehicleAnimation::kOnFireAnim) { @@ -370,21 +371,19 @@ * \param newSpeed Speed of movement * \return true if destination has been set correctly. */ -bool GenericCar::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { - speed_ = newSpeed; - setDestinationV(locT.tx, locT.ty, locT.tz, locT.ox, locT.oy, newSpeed); - return !dest_path_.empty(); -} - -void GenericCar::setDestinationV(int x, int y, int z, int ox, int oy, int new_speed) -{ +bool GenericCar::initMovementToDestination(Mission *pMission, const TilePoint &destinationPt, int newSpeed) { std::map < TilePoint, uint16 > open; std::set < TilePoint > closed; std::map < TilePoint, TilePoint > parent; int basex = pos_.tx, basey = pos_.ty; std::vector < TilePoint > path2add; path2add.reserve(16); - Map *pMap = g_App.maps().map(map_); + Map *pMap = pMission->get_map(); + int x = destinationPt.tx; + int y = destinationPt.ty; + int z = destinationPt.tz; + int ox = destinationPt.ox; + int oy = destinationPt.oy; pMap->adjXYZ(x, y, z); // NOTE: we will be using lower tiles, later will restore Z coord @@ -404,7 +403,7 @@ } #endif #endif - return; + return false; } if (!pMap->isTileWalkableByCar(pos_.tx, pos_.ty, z)) { @@ -487,7 +486,7 @@ } } if(dBest == 100000) - return; + return false; } TilePoint closest; @@ -591,7 +590,7 @@ if(!dest_path_.empty()) { // Adjusting offsets for correct positioning - speed_ = new_speed; + speed_ = newSpeed; int curox = pos_.ox; int curoy = pos_.oy; for(std::list < TilePoint >::iterator it = dest_path_.begin(); @@ -659,13 +658,15 @@ dest_path_.push_front(*it); } } + + return !dest_path_.empty(); } /*! * Moves a vehicle on the map. * \param elapsed Elapsed time sine last frame. */ -bool GenericCar::move_vehicle(int elapsed) +bool GenericCar::updatePosition(int elapsed, Mission *m) { bool updated = false; int used_time = elapsed; Modified: freesynd/trunk/src/model/vehicle.h =================================================================== --- freesynd/trunk/src/model/vehicle.h 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/model/vehicle.h 2017-01-23 20:58:44 UTC (rev 1014) @@ -107,8 +107,6 @@ //! Return true if vehicle is a car bool isCar() { return type_ != kVehicleTypeTrainHead && type_ != kVehicleTypeTrainBody; } - //void setType(uint8 type) { type_ = type; } - //! Adds the given ped to the list of passengers virtual void addPassenger(PedInstance *p); //! Removes the passenger from the vehicle @@ -124,8 +122,6 @@ bool containsHostilesForPed(PedInstance *p, unsigned int hostile_desc_alt); protected: - virtual bool move_vehicle(int elapsed) = 0; -protected: /*! The passengers of the vehicle.*/ std::set <PedInstance *> passengers_; /*! Animation for vehicle.*/ @@ -145,8 +141,8 @@ GenericCar(VehicleAnimation *pAnimation, uint16 id, uint8 aType, int m); virtual ~GenericCar() {} - //! Set the destination to reach at given speed (todo : replace setDestinationV()) - bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1); + //! See ShootableMovableMapObject::initMovementToDestination() + bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1); void addDestinationV(int x, int y, int z, int ox = 128, int oy = 128, int new_speed = 160) { @@ -154,7 +150,8 @@ speed_ = new_speed; } - void setDestinationV(int x, int y, int z, int ox = 128, int oy = 128, int new_speed = 160); + //! See ShootableMovableMapObject::updatePosition() + bool updatePosition(int elapsed, Mission *m); //! Adds the given ped to the list of passengers void addPassenger(PedInstance *p); Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/ped.h 2017-01-23 20:58:44 UTC (rev 1014) @@ -348,14 +348,12 @@ //************************************* // Movement management //************************************* - //! Set the destination to reach at given speed (todo : replace setDestinationP()) - bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1); + //! See ShootableMovableMapObject::initMovementToDestination() + bool initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed = -1); - void setDestinationP(Mission *m, int x, int y, int z, - int ox = 128, int oy = 128); + //! See ShootableMovableMapObject::updatePosition() + bool updatePosition(int elapsed, Mission *pMission); - bool movementP(Mission *m, int elapsed); - //************************************* // Weapon management //************************************* Modified: freesynd/trunk/src/pedpathfinding.cpp =================================================================== --- freesynd/trunk/src/pedpathfinding.cpp 2017-01-23 11:03:18 UTC (rev 1013) +++ freesynd/trunk/src/pedpathfinding.cpp 2017-01-23 20:58:44 UTC (rev 1014) @@ -41,22 +41,16 @@ * \param newSpeed Speed of movement * \return true if destination has been set correctly. */ -bool PedInstance::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { +//bool PedInstance::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { +bool PedInstance::initMovementToDestination(Mission *m, const TilePoint &destinationPt, int newSpeed) { // if no speed was set, use ped's default speed speed_ = newSpeed != -1 ? newSpeed : getDefaultSpeed(); - setDestinationP(m, locT.tx, locT.ty, locT.tz, locT.ox, locT.oy); - if (dest_path_.empty()) { - // destination was not set -> stop ped - speed_ = 0; - return false; - } else { - return true; - } -} + int x = destinationPt.tx; + int y = destinationPt.ty; + int z = destinationPt.tz; + int ox = destinationPt.ox; + int oy = destinationPt.oy; -void PedInstance::setDestinationP(Mission *m, int x, int y, int z, - int ox, int oy) -{ // NOTE: this is a "flood" algorithm, it expands until it reaches other's // flood point, then it removes unrelated points #ifdef EXECUTION_SPEED_TIME @@ -67,7 +61,7 @@ dest_path_.clear(); if (map_ == -1 || health_ <= 0) - return; + return false; floodPointDesc *targetd = &(m->mdpoints_[x + y * m->mmax_x_ + z * m->mmax_m_xy]); @@ -100,19 +94,19 @@ printf("==== unwalk target: x %i; y %i; z %i, ox %i, oy %i\n", x, y, z, ox, oy); printf("setDestinationP, Movement to nonwalkable postion\n"); - return; + return false; } if(based->t == m_fdNonWalkable) { printf("==== unwalk pos: x %i; y %i; z %i, ox %i, oy %i, oz %i\n", pos_.tx, pos_.ty, pos_.tz, pos_.ox, pos_.oy, pos_.oz); printf("setDestinationP, Movement from nonwalkable postion\n"); - return; + return false; } if (pos_.tx == x && pos_.ty == y && pos_.tz == z) { dest_path_.push_back(TilePoint(x, y, z, ox, oy)); - return; + return false; } #ifdef EXECUTION_SPEED_TIME printf("directions-map copy start %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); @@ -900,7 +894,7 @@ printf("target reached in %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); #endif if (!nodeset && lnknr) { - return; + return false; } if (blvl == bn.size()) blvl--; @@ -2271,6 +2265,14 @@ } } } + + if (dest_path_.empty()) { + // destination was not set -> stop ped + speed_ = 0; + return false; + } else { + return true; + } #ifdef EXECUTION_SPEED_TIME printf("smoothing time %i.%i\n", SDL_GetTicks()/1000, SDL_GetTicks()%1000); #endif @@ -2288,7 +2290,7 @@ #endif } -bool PedInstance::movementP(Mission *m, int elapsed) +bool PedInstance::updatePosition(int elapsed, Mission *pMission) { bool updated = false; int used_time = elapsed; @@ -2421,8 +2423,8 @@ } } - offzOnStairs(m->mtsurfaces_[pos_.tx + pos_.ty * m->mmax_x_ - + pos_.tz * m->mmax_m_xy].twd); + offzOnStairs(pMission->mtsurfaces_[pos_.tx + pos_.ty * pMission->mmax_x_ + + pos_.tz * pMission->mmax_m_xy].twd); } #ifdef _DEBUG if (dest_path_.empty() && speed_) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2017-01-23 11:03:21
|
Revision: 1013 http://sourceforge.net/p/freesynd/code/1013 Author: benblan Date: 2017-01-23 11:03:18 +0000 (Mon, 23 Jan 2017) Log Message: ----------- - fixed a bug when displaying a train - added german translation (thanks to Maik Wagner) Modified Paths: -------------- freesynd/trunk/data/lang/german.lng freesynd/trunk/src/gfx/screen.cpp freesynd/trunk/src/gfx/screen.h freesynd/trunk/src/mapobject.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/gameplaymenu.h freesynd/trunk/src/menus/maprenderer.cpp freesynd/trunk/src/menus/maprenderer.h Modified: freesynd/trunk/data/lang/german.lng =================================================================== --- freesynd/trunk/data/lang/german.lng 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/data/lang/german.lng 2017-01-23 11:03:18 UTC (rev 1013) @@ -1,24 +1,24 @@ #translate SELECT_RELOAD_BUT, HINT_FOLLOW, HINT_HIT_BY_CAR, HINT_ON_FIRE, HINT_DROP_WEAPON, SELECT_WPN_COST, SELECT_WPN_AMMO, SELECT_WPN_RANGE, SELECT_WPN_SHOT, SELECT_WPN_RELOAD #translate all intro texts -INTRO_0=CITY NAME : NEW HESSEN EUROPE -INTRO_1=DATELINE :1/85 NV (NEW CALENDER) -INTRO_2=TIME : 18:20 HRS -INTRO_3=NEW SUBJECTS REQUIRED FOR RECRUITMENT -INTRO_4=POSSIBLE SUBJECT LOCATED -INTRO_5=SUBJECT STATISTICS : MALE -INTRO_6=SUBJECT STATISTICS : HEIGHT :1.85M -INTRO_7=SUBJECT STATISTICS : WEIGHT :70KGS -INTRO_8=SUBJECT ACCEPTED -INTRO_9=ACQUIRE SUBJECT -INTRO_10=RETURN TO HEADQUARTERS -INTRO_11=PREPARE SUBJECT FOR BIOGENETIC ENGINEERING -INTRO_12=LEONARDO DEVICE ACTIVATED -INTRO_13=GENERATING REPLACEMENT LIMB -INTRO_14=OPERATION COMPLETED -INTRO_15=APPLY POLYMORPHIC RUBBER COATING +INTRO_0=CITY NAME : NEW HESSEN EUROPA +INTRO_1=DATELINE :1/85 NV (NEUER KALENDER) +INTRO_2=TIME : 18:20 STD +INTRO_3=NEUE PERSONEN FÜR ANWERBUNG NÖTIG +INTRO_4=MÖGLICHE PERSON ENTDECKT +INTRO_5=SUBJECT STATISTICS : MÄNNLICH +INTRO_6=SUBJECT STATISTICS : GRÖSSE :1.85M +INTRO_7=SUBJECT STATISTICS : GEWICHT :70KGS +INTRO_8=PERSON AKZEPTIERT +INTRO_9=PERSON AKQUIEREN +INTRO_10=ZURÜCK ZUM HAUPTQUARTIER +INTRO_11=PERSON FÜR BIOGENETISCHE UMWANDLUNG VORBEREITEN +INTRO_12=LEONARDO GERÄT AKTIVIERT +INTRO_13=ERSTELLUNG DES ERSATZGLIEDMASS +INTRO_14=OPERATION ERFOLGREICH +INTRO_15=ANWENDUNG POLYMORPHISCHER GUMMISCHICHT INTRO_16=SYSTEM CHECK -INTRO_17=PREPARE FOR MISSION -INTRO_18=BEGIN MISSION +INTRO_17=VORBEREITUNG ZUM EINSATZ +INTRO_18=EINSATZ BEGINNEN MENU_MAIN_BUT = HAUPTMENÜ MENU_ACC_BUT = BESTÄTIGEN @@ -368,21 +368,21 @@ GOAL_PROTECT = SCHÜTZEN GOAL_TAKE_WEAPON = WAFFE NEHMEN GOAL_ELIMINATE_POLICE = POLIZEI BESIEGEN -GOAL_ELIMINATE_AGENTS = AGENTE BESIEGEN +GOAL_ELIMINATE_AGENTS = AGENTEN BESIEGEN GOAL_DESTROY_VEHICLE = AUTO ZERSTÖREN GOAL_USE_VEHICLE = AUTO BENUTZEN GOAL_EVACUATE = EVAKUIEREN HINT_GOING = GEHT HINT_OBSERVING = WARTET -HINT_PICKUP_WEAPON = NIMMT WAFFE +HINT_PICKUP_WEAPON = WAFFE NEHMEN HINT_HIT_BY_BULLET = GETROFFEN HINT_MISSION_FAILED = EINSATZ VERSAGT HINT_MISSION_COMPLETE = EINSATZ ERFÜLLT HINT_PRESS_SPACE = DRÜCKE LEERTASTE -HINT_FOLLOW = FOLLOW -HINT_HIT_BY_CAR = HIT BY CAR -HINT_ON_FIRE = ON FIRE -HINT_DROP_WEAPON = DROP WEAPON +HINT_FOLLOW = FOLGEN +HINT_HIT_BY_CAR = ANGEFAHREN +HINT_ON_FIRE = UNTER BESCHUSS +HINT_DROP_WEAPON = WAFFE FÄLLT -GAME_PAUSED = GAME PAUSED +GAME_PAUSED = SPIELPAUSE Modified: freesynd/trunk/src/gfx/screen.cpp =================================================================== --- freesynd/trunk/src/gfx/screen.cpp 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/gfx/screen.cpp 2017-01-23 11:03:18 UTC (rev 1013) @@ -28,6 +28,10 @@ #include "screen.h" #include "utils/file.h" +const int Screen::kScreenWidth = 640; +const int Screen::kScreenHeight = 400; +const int Screen::kScreenPanelWidth = 129; + Screen::Screen(int width, int height) :width_(width) , height_(height) @@ -298,7 +302,7 @@ uint8 *pixel; /* - * Variable setup + * Variable setup */ dx = x2 - x1; dy = y2 - y1; @@ -306,11 +310,11 @@ sy = (dy >= 0) ? 1 : -1; /* - * No alpha blending - use fast pixel routines + * No alpha blending - use fast pixel routines */ /* - * More variable setup + * More variable setup */ dx = sx * dx + 1; dy = sy * dy + 1; @@ -329,7 +333,7 @@ } /* - * Draw + * Draw */ x = 0; y = 0; Modified: freesynd/trunk/src/gfx/screen.h =================================================================== --- freesynd/trunk/src/gfx/screen.h 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/gfx/screen.h 2017-01-23 11:03:18 UTC (rev 1013) @@ -32,6 +32,13 @@ */ class Screen : public Singleton<Screen> { public: + /*! Width of the screen in pixels.*/ + static const int kScreenWidth; + /*! Height of the screen in pixels.*/ + static const int kScreenHeight; + /*! Width of the left control panel*/ + static const int kScreenPanelWidth; + explicit Screen(int width, int height); ~Screen(); Modified: freesynd/trunk/src/mapobject.h =================================================================== --- freesynd/trunk/src/mapobject.h 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/mapobject.h 2017-01-23 11:03:18 UTC (rev 1013) @@ -67,6 +67,20 @@ //! Return the object's id uint16 id() { return id_; } + void setVisible(bool visible) { + isVisible_ = visible; + // TODO : remove when isVisible is active + if (!isVisible_) { + map_ = -1; + } + } + + bool isVisible() { + // TODO : replace with isvisible_ + return map_ != -1; + } + + virtual void draw(int x, int y) = 0; enum DamageType { dmg_None = 0x0000, @@ -207,6 +221,18 @@ return sqrt((double) (cx * cx + cy * cy + cz * cz)); } + + /** + * Returns true if given object is farther than this object. + * Objects are considered on same tile. farther objects are drawn first. + * \param pOther MapObject* + * \return bool + * + */ + bool isBehindObjectOnSameTile(MapObject *pOther) { + return pos_.ox < pOther->position().ox || pos_.oy < pOther->position().oy; + } + virtual bool animate(int elapsed); void setFramesPerSec(int framesPerSec) @@ -282,6 +308,8 @@ int size_x_, size_y_, size_z_; //! if equal -1 object is not on map and should not be drawn int map_; + //! Object should be drawn only if visible + bool isVisible_; //! animation frame changing int frame_; /*! Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2017-01-23 11:03:18 UTC (rev 1013) @@ -298,7 +298,8 @@ menu_manager_->setPaletteForMission(g_Session.getSelectedBlock().mis_id); g_Screen.clear(0); - updtAgentsMarker(); + highlightLeaderMarker(); + updateMarkersPosition(); // Init renderers map_renderer_.init(mission_, &selection_); @@ -366,6 +367,8 @@ for (size_t i = 0; i < mission_->numPeds(); i++) change |= mission_->ped(i)->animate(diff, mission_); + updateMarkersPosition(); + for (size_t i = 0; i < mission_->numVehicles(); i++) change |= mission_->vehicle(i)->animate(diff); @@ -1307,7 +1310,7 @@ if (selection_.selectAgent(agentNo, addToGroup)) { updateSelectAll(); centerMinimapOnLeader(); - updtAgentsMarker(); + highlightLeaderMarker(); g_App.gameSounds().play(snd::SPEECH_SELECTED); // redraw agent selectors @@ -1336,7 +1339,7 @@ * Make the current leader marker blinks. * All other agents not. */ -void GameplayMenu::updtAgentsMarker() +void GameplayMenu::highlightLeaderMarker() { for (size_t i = AgentManager::kSlot1; i < AgentManager::kMaxSlot; i++) { // draw animation only for leader @@ -1344,12 +1347,31 @@ } } +/** + * Updating position for visual markers for all agents. + * \return void + * + */ +void GameplayMenu::updateMarkersPosition() { + for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { + if (mission_->sfxObjects(i + 4)->isVisible()) { + TilePoint agentPos = mission_->getSquad()->member(i)->position(); + agentPos.ox -= 16; + agentPos.oz += 256; + + mission_->sfxObjects(i + 4)->setPosition(agentPos); + } + } +} + /*! * This method checks among the squad to see if an agent died and deselects him. */ -void GameplayMenu::updateSelectionForDeadAgent(PedInstance *p_ped) { +void GameplayMenu::updateSelectionForDeadAgent(PedInstance *pPed) { // Deselects dead agent - selection_.deselectAgent(p_ped); + selection_.deselectAgent(pPed); + // hide dead agent's marker + mission_->sfxObjects(pPed->id() + 4)->setVisible(false); // if selection is empty after agent's death // selects the first selectable agent @@ -1363,7 +1385,7 @@ } // anyway updates markers - updtAgentsMarker(); + highlightLeaderMarker(); updateSelectAll(); } Modified: freesynd/trunk/src/menus/gameplaymenu.h =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.h 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/menus/gameplaymenu.h 2017-01-23 11:03:18 UTC (rev 1013) @@ -85,7 +85,7 @@ //! Deselect agent if he died void updateSelectionForDeadAgent(PedInstance *p_ped); //! updates visual markers for our agents - void updtAgentsMarker(); + void highlightLeaderMarker(); //! Set pLocWToSet param with point on the map where player clicked to shoot bool getAimedAt(int x, int y, WorldPoint *pLocWToSet); void stopShootingEvent(); @@ -98,6 +98,8 @@ //! Update the target value for adrenaline etc for an agent void updateIPALevelMeters(int elapsed); + void updateMarkersPosition(); + protected: /*! Origin of the minimap on the screen.*/ static const int kMiniMapScreenX; Modified: freesynd/trunk/src/menus/maprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/maprenderer.cpp 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/menus/maprenderer.cpp 2017-01-23 11:03:18 UTC (rev 1013) @@ -45,28 +45,25 @@ /** * Draw tiles and map objects. */ -void MapRenderer::render(const Point2D &worldPos) { - // TODO: after a lot of attempts to fix this, map drawing remains buggy - TilePoint mtp = pMap_->screenToTilePoint(worldPos.x, worldPos.y); +void MapRenderer::render(const Point2D &viewport) { + // TODO: list of bugs to fix in rendering + // - Some advert panels lack a corner + TilePoint mtp = pMap_->screenToTilePoint(viewport.x, viewport.y); int sw = mtp.tx; int chk = g_Screen.gameScreenWidth() / (TILE_WIDTH / 2) + 2 + g_Screen.gameScreenHeight() / (TILE_HEIGHT / 3) + pMap_->maxZ() * 2; - int swm = sw + chk; int sh = mtp.ty - 8; int shm = sh + chk; -#ifdef EXECUTION_SPEED_TIME - printf("---------------------------"); - int measure_ticks = SDL_GetTicks(); - printf("start time %i.%i\n", measure_ticks/1000, measure_ticks%1000); -#endif + DEBUG_SPEED_INIT - createFastKeys(sw, sh, swm, shm); - int cmw = worldPos.x + g_Screen.gameScreenWidth() - + listObjectsToDraw(viewport); + + int cmw = viewport.x + g_Screen.gameScreenWidth() - g_Screen.gameScreenLeftMargin() + 128; - int cmh = worldPos.y + g_Screen.gameScreenHeight() + 128; - int cmx = worldPos.x - g_Screen.gameScreenLeftMargin(); + int cmh = viewport.y + g_Screen.gameScreenHeight() + 128; + int cmx = viewport.x - g_Screen.gameScreenLeftMargin(); // z = 0 - is minimap data and mapdata int chky = sh < 0 ? 0 : sh; int zr = shm + pMap_->maxZ() + 1; @@ -86,11 +83,10 @@ continue; } int screen_w = (pMap_->maxX() + (tile_x - tile_y)) * (TILE_WIDTH / 2); - // int screen_h = (max_z_ + w + h) * (TILE_HEIGHT / 3); int coord_h = ((pMap_->maxZ() + tile_x + tile_y) - (tile_z - 1)) * (TILE_HEIGHT / 3); - if (screen_w >= worldPos.x - TILE_WIDTH * 2 + if (screen_w >= viewport.x - TILE_WIDTH * 2 && screen_w + TILE_WIDTH * 2 < cmw - && coord_h >= worldPos.y - TILE_HEIGHT * 2 + && coord_h >= viewport.y - TILE_HEIGHT * 2 && coord_h + TILE_HEIGHT * 2 < cmh) { #if 0 if (z > 2) @@ -101,12 +97,12 @@ Tile *p_tile = pMap_->getTileAt(tile_x, tile_y, tile_z); if (p_tile->notTransparent()) { int dx = 0, dy = 0; - if (screen_w - worldPos.x < 0) - dx = -(screen_w - worldPos.x); - if (coord_h - worldPos.y < 0) - dy = -(coord_h - worldPos.y); + if (screen_w - viewport.x < 0) + dx = -(screen_w - viewport.x); + if (coord_h - viewport.y < 0) + dy = -(coord_h - viewport.y); if (dx < TILE_WIDTH && dy < TILE_HEIGHT) { - p_tile->drawToScreen(screen_w - cmx, coord_h - worldPos.y); + p_tile->drawToScreen(screen_w - cmx, coord_h - viewport.y); } } } @@ -114,10 +110,10 @@ // draw everything that's on the tile if (tile_z - 1 >= 0) { TilePoint currentTile(tile_x, tile_y, tile_z - 1); + Point2D screenPos = {screen_w - cmx + TILE_WIDTH / 2, + coord_h - viewport.y + TILE_HEIGHT / 3 * 2}; - drawAt(currentTile, - screen_w - cmx + TILE_WIDTH / 2, - coord_h - worldPos.y + TILE_HEIGHT / 3 * 2); + drawObjectsOnTile(currentTile, screenPos); } } --tile_y; @@ -126,11 +122,13 @@ } } + freeUnreleasedResources(); + #ifdef _DEBUG if (g_System.getKeyModState() & KMD_LALT) { for (SquadSelection::Iterator it = pSelection_->begin(); it != pSelection_->end(); ++it) { - (*it)->showPath(worldPos.x, worldPos.y); + (*it)->showPath(viewport.x, viewport.y); } } #endif @@ -138,170 +136,181 @@ DEBUG_SPEED_LOG("MapRenderer::render") } -int MapRenderer::fastKey(MapObject * m) { - return fastKey(m->position()); +int MapRenderer::tileHashKey(MapObject * m) { + return tileHashKey(m->position()); } -void MapRenderer::createFastKeys(int tilex, int tiley, int maxtilex, int maxtiley) { - if (tilex < 0) +void MapRenderer::listObjectsToDraw(const Point2D &viewport) { + /*if (tilex < 0) tilex = 0; if (tiley < 0) tiley = 0; if (maxtilex >= pMap_->maxX()) maxtilex = pMap_->maxX(); if (maxtiley >= pMap_->maxY()) - maxtiley = pMap_->maxY(); + maxtiley = pMap_->maxY();*/ - cache_vehicles_.clear(); - cache_peds_.clear(); - cache_weapons_.clear(); - cache_statics_.clear(); - cache_sfx_objects_.clear(); - fast_vehicle_cache_.clear(); - fast_ped_cache_.clear(); - fast_weapon_cache_.clear(); - fast_statics_cache_.clear(); - fast_sfx_objects_cache_.clear(); - - // updating position for visual markers - for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { - PedInstance *p = pMission_->getSquad()->member(i); - if (p != NULL && p->isAlive()) { - if (p->tileX() >= tilex && p->tileX() < maxtilex - && p->tileY() >= tiley && p->tileY() < maxtiley) { - // sfx_objects_[i]->setPosition(p->tileX(), p->tileY(), p->tileZ(), - // p->offX(), p->offY(), p->offZ() + 320); - pMission_->sfxObjects(i + 4)->setPosition(p->tileX(), p->tileY(), - p->tileZ(), p->offX() - 16, p->offY(), p->offZ() + 256); - } - } else { - // sfx_objects_[i]->setMap(-1); - pMission_->sfxObjects(i + 4)->setMap(-1); + // Include peds + for (size_t i = 0; i < pMission_->numPeds(); i++) { + PedInstance *pPed = pMission_->ped(i); + if (pPed->isVisible() && isObjectInsideDrawingArea(pPed, viewport)) { + addObjectToDraw(pPed); } } // vehicles - for (unsigned int i = 0; i < pMission_->numVehicles(); i++) { - Vehicle *v = pMission_->vehicle(i); - if (v->tileX() >= tilex && v->tileX() < maxtilex - && v->tileY() >= tiley && v->tileY() < maxtiley) { - // NOTE: a trick to make vehicles be drawn correctly z+1 - TilePoint tilePos( v->position()); - tilePos.tz += 1; - fast_vehicle_cache_.insert(fastKey(tilePos)); - cache_vehicles_.push_back(v); + for (size_t i = 0; i < pMission_->numVehicles(); i++) { + Vehicle *pVehicle = pMission_->vehicle(i); + if (isObjectInsideDrawingArea(pVehicle, viewport)) { + addObjectToDraw(pVehicle); } } - // peds - for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { - PedInstance *p = pMission_->getSquad()->member(i); - if (p != NULL && p->map() != -1) { - if (p->tileX() >= tilex && p->tileX() < maxtilex - && p->tileY() >= tiley && p->tileY() < maxtiley) { - fast_ped_cache_.insert(fastKey(p)); - cache_peds_.push_back(p); - } - } - } - for (size_t i = pMission_->getSquad()->size(); i < pMission_->numPeds(); i++) { - PedInstance *p = pMission_->ped(i); - if (p->map() != -1) { - if (p->tileX() >= tilex && p->tileX() < maxtilex - && p->tileY() >= tiley && p->tileY() < maxtiley) { - fast_ped_cache_.insert(fastKey(p)); - cache_peds_.push_back(p); - } - } - } - // weapons - for (unsigned int i = 0; i < pMission_->numWeapons(); i++) { - WeaponInstance *w = pMission_->weapon(i); - if (w->map() != -1 && w->tileX() >= tilex && w->tileX() < maxtilex - && w->tileY() >= tiley && w->tileY() < maxtiley) { - fast_weapon_cache_.insert(fastKey(w)); - cache_weapons_.push_back(w); + for (size_t i = 0; i < pMission_->numWeapons(); i++) { + WeaponInstance *pWeapon = pMission_->weapon(i); + if (pWeapon->isVisible() && isObjectInsideDrawingArea(pWeapon, viewport)) { + addObjectToDraw(pWeapon); } } // statics - for (unsigned int i = 0; i < pMission_->numStatics(); i++) { - Static *s = pMission_->statics(i); - if (s->tileX() >= tilex && s->tileX() < maxtilex - && s->tileY() >= tiley && s->tileY() < maxtiley) { - fast_statics_cache_.insert(fastKey(s)); - cache_statics_.push_back(s); + for (size_t i = 0; i < pMission_->numStatics(); i++) { + Static *pStatic = pMission_->statics(i); + if (isObjectInsideDrawingArea(pStatic, viewport)) { + addObjectToDraw(pStatic); } } // sfx objects - for (unsigned int i = 0; i < pMission_->numSfxObjects(); i++) { - SFXObject *so = pMission_->sfxObjects(i); - if (so->map() != -1 && so->tileX() >= tilex && so->tileX() < maxtilex - && so->tileY() >= tiley && so->tileY() < maxtiley) { - fast_sfx_objects_cache_.insert(fastKey(so)); - cache_sfx_objects_.push_back(so); + for (size_t i = 0; i < pMission_->numSfxObjects(); i++) { + SFXObject *pSfx = pMission_->sfxObjects(i); + if (pSfx->isVisible() && isObjectInsideDrawingArea(pSfx, viewport)) { + addObjectToDraw(pSfx); } } } -void MapRenderer::drawAt(const TilePoint & tilePos, int x, int y) { - int key = fastKey(tilePos); +/** + * Return true if the object appears on the screen and so should be drawn. + * \param pObject MapObject* + * \param viewport const Point2D& + * \return bool + * + */ +bool MapRenderer::isObjectInsideDrawingArea(MapObject *pObject, const Point2D &viewport) { + Point2D objectViewport; + pMission_->get_map()->tileToScreenPoint(pObject->position(), &objectViewport); - if (fast_vehicle_cache_.find(key) != fast_vehicle_cache_.end()) { - // draw vehicles - for (unsigned int i = 0; i < cache_vehicles_.size(); i++) - if (cache_vehicles_[i]->tileX() == tilePos.tx - && cache_vehicles_[i]->tileY() == tilePos.ty - // NOTE: a trick to make vehicles be drawn correctly z+1 - && (cache_vehicles_[i]->tileZ() + 1) == tilePos.tz) - cache_vehicles_[i]->draw(x, y); - } + // Limits are larger than screen size in order to have a smooth display + // of appearance/disappearance of objects on screen. Otherwise they popup when + // entering the display screen. + return objectViewport.x > (viewport.x - TILE_WIDTH / 2) && objectViewport.y > viewport.y && + objectViewport.x <= (viewport.x + Screen::kScreenWidth - Screen::kScreenPanelWidth + 10) && + objectViewport.y <= (viewport.y + Screen::kScreenHeight + pObject->position().tz * 48); +} - if (fast_ped_cache_.find(key) != fast_ped_cache_.end()) { - // draw peds - for (unsigned int i = 0; i < cache_peds_.size(); i++) - if (cache_peds_[i]->sameTile(tilePos)) { - cache_peds_[i]->draw(x, y); -#if 0 - g_Screen.drawLine(x - TILE_WIDTH / 2, y, - x + TILE_WIDTH / 2, y, 11); - g_Screen.drawLine(x + TILE_WIDTH / 2, y, - x + TILE_WIDTH / 2, y + TILE_HEIGHT, - 11); - g_Screen.drawLine(x + TILE_WIDTH / 2, y + TILE_HEIGHT, - x - TILE_WIDTH / 2, y + TILE_HEIGHT, - 11); - g_Screen.drawLine(x - TILE_WIDTH / 2, y + TILE_HEIGHT, - x - TILE_WIDTH / 2, y, 11); -#endif - } +/** + * Draw all objects on the given tile. + * \param tilePos const TilePoint& tile coordinates + * \param screenPos const Point2D& position of tile on the screen + * \return int number of objects for debug + * + */ +int MapRenderer::drawObjectsOnTile(const TilePoint & tilePos, const Point2D &screenPos) { + int tileKey = tileHashKey(tilePos); + int nbDrawnObjects = 0; + + std::map<int, ObjectToDraw *>::iterator it = objectsByTile_.find(tileKey); + if(it != objectsByTile_.end()) { + ObjectToDraw *pObj = it->second; + objectsByTile_.erase(it); + while(pObj != NULL) { + pObj->getObject()->draw(screenPos.x, screenPos.y); + ObjectToDraw *pNext = pObj->getNext(); + pool_.releaseResource(pObj); + pObj = pNext; + nbDrawnObjects++; + } } - if (fast_weapon_cache_.find(key) != fast_weapon_cache_.end()) { - // draw weapons - for (unsigned int i = 0; i < cache_weapons_.size(); i++) - if (cache_weapons_[i]->map() != -1 - && cache_weapons_[i]->sameTile(tilePos)) { - cache_weapons_[i]->draw(x, y); - } + return nbDrawnObjects; +} + + +/** + * Adds an object to the list of objects to draw for the tile it's on. + * For a given tile object are sorted from back to front so that + * objects in the back are drawn first. + * \param pObjectToAdd MapObject* Object to add + * \return void + * + */ +void MapRenderer::addObjectToDraw(MapObject *pObjectToAdd) { + int tileKey; + ObjectToDraw *pNewEntry = pool_.getResource(); + pNewEntry->setObject(pObjectToAdd); + + if (pObjectToAdd->is(MapObject::kNatureVehicle)) { + // vehicle are associated with the tile just above (z+1) + // because it is bigger than a tile so all tiles below must be drawn first + TilePoint vehiclePos( pObjectToAdd->position()); + vehiclePos.tz += 1; + tileKey = tileHashKey(vehiclePos); + } else { + tileKey = tileHashKey(pObjectToAdd); } - if (fast_statics_cache_.find(key) != fast_statics_cache_.end()) { - // draw statics - for (unsigned int i = 0; i < cache_statics_.size(); i++) - if (cache_statics_[i]->sameTile(tilePos)) { - cache_statics_[i]->draw(x, y); + std::map<int, ObjectToDraw *>::iterator element = objectsByTile_.find(tileKey); + if(element == objectsByTile_.end()) { + // no element has been set with the tile so add the first element + objectsByTile_[tileKey] = pNewEntry; + } else { + // there is at leastone element already set with the tile + ObjectToDraw *pObjectInList = element->second; + if (pObjectToAdd->isBehindObjectOnSameTile(pObjectInList->getObject())) { + // first case is when the new object should be first in the list + pNewEntry->setNext(pObjectInList); + objectsByTile_[tileKey] = pNewEntry; + } else { + // second case is when new object is somewhere in the list + while (pObjectInList != NULL) { + if (pObjectInList->getNext() != NULL) { + if (pObjectToAdd->isBehindObjectOnSameTile(pObjectInList->getNext()->getObject())) { + pObjectInList->insertNext(pNewEntry); + break; + } else { + pObjectInList = pObjectInList->getNext(); + } + } else { + pObjectInList->setNext(pNewEntry); + break; + } } + } } +} - if (fast_sfx_objects_cache_.find(key) != fast_sfx_objects_cache_.end()) { - // draw sfx objects - for (unsigned int i = 0; i < cache_sfx_objects_.size(); i++) - if (cache_sfx_objects_[i]->sameTile(tilePos)) { - cache_sfx_objects_[i]->draw(x, y); - } +/** + * Objects that were listed for drawing may be bigger than objects really drawn. + * So remove those objects from the list. + * \return void + * + */ +void MapRenderer::freeUnreleasedResources() { + int nbFreed = 0; + std::map<int, ObjectToDraw *>::iterator itr = objectsByTile_.begin(); + while (itr != objectsByTile_.end()) { + std::map<int, ObjectToDraw *>::iterator toErase = itr; + ++itr; + ObjectToDraw *pObj = toErase->second; + while(pObj != NULL) { + ObjectToDraw *pNext = pObj->getNext(); + pool_.releaseResource(pObj); + nbFreed++; + pObj = pNext; + } + objectsByTile_.erase(toErase); } } Modified: freesynd/trunk/src/menus/maprenderer.h =================================================================== --- freesynd/trunk/src/menus/maprenderer.h 2016-11-08 21:54:22 UTC (rev 1012) +++ freesynd/trunk/src/menus/maprenderer.h 2017-01-23 11:03:18 UTC (rev 1013) @@ -28,10 +28,13 @@ #ifndef MENUS_MAPRENDERER_H_ #define MENUS_MAPRENDERER_H_ +#include <list> #include <vector> #include <set> +#include <map> #include "common.h" +#include "utils/log.h" #include "model/position.h" class Mission; @@ -44,21 +47,129 @@ class SFXObject; class SquadSelection; +class PoolableResource { +public: + PoolableResource() { free_ = true; } + virtual ~PoolableResource() {} + + bool isFree() { return free_; } + void setFree(bool free) { free_ = free; } + + virtual void handleRelease() {} + +private: + bool free_; +}; + +class ObjectToDraw : public PoolableResource { +public: + ObjectToDraw() { + handleRelease(); + } + + void handleRelease() { + pObject_ = NULL; + pNext_ = NULL; + } + + MapObject * getObject() { return pObject_; } + ObjectToDraw * getNext() { return pNext_; } + + void setObject(MapObject *pObj) { pObject_ = pObj; } + void setNext(ObjectToDraw *pNext) { + pNext_ = pNext; + } + void insertNext(ObjectToDraw *pNext) { + pNext->setNext(pNext_); + pNext_ = pNext; + } + + +private: + MapObject *pObject_; + ObjectToDraw *pNext_; +}; + +template<class T> +class Pool { +public: + Pool(int nbInitialRes) { + totalResourceCreated_ = 0; + for (int nbRes = 0; nbRes < nbInitialRes; nbRes++) { + pool_.push_back(new T()); + totalResourceCreated_++; + } + } + ~Pool() { + for (typename std::list < T * >::iterator it = pool_.begin(); + it != pool_.end(); it++) { + T * pRes = (*it); + delete pRes; + totalResourceCreated_--; + } + + pool_.clear(); + + if (totalResourceCreated_ > 0) { + FSERR(Log::k_FLG_MEM, "Pool", "~Pool", ("There %d unfreed resource(s)", totalResourceCreated_)); + } + }; + + T * getResource() { + T *pResource = NULL; + + if (pool_.empty()) { + pResource = new T(); + totalResourceCreated_++; + } else { + pResource = pool_.front(); + pool_.pop_front(); + } + + pResource->setFree(false); + return pResource; + } + + void releaseResource(T * pResource) { + if (!pResource->isFree()) { + pResource->handleRelease(); + pool_.push_back(pResource); + pResource->setFree(true); + } + } + +private: + std::list<T *> pool_; + int totalResourceCreated_; +}; + class MapRenderer { public: + MapRenderer() : pool_(10) {} + void init(Mission *pMission, SquadSelection *pSelection); void render(const Point2D &worldPos); private: - static int fastKey(const TilePoint & tilePos) { + /** + * Return a integer which is a hash for identifying easily + * a tile instead of use the 3 usual coordinates. + * \param tilePos + * \return int + */ + static int tileHashKey(const TilePoint & tilePos) { return tilePos.tx | (tilePos.ty << 8) | (tilePos.tz << 16); } - static int fastKey(MapObject * m); + //! Get the hashkey of the tile for the given object + static int tileHashKey(MapObject * m); - void createFastKeys(int tilex, int tiley, int maxtilex, int maxtiley); - void drawAt(const TilePoint & tilePos, int x, int y); + void listObjectsToDraw(const Point2D &viewport); + bool isObjectInsideDrawingArea(MapObject *pObject, const Point2D &viewport); + int drawObjectsOnTile(const TilePoint & tilePos, const Point2D &screenPos); + void addObjectToDraw(MapObject *pObject); + void freeUnreleasedResources(); private: Mission *pMission_; @@ -73,6 +184,10 @@ std::set<int> fast_vehicle_cache_, fast_ped_cache_, fast_weapon_cache_, fast_statics_cache_, fast_sfx_objects_cache_; + + Pool<ObjectToDraw> pool_; + /*! This map contains for each tile the list of objects to draw.*/ + std::map<int, ObjectToDraw *> objectsByTile_; }; #endif // MENUS_MAPRENDERER_H_ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-11-08 21:54:23
|
Revision: 1012 http://sourceforge.net/p/freesynd/code/1012 Author: benblan Date: 2016-11-08 21:54:22 +0000 (Tue, 08 Nov 2016) Log Message: ----------- cancel some code change on maprenderer Modified Paths: -------------- freesynd/trunk/src/menus/maprenderer.cpp freesynd/trunk/src/menus/maprenderer.h Modified: freesynd/trunk/src/menus/maprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/maprenderer.cpp 2016-10-15 06:15:54 UTC (rev 1011) +++ freesynd/trunk/src/menus/maprenderer.cpp 2016-11-08 21:54:22 UTC (rev 1012) @@ -47,48 +47,44 @@ */ void MapRenderer::render(const Point2D &worldPos) { // TODO: after a lot of attempts to fix this, map drawing remains buggy - TilePoint worldTilePos = pMap_->screenToTilePoint(worldPos.x, worldPos.y); - - int boardSize = g_Screen.gameScreenWidth() / (TILE_WIDTH / 2) + 2 + TilePoint mtp = pMap_->screenToTilePoint(worldPos.x, worldPos.y); + int sw = mtp.tx; + int chk = g_Screen.gameScreenWidth() / (TILE_WIDTH / 2) + 2 + g_Screen.gameScreenHeight() / (TILE_HEIGHT / 3) + pMap_->maxZ() * 2; - //int chk = 1; + int swm = sw + chk; + int sh = mtp.ty - 8; - Point2D enclosingStartPos = {worldTilePos.tx, worldTilePos.ty - 8}; - pMap_->clip(&enclosingStartPos); + int shm = sh + chk; - Point2D enclosingEndPos = {enclosingStartPos.x + boardSize, enclosingStartPos.y + boardSize}; - pMap_->clip(&enclosingEndPos); +#ifdef EXECUTION_SPEED_TIME + printf("---------------------------"); + int measure_ticks = SDL_GetTicks(); + printf("start time %i.%i\n", measure_ticks/1000, measure_ticks%1000); +#endif - DEBUG_SPEED_INIT - - createFastKeys(enclosingStartPos, enclosingEndPos); + createFastKeys(sw, sh, swm, shm); int cmw = worldPos.x + g_Screen.gameScreenWidth() - g_Screen.gameScreenLeftMargin() + 128; int cmh = worldPos.y + g_Screen.gameScreenHeight() + 128; int cmx = worldPos.x - g_Screen.gameScreenLeftMargin(); // z = 0 - is minimap data and mapdata - int zr = enclosingEndPos.y + pMap_->maxZ() + 1; - - int nbobject = 0; - + int chky = sh < 0 ? 0 : sh; + int zr = shm + pMap_->maxZ() + 1; for (int inc = 0; inc < zr; ++inc) { - int ye = enclosingStartPos.y + inc; + int ye = sh + inc; int ys = ye - pMap_->maxZ() - 2; int tile_z = pMap_->maxZ() + 1; // the Z coord of the next tile to draw for (int yb = ys; yb < ye; ++yb) { - if (yb < 0 || yb < enclosingStartPos.y || yb >= enclosingEndPos.y) { + if (yb < 0 || yb < sh || yb >= shm) { --tile_z; continue; } int tile_y = yb; // The Y coord of the tile to draw - for (int tile_x = enclosingStartPos.x; - tile_y >= enclosingStartPos.y && tile_x < pMap_->maxX(); - ++tile_x) { + for (int tile_x = sw; tile_y >= chky && tile_x < pMap_->maxX(); ++tile_x) { if (tile_x < 0 || tile_y >= pMap_->maxY()) { --tile_y; continue; } - int screen_w = (pMap_->maxX() + (tile_x - tile_y)) * (TILE_WIDTH / 2); // int screen_h = (max_z_ + w + h) * (TILE_HEIGHT / 3); int coord_h = ((pMap_->maxZ() + tile_x + tile_y) - (tile_z - 1)) * (TILE_HEIGHT / 3); @@ -119,11 +115,9 @@ if (tile_z - 1 >= 0) { TilePoint currentTile(tile_x, tile_y, tile_z - 1); - Point2D screenPos = { + drawAt(currentTile, screen_w - cmx + TILE_WIDTH / 2, - coord_h - worldPos.y + TILE_HEIGHT / 3 * 2}; - - nbobject += drawObjectsOnTile(currentTile, screenPos); + coord_h - worldPos.y + TILE_HEIGHT / 3 * 2); } } --tile_y; @@ -148,8 +142,15 @@ return fastKey(m->position()); } -void MapRenderer::createFastKeys(const Point2D &startPos, const Point2D &endPos) { - int nbobject = 0; +void MapRenderer::createFastKeys(int tilex, int tiley, int maxtilex, int maxtiley) { + if (tilex < 0) + tilex = 0; + if (tiley < 0) + tiley = 0; + if (maxtilex >= pMap_->maxX()) + maxtilex = pMap_->maxX(); + if (maxtiley >= pMap_->maxY()) + maxtiley = pMap_->maxY(); cache_vehicles_.clear(); cache_peds_.clear(); @@ -167,8 +168,8 @@ for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { PedInstance *p = pMission_->getSquad()->member(i); if (p != NULL && p->isAlive()) { - if (p->tileX() >= startPos.x && p->tileX() < endPos.x - && p->tileY() >= startPos.y && p->tileY() < endPos.y) { + if (p->tileX() >= tilex && p->tileX() < maxtilex + && p->tileY() >= tiley && p->tileY() < maxtiley) { // sfx_objects_[i]->setPosition(p->tileX(), p->tileY(), p->tileZ(), // p->offX(), p->offY(), p->offZ() + 320); pMission_->sfxObjects(i + 4)->setPosition(p->tileX(), p->tileY(), @@ -183,14 +184,13 @@ // vehicles for (unsigned int i = 0; i < pMission_->numVehicles(); i++) { Vehicle *v = pMission_->vehicle(i); - if (v->tileX() >= startPos.x && v->tileX() < endPos.x - && v->tileY() >= startPos.y && v->tileY() < endPos.y) { + if (v->tileX() >= tilex && v->tileX() < maxtilex + && v->tileY() >= tiley && v->tileY() < maxtiley) { // NOTE: a trick to make vehicles be drawn correctly z+1 TilePoint tilePos( v->position()); tilePos.tz += 1; fast_vehicle_cache_.insert(fastKey(tilePos)); cache_vehicles_.push_back(v); - nbobject++; } } @@ -198,23 +198,20 @@ for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { PedInstance *p = pMission_->getSquad()->member(i); if (p != NULL && p->map() != -1) { - if (p->tileX() >= startPos.x && p->tileX() < endPos.x - && p->tileY() >= startPos.y && p->tileY() < endPos.y) { + if (p->tileX() >= tilex && p->tileX() < maxtilex + && p->tileY() >= tiley && p->tileY() < maxtiley) { fast_ped_cache_.insert(fastKey(p)); cache_peds_.push_back(p); - - nbobject++; } } } for (size_t i = pMission_->getSquad()->size(); i < pMission_->numPeds(); i++) { PedInstance *p = pMission_->ped(i); if (p->map() != -1) { - if (p->tileX() >= startPos.x && p->tileX() < endPos.x - && p->tileY() >= startPos.y && p->tileY() < endPos.y) { + if (p->tileX() >= tilex && p->tileX() < maxtilex + && p->tileY() >= tiley && p->tileY() < maxtiley) { fast_ped_cache_.insert(fastKey(p)); cache_peds_.push_back(p); - nbobject++; } } } @@ -222,47 +219,36 @@ // weapons for (unsigned int i = 0; i < pMission_->numWeapons(); i++) { WeaponInstance *w = pMission_->weapon(i); - if (w->map() != -1 && w->tileX() >= startPos.x && w->tileX() < endPos.x - && w->tileY() >= startPos.y && w->tileY() < endPos.y) { + if (w->map() != -1 && w->tileX() >= tilex && w->tileX() < maxtilex + && w->tileY() >= tiley && w->tileY() < maxtiley) { fast_weapon_cache_.insert(fastKey(w)); cache_weapons_.push_back(w); - nbobject++; } } // statics for (unsigned int i = 0; i < pMission_->numStatics(); i++) { Static *s = pMission_->statics(i); - if (s->tileX() >= startPos.x && s->tileX() < endPos.x - && s->tileY() >= startPos.y && s->tileY() < endPos.y) { + if (s->tileX() >= tilex && s->tileX() < maxtilex + && s->tileY() >= tiley && s->tileY() < maxtiley) { fast_statics_cache_.insert(fastKey(s)); cache_statics_.push_back(s); - nbobject++; } } // sfx objects for (unsigned int i = 0; i < pMission_->numSfxObjects(); i++) { SFXObject *so = pMission_->sfxObjects(i); - if (so->map() != -1 && so->tileX() >= startPos.x && so->tileX() < endPos.x - && so->tileY() >= startPos.y && so->tileY() < endPos.y) { + if (so->map() != -1 && so->tileX() >= tilex && so->tileX() < maxtilex + && so->tileY() >= tiley && so->tileY() < maxtiley) { fast_sfx_objects_cache_.insert(fastKey(so)); cache_sfx_objects_.push_back(so); - nbobject++; } } } -/*! - * Draw on screen all objects that have their position on the given tile. - * \param tilePos const TilePoint& Tile's position - * \param screenPos const Point2D& Screen position to draw the objects - * \return int - * - */ -int MapRenderer::drawObjectsOnTile(const TilePoint & tilePos, const Point2D &screenPos) { +void MapRenderer::drawAt(const TilePoint & tilePos, int x, int y) { int key = fastKey(tilePos); - int nbobject = 0; if (fast_vehicle_cache_.find(key) != fast_vehicle_cache_.end()) { // draw vehicles @@ -271,18 +257,14 @@ && cache_vehicles_[i]->tileY() == tilePos.ty // NOTE: a trick to make vehicles be drawn correctly z+1 && (cache_vehicles_[i]->tileZ() + 1) == tilePos.tz) - cache_vehicles_[i]->draw(screenPos.x, screenPos.y); - nbobject++; + cache_vehicles_[i]->draw(x, y); } if (fast_ped_cache_.find(key) != fast_ped_cache_.end()) { // draw peds for (unsigned int i = 0; i < cache_peds_.size(); i++) if (cache_peds_[i]->sameTile(tilePos)) { - cache_peds_[i]->draw(screenPos.x, screenPos.y); - - nbobject++; - + cache_peds_[i]->draw(x, y); #if 0 g_Screen.drawLine(x - TILE_WIDTH / 2, y, x + TILE_WIDTH / 2, y, 11); @@ -303,8 +285,7 @@ for (unsigned int i = 0; i < cache_weapons_.size(); i++) if (cache_weapons_[i]->map() != -1 && cache_weapons_[i]->sameTile(tilePos)) { - cache_weapons_[i]->draw(screenPos.x, screenPos.y); - nbobject++; + cache_weapons_[i]->draw(x, y); } } @@ -312,8 +293,7 @@ // draw statics for (unsigned int i = 0; i < cache_statics_.size(); i++) if (cache_statics_[i]->sameTile(tilePos)) { - cache_statics_[i]->draw(screenPos.x, screenPos.y); - nbobject++; + cache_statics_[i]->draw(x, y); } } @@ -321,10 +301,7 @@ // draw sfx objects for (unsigned int i = 0; i < cache_sfx_objects_.size(); i++) if (cache_sfx_objects_[i]->sameTile(tilePos)) { - cache_sfx_objects_[i]->draw(screenPos.x, screenPos.y); - nbobject++; + cache_sfx_objects_[i]->draw(x, y); } } - - return nbobject; } Modified: freesynd/trunk/src/menus/maprenderer.h =================================================================== --- freesynd/trunk/src/menus/maprenderer.h 2016-10-15 06:15:54 UTC (rev 1011) +++ freesynd/trunk/src/menus/maprenderer.h 2016-11-08 21:54:22 UTC (rev 1012) @@ -57,8 +57,8 @@ static int fastKey(MapObject * m); - void createFastKeys(const Point2D &startPos, const Point2D &endPos); - int drawObjectsOnTile(const TilePoint & tilePos, const Point2D &screenPos); + void createFastKeys(int tilex, int tiley, int maxtilex, int maxtiley); + void drawAt(const TilePoint & tilePos, int x, int y); private: Mission *pMission_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-10-15 06:15:57
|
Revision: 1011 http://sourceforge.net/p/freesynd/code/1011 Author: benblan Date: 2016-10-15 06:15:54 +0000 (Sat, 15 Oct 2016) Log Message: ----------- - new property MapObject::isVisible to replace the "map == -1" rule for displaying object - Added weapons and sfxobject in the new rendering process - change location of updating agent markers position from MapRenderer to GameplayMenu Modified Paths: -------------- freesynd/branches/fix-render/src/mapobject.h freesynd/branches/fix-render/src/menus/gameplaymenu.cpp freesynd/branches/fix-render/src/menus/gameplaymenu.h freesynd/branches/fix-render/src/menus/maprenderer.cpp Modified: freesynd/branches/fix-render/src/mapobject.h =================================================================== --- freesynd/branches/fix-render/src/mapobject.h 2016-10-12 20:28:47 UTC (rev 1010) +++ freesynd/branches/fix-render/src/mapobject.h 2016-10-15 06:15:54 UTC (rev 1011) @@ -67,6 +67,19 @@ //! Return the object's id uint16 id() { return id_; } + void setVisible(bool visible) { + isVisible_ = visible; + // TODO : remove when isVisible is active + if (!isVisible_) { + map_ = -1; + } + } + + bool isVisible() { + // TODO : replace with isvisible_ + return map_ != -1; + } + virtual void draw(int x, int y) = 0; enum DamageType { dmg_None = 0x0000, @@ -274,6 +287,9 @@ void offzOnStairs(uint8 twd); protected: + void addOffs(int &x, int &y); + +protected: //! the nature of this object ObjectNature nature_; //! Id of the object. Id is unique within a nature @@ -286,6 +302,8 @@ int size_x_, size_y_, size_z_; //! if equal -1 object is not on map and should not be drawn int map_; + //! Object should be drawn only if visible + bool isVisible_; //! animation frame changing int frame_; /*! @@ -307,8 +325,6 @@ */ bool is_frame_drawn_; uint32 state_; - - void addOffs(int &x, int &y); }; /*! Modified: freesynd/branches/fix-render/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/branches/fix-render/src/menus/gameplaymenu.cpp 2016-10-12 20:28:47 UTC (rev 1010) +++ freesynd/branches/fix-render/src/menus/gameplaymenu.cpp 2016-10-15 06:15:54 UTC (rev 1011) @@ -215,7 +215,8 @@ menu_manager_->setPaletteForMission(g_Session.getSelectedBlock().mis_id); g_Screen.clear(0); - updtAgentsMarker(); + highlightLeaderMarker(); + updateMarkersPosition(); // Init renderers map_renderer_.init(mission_, &selection_); @@ -290,6 +291,8 @@ for (size_t i = 0; i < mission_->numPeds(); i++) change |= mission_->ped(i)->animate(diff, mission_); + updateMarkersPosition(); + for (size_t i = 0; i < mission_->numVehicles(); i++) change |= mission_->vehicle(i)->animate(diff); @@ -325,7 +328,7 @@ { g_Screen.clear(0); map_renderer_.render(viewPortOrigin_); - g_Screen.drawRect(0,0, 129, GAME_SCREEN_HEIGHT); + g_Screen.drawRect(0,0, Screen::kScreenPanelWidth, Screen::kScreenHeight); agt_sel_renderer_.render(selection_, mission_->getSquad()); drawSelectAllButton(); drawMissionHint(0); @@ -345,7 +348,7 @@ for (int i = 1756; i < g_App.gameSprites().spriteCount(); i++) { Sprite *s = g_App.gameSprites().sprite(i); - if (y + s->height() > GAME_SCREEN_HEIGHT) { + if (y + s->height() > Screen::kScreenHeight) { printf("last sprite %i\n", i - 1); break; } @@ -523,19 +526,12 @@ for (size_t i = 0; mission_ && i < mission_->numWeapons(); ++i) { WeaponInstance *w = mission_->weapon(i); - if (w->map() != -1) { - Point2D scPt; - mission_->get_map()->tileToScreenPoint(w->position(), &scPt); - int px = scPt.x - 10; - int py = scPt.y + 4 - w->tileZ() * TILE_HEIGHT/3 - - (w->offZ() * TILE_HEIGHT/3) / 128; + mission_->get_map()->tileToViewportCoords(w->position(), &objPosInViewportPt); - if (x - 129 + viewPortOrigin_.x >= px && y + viewPortOrigin_.y >= py && - x - 129 + viewPortOrigin_.x < px + 20 && y + viewPortOrigin_.y < py + 15) - { - target_ = w; - break; - } + if (isMouseOnObject(mouseInViewport, objPosInViewportPt, 4, -12, 10, 5)) { + // mouse pointer is on the object, so it's the new target + target_ = w; + break; } } #if 0 @@ -1254,7 +1250,7 @@ if (selection_.selectAgent(agentNo, addToGroup)) { updateSelectAll(); centerMinimapOnLeader(); - updtAgentsMarker(); + highlightLeaderMarker(); g_App.gameSounds().play(snd::SPEECH_SELECTED); // redraw agent selectors @@ -1283,14 +1279,35 @@ * Make the current leader marker blinks. * All other agents not. */ -void GameplayMenu::updtAgentsMarker() +void GameplayMenu::highlightLeaderMarker() { for (size_t i = AgentManager::kSlot1; i < AgentManager::kMaxSlot; i++) { - // draw animation only for leader - mission_->sfxObjects(4 + i)->setDrawAllFrames(selection_.getLeaderSlot() == i); + PedInstance *pAgent = mission_->getSquad()->member(i); + if (pAgent == NULL || pAgent->isDead()) { + mission_->sfxObjects(4 + i)->setVisible(false); + } else { + // draw animation only for leader + mission_->sfxObjects(4 + i)->setDrawAllFrames(selection_.getLeaderSlot() == i); + } } } +/** + * Updating position for visual markers for all agents. + * \return void + * + */ +void GameplayMenu::updateMarkersPosition() { + for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { + if (mission_->sfxObjects(i + 4)->isVisible()) { + TilePoint agentPos = mission_->getSquad()->member(i)->position(); + agentPos.ox -= 16; + agentPos.oz += 256; + + mission_->sfxObjects(i + 4)->setPosition(agentPos); + } + } +} /*! * This method checks among the squad to see if an agent died and deselects him. */ @@ -1310,7 +1327,7 @@ } // anyway updates markers - updtAgentsMarker(); + highlightLeaderMarker(); updateSelectAll(); } Modified: freesynd/branches/fix-render/src/menus/gameplaymenu.h =================================================================== --- freesynd/branches/fix-render/src/menus/gameplaymenu.h 2016-10-12 20:28:47 UTC (rev 1010) +++ freesynd/branches/fix-render/src/menus/gameplaymenu.h 2016-10-15 06:15:54 UTC (rev 1011) @@ -92,8 +92,10 @@ //! Deselect agent if he died void updateSelectionForDeadAgent(PedInstance *p_ped); - //! updates visual markers for our agents - void updtAgentsMarker(); + //! Make leader's marker blink + void highlightLeaderMarker(); + //! Make markers aligned with each agent position + void updateMarkersPosition(); //! Set pLocWToSet param with point on the map where player clicked to shoot bool getAimedAt(int x, int y, WorldPoint *pLocWToSet); void stopShootingEvent(); Modified: freesynd/branches/fix-render/src/menus/maprenderer.cpp =================================================================== --- freesynd/branches/fix-render/src/menus/maprenderer.cpp 2016-10-12 20:28:47 UTC (rev 1010) +++ freesynd/branches/fix-render/src/menus/maprenderer.cpp 2016-10-15 06:15:54 UTC (rev 1011) @@ -160,11 +160,11 @@ freeUnreleasedResources(); - /*if (debugScreenPos.x != 0) { - g_Screen.drawLine(debugScreenPos.x, debugScreenPos.y, debugScreenPos.x + TILE_WIDTH, debugScreenPos.y, 11); - g_Screen.drawLine(debugScreenPos.x + TILE_WIDTH, debugScreenPos.y, debugScreenPos.x + TILE_WIDTH, debugScreenPos.y + TILE_HEIGHT, 11); - g_Screen.drawLine(debugScreenPos.x, debugScreenPos.y, debugScreenPos.x, debugScreenPos.y + TILE_HEIGHT, 11); - g_Screen.drawLine(debugScreenPos.x, debugScreenPos.y + TILE_HEIGHT, debugScreenPos.x + TILE_WIDTH, debugScreenPos.y + TILE_HEIGHT, 11); + /*if (point != NULL) { + g_Screen.drawLine(point.x, point.y, point.x + 5, point.y, 11); + g_Screen.drawLine(point.x + 5, point.y, point.x + 5, point.y + 5, 11); + g_Screen.drawLine(point.x, point.y, point.x, point.y + 5, 11); + g_Screen.drawLine(point.x, point.y + 5, point.x + 5, point.y + 5, 11); }*/ DEBUG_SPEED_LOG("MapRenderer::render") @@ -241,12 +241,26 @@ // Include peds for (size_t i = 0; i < pMission_->numPeds(); i++) { PedInstance *pPed = pMission_->ped(i); - if (pPed->map() != -1) { - if (isObjectInsideDrawingArea(pPed, viewport)) { - addObjectToDraw(pPed); - } + if (pPed->isVisible() && isObjectInsideDrawingArea(pPed, viewport)) { + addObjectToDraw(pPed); } } + + // weapons + for (size_t i = 0; i < pMission_->numWeapons(); i++) { + WeaponInstance *pWeapon = pMission_->weapon(i); + if (pWeapon->isVisible() && isObjectInsideDrawingArea(pWeapon, viewport)) { + addObjectToDraw(pWeapon); + } + } + + // sfx objects + for (size_t i = 0; i < pMission_->numSfxObjects(); i++) { + SFXObject *pSfx = pMission_->sfxObjects(i); + if (pSfx->isVisible() && isObjectInsideDrawingArea(pSfx, viewport)) { + addObjectToDraw(pSfx); + } + } } bool MapRenderer::isObjectInsideDrawingArea(MapObject *pObject, const Point2D &viewport) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-09-03 06:06:33
|
Revision: 1009 http://sourceforge.net/p/freesynd/code/1009 Author: benblan Date: 2016-09-03 06:06:31 +0000 (Sat, 03 Sep 2016) Log Message: ----------- This branch is used to fix map rendering bugs Added Paths: ----------- freesynd/branches/fix-render/ Index: freesynd/branches/fix-render =================================================================== --- freesynd/trunk 2016-07-18 18:06:29 UTC (rev 1008) +++ freesynd/branches/fix-render 2016-09-03 06:06:31 UTC (rev 1009) Property changes on: freesynd/branches/fix-render ___________________________________________________________________ Added: svn:ignore ## -0,0 +1,4 ## +CMakeCache.txt +CMakeFiles +Makefile +cmake_install.cmake Added: svn:mergeinfo ## -0,0 +1,3 ## +/freesynd/branches/cmake:496-499 +/freesynd/branches/rework-actions:937-984 +/freesynd/branches/trunk-r608-feature-3202739:610-615 \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-07-18 18:06:32
|
Revision: 1008 http://sourceforge.net/p/freesynd/code/1008 Author: benblan Date: 2016-07-18 18:06:29 +0000 (Mon, 18 Jul 2016) Log Message: ----------- - Renamed ScreenPoint to Point2D and moved in common.h - New macro to manage code performance measurement - Some refactoring in MapRenderer for better readability Modified Paths: -------------- freesynd/trunk/src/common.h freesynd/trunk/src/config.h freesynd/trunk/src/map.cpp freesynd/trunk/src/map.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/gameplaymenu.h freesynd/trunk/src/menus/maprenderer.cpp freesynd/trunk/src/menus/maprenderer.h freesynd/trunk/src/model/position.h freesynd/trunk/src/ped.cpp Modified: freesynd/trunk/src/common.h =================================================================== --- freesynd/trunk/src/common.h 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/common.h 2016-07-18 18:06:29 UTC (rev 1008) @@ -170,6 +170,14 @@ left = (x1 < x2) ? x1 : x2; } +/*! + * A structure to store a point defined with 2 coordinates. + */ +struct Point2D { + int x; + int y; +}; + #define IS_FLAG_SET(field, flags) (field & flags) != 0 #define SET_FLAG(field, flags) field |= flags Modified: freesynd/trunk/src/config.h =================================================================== --- freesynd/trunk/src/config.h 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/config.h 2016-07-18 18:06:29 UTC (rev 1008) @@ -36,4 +36,17 @@ // Define this to display frame rate during gameplay //define TRACK_FPS 1 +// Set this to enable speed measurement of code execution +// 0 > disable +// 1 > map renderer +#define EXEC_SPEED_TIME 0 + +#if EXEC_SPEED_TIME == 1 +#define DEBUG_SPEED_INIT int start_mesure_ticks = SDL_GetTicks(); +#define DEBUG_SPEED_LOG(module) printf("%s - speed : %i\n", module, SDL_GetTicks() - start_mesure_ticks); +#else +#define DEBUG_SPEED_INIT +#define DEBUG_SPEED_LOG(module) #endif + +#endif Modified: freesynd/trunk/src/map.cpp =================================================================== --- freesynd/trunk/src/map.cpp 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/map.cpp 2016-07-18 18:06:29 UTC (rev 1008) @@ -116,13 +116,27 @@ y = maxY() - 1; } +void Map::clip(Point2D *pPoint) { + if (pPoint->x < 0) { + pPoint->x = 0; + } else if (pPoint->x >= maxX()) { + pPoint->x = maxX(); + } + + if (pPoint->y < 0) { + pPoint->y = 0; + } else if (pPoint->y >= maxY()) { + pPoint->y = maxY(); + } +} + float scalexPx = 256.0f; float scalexPy = 256.0f; float scaleyPx = 256.0f; float scaleyPy = 256.0f; -void Map::tileToScreenPoint(int x, int y, int z, int pX, int pY, ScreenPoint *pScp) +void Map::tileToScreenPoint(int x, int y, int z, int pX, int pY, Point2D *pScp) { float fx = x + pX / scalexPx; float fy = y + pY / scalexPy; @@ -133,7 +147,7 @@ pScp->y = (int) ((max_z_ + 1) * TILE_HEIGHT / 3 + (fx + fy) * TILE_HEIGHT / 3); } -void Map::tileToScreenPoint(const TilePoint &tPt, ScreenPoint *pScp) { +void Map::tileToScreenPoint(const TilePoint &tPt, Point2D *pScp) { tileToScreenPoint(tPt.tx, tPt.ty, tPt.tz, tPt.ox, tPt.oy, pScp); } Modified: freesynd/trunk/src/map.h =================================================================== --- freesynd/trunk/src/map.h 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/map.h 2016-07-18 18:06:29 UTC (rev 1008) @@ -51,10 +51,12 @@ void mapDimensions(int *x, int *y, int *z); //! Clip x,y,z to map dimensions void adjXYZ(int &x, int &y, int &z); + //! Clip x and y to map dimensions. + void clip(Point2D *point); //! Converts a Map tile position to a screen position - void tileToScreenPoint(int x, int y, int z, int pX, int pY, ScreenPoint *pScp); - void tileToScreenPoint(const TilePoint &tPt, ScreenPoint *pScp); + void tileToScreenPoint(int x, int y, int z, int pX, int pY, Point2D *pScp); + void tileToScreenPoint(const TilePoint &tPt, Point2D *pScp); //! Converts a screen position in pixel into a Map tile position TilePoint screenToTilePoint(int x, int y); Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2016-07-18 18:06:29 UTC (rev 1008) @@ -245,7 +245,7 @@ { // get the leader position on the map PedInstance *p_leader = selection_.leader(); - ScreenPoint start; + Point2D start; mission_->get_map()->tileToScreenPoint(p_leader->tileX(), p_leader->tileY(), mission_->mmax_z_ + 1, 0, 0, &start); start.x -= (GAME_SCREEN_WIDTH - 129) / 2; @@ -273,7 +273,7 @@ mpt.ty = mission_->maxY(); // recalculating new screen coords - ScreenPoint msp; + Point2D msp; mission_->get_map()->tileToScreenPoint(mpt.tx, mpt.ty, mission_->mmax_z_ + 1, 0, 0, &msp); displayOriginPt_.x = msp.x; @@ -301,7 +301,7 @@ updtAgentsMarker(); // Init renderers - map_renderer_.init(mission_); + map_renderer_.init(mission_, &selection_); mm_renderer_.init(mission_, mission_->getSquad()->hasScanner()); centerMinimapOnLeader(); isPlayerShooting_ = false; @@ -400,7 +400,7 @@ void GameplayMenu::handleRender(DirtyList &dirtyList) { g_Screen.clear(0); - map_renderer_.render(displayOriginPt_.x, displayOriginPt_.y, &selection_); + map_renderer_.render(displayOriginPt_); g_Screen.drawRect(0,0, 129, GAME_SCREEN_HEIGHT); agt_sel_renderer_.render(selection_, mission_->getSquad()); drawSelectAllButton(); @@ -545,7 +545,7 @@ #endif PedInstance *p = mission_->ped(i); if (p->isAlive() && p->map() != -1) { - ScreenPoint scPt; + Point2D scPt; mission_->get_map()->tileToScreenPoint(p->position(), &scPt); int px = scPt.x - 10; int py = scPt.y - (1 + p->tileZ()) * TILE_HEIGHT/3 @@ -565,7 +565,7 @@ for (size_t i = 0; mission_ && i < mission_->numVehicles(); ++i) { Vehicle *v = mission_->vehicle(i); if (v->isAlive()) { - ScreenPoint scPt; + Point2D scPt; mission_->get_map()->tileToScreenPoint(v->position(), &scPt); int px = scPt.x - 20; int py = scPt.y - 10 - v->tileZ() * TILE_HEIGHT/3; @@ -584,7 +584,7 @@ WeaponInstance *w = mission_->weapon(i); if (w->map() != -1) { - ScreenPoint scPt; + Point2D scPt; mission_->get_map()->tileToScreenPoint(w->position(), &scPt); int px = scPt.x - 10; int py = scPt.y + 4 - w->tileZ() * TILE_HEIGHT/3 @@ -604,7 +604,7 @@ Static *s = mission_->statics(i); if (s->map() != -1) { - ScreenPoint scPt; + Point2D scPt; mission_->get_map()->tileToScreenPoint(w->position(), &scPt); int px = scPt.x - 10; int py = scPt.y + 4 - s->tileZ() * TILE_HEIGHT/3 Modified: freesynd/trunk/src/menus/gameplaymenu.h =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.h 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/menus/gameplaymenu.h 2016-07-18 18:06:29 UTC (rev 1008) @@ -111,7 +111,7 @@ /*! This is a projection in 2D of a point on a the map. This point represents the top * left corner of the screen and it moves inside the map's borders.*/ - ScreenPoint displayOriginPt_; + Point2D displayOriginPt_; /*! Holds the amount of scroll on the X axis.*/ int scroll_x_; /*! Holds the amount of scroll on the Y axis.*/ Modified: freesynd/trunk/src/menus/maprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/maprenderer.cpp 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/menus/maprenderer.cpp 2016-07-18 18:06:29 UTC (rev 1008) @@ -26,7 +26,6 @@ ************************************************************************/ #include "menus/maprenderer.h" -#include "common.h" #include "mission.h" #include "model/vehicle.h" #include "agentmanager.h" @@ -37,60 +36,65 @@ #include "system.h" #include "menus/squadselection.h" -void MapRenderer::init(Mission *pMission) { +void MapRenderer::init(Mission *pMission, SquadSelection *pSelection) { pMission_ = pMission; pMap_ = pMission->get_map(); + pSelection_ = pSelection; } /** * Draw tiles and map objects. */ -void MapRenderer::render(int worldX, int worldY, SquadSelection *pSelection) { +void MapRenderer::render(const Point2D &worldPos) { // TODO: after a lot of attempts to fix this, map drawing remains buggy - TilePoint mtp = pMap_->screenToTilePoint(worldX, worldY); - int sw = mtp.tx; - int chk = g_Screen.gameScreenWidth() / (TILE_WIDTH / 2) + 2 + TilePoint worldTilePos = pMap_->screenToTilePoint(worldPos.x, worldPos.y); + + int boardSize = g_Screen.gameScreenWidth() / (TILE_WIDTH / 2) + 2 + g_Screen.gameScreenHeight() / (TILE_HEIGHT / 3) + pMap_->maxZ() * 2; - int swm = sw + chk; - int sh = mtp.ty - 8; + //int chk = 1; - int shm = sh + chk; + Point2D enclosingStartPos = {worldTilePos.tx, worldTilePos.ty - 8}; + pMap_->clip(&enclosingStartPos); -#ifdef EXECUTION_SPEED_TIME - printf("---------------------------"); - int measure_ticks = SDL_GetTicks(); - printf("start time %i.%i\n", measure_ticks/1000, measure_ticks%1000); -#endif + Point2D enclosingEndPos = {enclosingStartPos.x + boardSize, enclosingStartPos.y + boardSize}; + pMap_->clip(&enclosingEndPos); - createFastKeys(sw, sh, swm, shm); - int cmw = worldX + g_Screen.gameScreenWidth() - + DEBUG_SPEED_INIT + + createFastKeys(enclosingStartPos, enclosingEndPos); + int cmw = worldPos.x + g_Screen.gameScreenWidth() - g_Screen.gameScreenLeftMargin() + 128; - int cmh = worldY + g_Screen.gameScreenHeight() + 128; - int cmx = worldX - g_Screen.gameScreenLeftMargin(); + int cmh = worldPos.y + g_Screen.gameScreenHeight() + 128; + int cmx = worldPos.x - g_Screen.gameScreenLeftMargin(); // z = 0 - is minimap data and mapdata - int chky = sh < 0 ? 0 : sh; - int zr = shm + pMap_->maxZ() + 1; + int zr = enclosingEndPos.y + pMap_->maxZ() + 1; + + int nbobject = 0; + for (int inc = 0; inc < zr; ++inc) { - int ye = sh + inc; + int ye = enclosingStartPos.y + inc; int ys = ye - pMap_->maxZ() - 2; int tile_z = pMap_->maxZ() + 1; // the Z coord of the next tile to draw for (int yb = ys; yb < ye; ++yb) { - if (yb < 0 || yb < sh || yb >= shm) { + if (yb < 0 || yb < enclosingStartPos.y || yb >= enclosingEndPos.y) { --tile_z; continue; } int tile_y = yb; // The Y coord of the tile to draw - for (int tile_x = sw; tile_y >= chky && tile_x < pMap_->maxX(); ++tile_x) { + for (int tile_x = enclosingStartPos.x; + tile_y >= enclosingStartPos.y && tile_x < pMap_->maxX(); + ++tile_x) { if (tile_x < 0 || tile_y >= pMap_->maxY()) { --tile_y; continue; } + int screen_w = (pMap_->maxX() + (tile_x - tile_y)) * (TILE_WIDTH / 2); // int screen_h = (max_z_ + w + h) * (TILE_HEIGHT / 3); int coord_h = ((pMap_->maxZ() + tile_x + tile_y) - (tile_z - 1)) * (TILE_HEIGHT / 3); - if (screen_w >= worldX - TILE_WIDTH * 2 + if (screen_w >= worldPos.x - TILE_WIDTH * 2 && screen_w + TILE_WIDTH * 2 < cmw - && coord_h >= worldY - TILE_HEIGHT * 2 + && coord_h >= worldPos.y - TILE_HEIGHT * 2 && coord_h + TILE_HEIGHT * 2 < cmh) { #if 0 if (z > 2) @@ -101,21 +105,25 @@ Tile *p_tile = pMap_->getTileAt(tile_x, tile_y, tile_z); if (p_tile->notTransparent()) { int dx = 0, dy = 0; - if (screen_w - worldX < 0) - dx = -(screen_w - worldX); - if (coord_h - worldY < 0) - dy = -(coord_h - worldY); + if (screen_w - worldPos.x < 0) + dx = -(screen_w - worldPos.x); + if (coord_h - worldPos.y < 0) + dy = -(coord_h - worldPos.y); if (dx < TILE_WIDTH && dy < TILE_HEIGHT) { - p_tile->drawToScreen(screen_w - cmx, coord_h - worldY); + p_tile->drawToScreen(screen_w - cmx, coord_h - worldPos.y); } } } // draw everything that's on the tile if (tile_z - 1 >= 0) { - drawAt(tile_x, tile_y, tile_z - 1, + TilePoint currentTile(tile_x, tile_y, tile_z - 1); + + Point2D screenPos = { screen_w - cmx + TILE_WIDTH / 2, - coord_h - worldY + TILE_HEIGHT / 3 * 2); + coord_h - worldPos.y + TILE_HEIGHT / 3 * 2}; + + nbobject += drawObjectsOnTile(currentTile, screenPos); } } --tile_y; @@ -126,34 +134,22 @@ #ifdef _DEBUG if (g_System.getKeyModState() & KMD_LALT) { - for (SquadSelection::Iterator it = pSelection->begin(); - it != pSelection->end(); ++it) { - (*it)->showPath(worldX, worldY); + for (SquadSelection::Iterator it = pSelection_->begin(); + it != pSelection_->end(); ++it) { + (*it)->showPath(worldPos.x, worldPos.y); } } #endif -#ifdef EXECUTION_SPEED_TIME - printf("+++++++++++++++++++++++++++"); - int measure_ticks_end = SDL_GetTicks(); - printf("end time %i.%i,%i\n", measure_ticks_end/1000, measure_ticks_end%1000, - measure_ticks_end - measure_ticks); -#endif + DEBUG_SPEED_LOG("MapRenderer::render") } int MapRenderer::fastKey(MapObject * m) { - return fastKey(m->tileX(), m->tileY(), m->tileZ()); + return fastKey(m->position()); } -void MapRenderer::createFastKeys(int tilex, int tiley, int maxtilex, int maxtiley) { - if (tilex < 0) - tilex = 0; - if (tiley < 0) - tiley = 0; - if (maxtilex >= pMap_->maxX()) - maxtilex = pMap_->maxX(); - if (maxtiley >= pMap_->maxY()) - maxtiley = pMap_->maxY(); +void MapRenderer::createFastKeys(const Point2D &startPos, const Point2D &endPos) { + int nbobject = 0; cache_vehicles_.clear(); cache_peds_.clear(); @@ -171,8 +167,8 @@ for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { PedInstance *p = pMission_->getSquad()->member(i); if (p != NULL && p->isAlive()) { - if (p->tileX() >= tilex && p->tileX() < maxtilex - && p->tileY() >= tiley && p->tileY() < maxtiley) { + if (p->tileX() >= startPos.x && p->tileX() < endPos.x + && p->tileY() >= startPos.y && p->tileY() < endPos.y) { // sfx_objects_[i]->setPosition(p->tileX(), p->tileY(), p->tileZ(), // p->offX(), p->offY(), p->offZ() + 320); pMission_->sfxObjects(i + 4)->setPosition(p->tileX(), p->tileY(), @@ -187,12 +183,14 @@ // vehicles for (unsigned int i = 0; i < pMission_->numVehicles(); i++) { Vehicle *v = pMission_->vehicle(i); - if (v->tileX() >= tilex && v->tileX() < maxtilex - && v->tileY() >= tiley && v->tileY() < maxtiley) { + if (v->tileX() >= startPos.x && v->tileX() < endPos.x + && v->tileY() >= startPos.y && v->tileY() < endPos.y) { // NOTE: a trick to make vehicles be drawn correctly z+1 - fast_vehicle_cache_.insert(fastKey(v->tileX(), - v->tileY(), v->tileZ() + 1)); + TilePoint tilePos( v->position()); + tilePos.tz += 1; + fast_vehicle_cache_.insert(fastKey(tilePos)); cache_vehicles_.push_back(v); + nbobject++; } } @@ -200,20 +198,23 @@ for (size_t i = 0; i < AgentManager::kMaxSlot; i++) { PedInstance *p = pMission_->getSquad()->member(i); if (p != NULL && p->map() != -1) { - if (p->tileX() >= tilex && p->tileX() < maxtilex - && p->tileY() >= tiley && p->tileY() < maxtiley) { + if (p->tileX() >= startPos.x && p->tileX() < endPos.x + && p->tileY() >= startPos.y && p->tileY() < endPos.y) { fast_ped_cache_.insert(fastKey(p)); cache_peds_.push_back(p); + + nbobject++; } } } for (size_t i = pMission_->getSquad()->size(); i < pMission_->numPeds(); i++) { PedInstance *p = pMission_->ped(i); if (p->map() != -1) { - if (p->tileX() >= tilex && p->tileX() < maxtilex - && p->tileY() >= tiley && p->tileY() < maxtiley) { + if (p->tileX() >= startPos.x && p->tileX() < endPos.x + && p->tileY() >= startPos.y && p->tileY() < endPos.y) { fast_ped_cache_.insert(fastKey(p)); cache_peds_.push_back(p); + nbobject++; } } } @@ -221,54 +222,67 @@ // weapons for (unsigned int i = 0; i < pMission_->numWeapons(); i++) { WeaponInstance *w = pMission_->weapon(i); - if (w->map() != -1 && w->tileX() >= tilex && w->tileX() < maxtilex - && w->tileY() >= tiley && w->tileY() < maxtiley) { + if (w->map() != -1 && w->tileX() >= startPos.x && w->tileX() < endPos.x + && w->tileY() >= startPos.y && w->tileY() < endPos.y) { fast_weapon_cache_.insert(fastKey(w)); cache_weapons_.push_back(w); + nbobject++; } } // statics for (unsigned int i = 0; i < pMission_->numStatics(); i++) { Static *s = pMission_->statics(i); - if (s->tileX() >= tilex && s->tileX() < maxtilex - && s->tileY() >= tiley && s->tileY() < maxtiley) { + if (s->tileX() >= startPos.x && s->tileX() < endPos.x + && s->tileY() >= startPos.y && s->tileY() < endPos.y) { fast_statics_cache_.insert(fastKey(s)); cache_statics_.push_back(s); + nbobject++; } } // sfx objects for (unsigned int i = 0; i < pMission_->numSfxObjects(); i++) { SFXObject *so = pMission_->sfxObjects(i); - if (so->map() != -1 && so->tileX() >= tilex && so->tileX() < maxtilex - && so->tileY() >= tiley && so->tileY() < maxtiley) { + if (so->map() != -1 && so->tileX() >= startPos.x && so->tileX() < endPos.x + && so->tileY() >= startPos.y && so->tileY() < endPos.y) { fast_sfx_objects_cache_.insert(fastKey(so)); cache_sfx_objects_.push_back(so); + nbobject++; } } } -void MapRenderer::drawAt(int tilex, int tiley, int tilez, int x, int y) { - int key = fastKey(tilex, tiley, tilez); +/*! + * Draw on screen all objects that have their position on the given tile. + * \param tilePos const TilePoint& Tile's position + * \param screenPos const Point2D& Screen position to draw the objects + * \return int + * + */ +int MapRenderer::drawObjectsOnTile(const TilePoint & tilePos, const Point2D &screenPos) { + int key = fastKey(tilePos); + int nbobject = 0; if (fast_vehicle_cache_.find(key) != fast_vehicle_cache_.end()) { // draw vehicles for (unsigned int i = 0; i < cache_vehicles_.size(); i++) - if (cache_vehicles_[i]->tileX() == tilex - && cache_vehicles_[i]->tileY() == tiley + if (cache_vehicles_[i]->tileX() == tilePos.tx + && cache_vehicles_[i]->tileY() == tilePos.ty // NOTE: a trick to make vehicles be drawn correctly z+1 - && (cache_vehicles_[i]->tileZ() + 1) == tilez) - cache_vehicles_[i]->draw(x, y); + && (cache_vehicles_[i]->tileZ() + 1) == tilePos.tz) + cache_vehicles_[i]->draw(screenPos.x, screenPos.y); + nbobject++; } if (fast_ped_cache_.find(key) != fast_ped_cache_.end()) { // draw peds for (unsigned int i = 0; i < cache_peds_.size(); i++) - if (cache_peds_[i]->tileX() == tilex - && cache_peds_[i]->tileY() == tiley - && cache_peds_[i]->tileZ() == tilez) { - cache_peds_[i]->draw(x, y); + if (cache_peds_[i]->sameTile(tilePos)) { + cache_peds_[i]->draw(screenPos.x, screenPos.y); + + nbobject++; + #if 0 g_Screen.drawLine(x - TILE_WIDTH / 2, y, x + TILE_WIDTH / 2, y, 11); @@ -288,30 +302,29 @@ // draw weapons for (unsigned int i = 0; i < cache_weapons_.size(); i++) if (cache_weapons_[i]->map() != -1 - && cache_weapons_[i]->tileX() == tilex - && cache_weapons_[i]->tileY() == tiley - && cache_weapons_[i]->tileZ() == tilez) { - cache_weapons_[i]->draw(x, y); + && cache_weapons_[i]->sameTile(tilePos)) { + cache_weapons_[i]->draw(screenPos.x, screenPos.y); + nbobject++; } } if (fast_statics_cache_.find(key) != fast_statics_cache_.end()) { // draw statics for (unsigned int i = 0; i < cache_statics_.size(); i++) - if (cache_statics_[i]->tileX() == tilex - && cache_statics_[i]->tileY() == tiley - && cache_statics_[i]->tileZ() == tilez) { - cache_statics_[i]->draw(x, y); + if (cache_statics_[i]->sameTile(tilePos)) { + cache_statics_[i]->draw(screenPos.x, screenPos.y); + nbobject++; } } if (fast_sfx_objects_cache_.find(key) != fast_sfx_objects_cache_.end()) { // draw sfx objects for (unsigned int i = 0; i < cache_sfx_objects_.size(); i++) - if (cache_sfx_objects_[i]->tileX() == tilex - && cache_sfx_objects_[i]->tileY() == tiley - && cache_sfx_objects_[i]->tileZ() == tilez) { - cache_sfx_objects_[i]->draw(x, y); + if (cache_sfx_objects_[i]->sameTile(tilePos)) { + cache_sfx_objects_[i]->draw(screenPos.x, screenPos.y); + nbobject++; } } + + return nbobject; } Modified: freesynd/trunk/src/menus/maprenderer.h =================================================================== --- freesynd/trunk/src/menus/maprenderer.h 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/menus/maprenderer.h 2016-07-18 18:06:29 UTC (rev 1008) @@ -31,6 +31,9 @@ #include <vector> #include <set> +#include "common.h" +#include "model/position.h" + class Mission; class Map; class MapObject; @@ -43,22 +46,24 @@ class MapRenderer { public: - void init(Mission *pMission); + void init(Mission *pMission, SquadSelection *pSelection); - void render(int worldX, int worldY, SquadSelection *pSelection); + void render(const Point2D &worldPos); private: - static int fastKey(int tx, int ty, int tz) { - return tx | (ty << 8) | (tz << 16); + static int fastKey(const TilePoint & tilePos) { + return tilePos.tx | (tilePos.ty << 8) | (tilePos.tz << 16); } static int fastKey(MapObject * m); - void createFastKeys(int tilex, int tiley, int maxtilex, int maxtiley); - void drawAt(int tilex, int tiley, int tilez, int x, int y); + void createFastKeys(const Point2D &startPos, const Point2D &endPos); + int drawObjectsOnTile(const TilePoint & tilePos, const Point2D &screenPos); + private: Mission *pMission_; Map *pMap_; + SquadSelection *pSelection_; std::vector<Vehicle *> cache_vehicles_; std::vector<PedInstance *> cache_peds_; Modified: freesynd/trunk/src/model/position.h =================================================================== --- freesynd/trunk/src/model/position.h 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/model/position.h 2016-07-18 18:06:29 UTC (rev 1008) @@ -158,15 +158,4 @@ } }; -/*! - * This a convenient structure to store a position - * in screen coordinates (in pixels). - */ -struct ScreenPoint { - /*! the X coord on the screen.*/ - int x; - /*! the Y coord on the screen.*/ - int y; -}; - #endif // MODEL_POSITION_H_ Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2016-07-05 17:21:32 UTC (rev 1007) +++ freesynd/trunk/src/ped.cpp 2016-07-18 18:06:29 UTC (rev 1008) @@ -613,7 +613,7 @@ && y < scrollY + GAME_SCREEN_HEIGHT; } -bool getOnScreen(int scrollX, int scrollY, ScreenPoint &scPt, const ScreenPoint &tScPt) { +bool getOnScreen(int scrollX, int scrollY, Point2D &scPt, const Point2D &tScPt) { bool off = false; // get x, y on screen @@ -631,14 +631,14 @@ } void PedInstance::showPath(int scrollX, int scrollY) { - ScreenPoint pedScPt; + Point2D pedScPt; g_App.maps().map(map())->tileToScreenPoint(pos_, &pedScPt); pedScPt.y = pedScPt.y - pos_.tz * TILE_HEIGHT/3 + TILE_HEIGHT/3; for (std::list<TilePoint>::iterator it = dest_path_.begin(); it != dest_path_.end(); ++it) { TilePoint & d = *it; - ScreenPoint pathSp; + Point2D pathSp; g_App.maps().map(map())->tileToScreenPoint(d, &pathSp); pathSp.y = pathSp.y - d.tz * TILE_HEIGHT/3 + TILE_HEIGHT/3; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-07-05 17:21:35
|
Revision: 1007 http://sourceforge.net/p/freesynd/code/1007 Author: benblan Date: 2016-07-05 17:21:32 +0000 (Tue, 05 Jul 2016) Log Message: ----------- - Update search mission in editor - Update animation menu in editor Modified Paths: -------------- freesynd/trunk/src/CMakeLists.txt freesynd/trunk/src/editor/animmenu.cpp freesynd/trunk/src/editor/animmenu.h freesynd/trunk/src/editor/listmissionmenu.cpp freesynd/trunk/src/editor/searchmissionmenu.cpp freesynd/trunk/src/editor/searchmissionmenu.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/gameplaymenu.h freesynd/trunk/src/missionmanager.cpp freesynd/trunk/src/model/vehicle.h Modified: freesynd/trunk/src/CMakeLists.txt =================================================================== --- freesynd/trunk/src/CMakeLists.txt 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/CMakeLists.txt 2016-07-05 17:21:32 UTC (rev 1007) @@ -256,6 +256,7 @@ modmanager.cpp missionmanager.cpp model/vehicle.cpp + model/train.cpp weapon.cpp weaponmanager.cpp core/gamecontroller.cpp Modified: freesynd/trunk/src/editor/animmenu.cpp =================================================================== --- freesynd/trunk/src/editor/animmenu.cpp 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/editor/animmenu.cpp 2016-07-05 17:21:32 UTC (rev 1007) @@ -31,11 +31,23 @@ #include "editor/editorapp.h" AnimMenu::AnimMenu(MenuManager * m): - Menu(m, fs_edit_menus::kMenuIdFont, fs_edit_menus::kMenuIdMain, "", "") + Menu(m, fs_edit_menus::kMenuIdFont, fs_edit_menus::kMenuIdMain, "mscrenup.dat", "") { isCachable_ = false; - animId_ = 1960; + animId_ = 416; frameId_ = 0; + + addStatic(0, 40, g_Screen.gameScreenWidth(), "ANIMATIONS", FontManager::SIZE_4, false); + // Accept button + addOption(17, 347, 128, 25, "BACK", FontManager::SIZE_2, fs_edit_menus::kMenuIdMain); + + // Animation id + addStatic(180, 300, "ANIMATION:", FontManager::SIZE_2, true); + txtAnimId_ = addStatic(300, 300, "416", FontManager::SIZE_2, true); + + // frame id + addStatic(180, 350, "FRAME:", FontManager::SIZE_2, true); + txtFrameId_ = addStatic(300, 350, "0", FontManager::SIZE_2, true); } void AnimMenu::handleShow() @@ -46,12 +58,15 @@ g_System.showCursor(); menu_manager_->setDefaultPalette(); + + menu_manager_->saveBackground(); } void AnimMenu::handleRender(DirtyList &dirtyList) { - g_Screen.clear(0); - g_App.gameSprites().drawFrame(animId_, frameId_, 100, 100); + g_Screen.drawRect(150, 110, 350, 150); + //GameSpriteFrame sprite = g_App.gameSprites(). + g_App.gameSprites().drawFrame(animId_, frameId_, 310, 180); } void AnimMenu::handleLeave() { @@ -92,7 +107,14 @@ } if (change) { - printf("Animation #%d, frame #%d\n", animId_, frameId_); + //printf("Animation #%d, frame #%d\n", animId_, frameId_); + char tmp[100]; + sprintf(tmp, "%d", animId_); + getStatic(txtAnimId_)->setText(tmp); + + sprintf(tmp, "%d", frameId_); + getStatic(txtFrameId_)->setText(tmp); + needRendering(); } Modified: freesynd/trunk/src/editor/animmenu.h =================================================================== --- freesynd/trunk/src/editor/animmenu.h 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/editor/animmenu.h 2016-07-05 17:21:32 UTC (rev 1007) @@ -46,6 +46,9 @@ protected: int animId_; int frameId_; + + int txtAnimId_; + int txtFrameId_; }; #endif // EDITOR_ANIMMENU_H_ Modified: freesynd/trunk/src/editor/listmissionmenu.cpp =================================================================== --- freesynd/trunk/src/editor/listmissionmenu.cpp 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/editor/listmissionmenu.cpp 2016-07-05 17:21:32 UTC (rev 1007) @@ -47,8 +47,13 @@ int missionId = *it; char label[50]; - sprintf(label, "MISSION %d", missionId); + if (missionId < 10) { + sprintf(label, "#CNTRY_0%d", missionId); + } else { + sprintf(label, "#CNTRY_%d", missionId); + } + if (nbRes % 10 == 0) { y = topY; x += (nbRes == 0 ? 0 : 130); Modified: freesynd/trunk/src/editor/searchmissionmenu.cpp =================================================================== --- freesynd/trunk/src/editor/searchmissionmenu.cpp 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/editor/searchmissionmenu.cpp 2016-07-05 17:21:32 UTC (rev 1007) @@ -32,15 +32,42 @@ #include "system.h" #include "missionmanager.h" #include "mission.h" -#include "ped.h" +#include "model/vehicle.h" +std::string PedTypeAdapter::getName() { + switch (type_) { + case PedInstance::kPedTypeAgent: + return "AGENT"; + case PedInstance::kPedTypeCivilian: + return "CIVILIAN"; + case PedInstance::kPedTypeCriminal: + return "CRIMINAL"; + case PedInstance::kPedTypeGuard: + return "GUARD"; + case PedInstance::kPedTypePolice: + return "POLICE"; + default: + return "UNKOWN"; + } +} + +std::string VehicleTypeAdapter::getName() { + if (type_ == Vehicle::kVehicleTypeTrainHead) { + return "TRAIN"; + } + + return "UNKOWN"; +} + SearchMissionMenu::SearchMissionMenu(MenuManager * m): Menu(m, fs_edit_menus::kMenuIdSrchMis, fs_edit_menus::kMenuIdMain, "mscrenup.dat", "") { isCachable_ = false; addStatic(0, 40, g_Screen.gameScreenWidth(), "SEARCH MISSION", FontManager::SIZE_4, false); + initPedTypeListAndWidget(); + initVehicleTypeListAndWidget(); // Accept button addOption(17, 347, 128, 25, "BACK", FontManager::SIZE_2, fs_edit_menus::kMenuIdMain); @@ -48,18 +75,82 @@ searchButId_ = addOption(500, 347, 128, 25, "SEARCH", FontManager::SIZE_2); } +SearchMissionMenu::~SearchMissionMenu() { + for (unsigned int i=0; i<pedTypeList_.size(); i++) { + PedTypeAdapter *pType = pedTypeList_.get(i); + delete pType; + } +} + +void SearchMissionMenu::initPedTypeListAndWidget() { + pedTypeList_.add(new PedTypeAdapter(PedInstance::kPedTypeAgent)); + pedTypeList_.add(new PedTypeAdapter(PedInstance::kPedTypeCivilian)); + pedTypeList_.add(new PedTypeAdapter(PedInstance::kPedTypeCriminal)); + pedTypeList_.add(new PedTypeAdapter(PedInstance::kPedTypeGuard)); + pedTypeList_.add(new PedTypeAdapter(PedInstance::kPedTypePolice)); + + pPedTypeListBox_ = addListBox(20, 84, 70, 120, true); + pPedTypeListBox_->setModel(&pedTypeList_); +} + +void SearchMissionMenu::initVehicleTypeListAndWidget() { + vehicleTypeList_.add(new VehicleTypeAdapter(Vehicle::kVehicleTypeTrainHead)); + + pVehicleTypeListBox_ = addListBox(110, 84, 70, 120, true); + pVehicleTypeListBox_->setModel(&vehicleTypeList_); +} + +void SearchMissionMenu::initSearchCriterias() { + searchOnPedType_ = false; + pedTypeCriteria_ = PedInstance::kPedTypeAgent; + searchOnVehicleType_ = false; + vehicleTypeCriteria_ = 0; +} + void SearchMissionMenu::handleShow() { // If we came from the intro, the cursor is invisible // otherwise, it does no harm g_System.useMenuCursor(); g_System.showCursor(); + + initSearchCriterias(); } void SearchMissionMenu::handleLeave() { g_System.hideCursor(); } +bool SearchMissionMenu::matchMissionWithPedType(Mission *pMission) { + if (searchOnPedType_) { + for (size_t pedId = 0; pedId < pMission->numPeds(); pedId++) { + PedInstance *pPed = pMission->ped(pedId); + + if (pPed->type() == pedTypeCriteria_) { + return true; + } + } + return false; + } + + return true; +} + +bool SearchMissionMenu::matchMissionWithVehicleType(Mission *pMission) { + if (searchOnVehicleType_) { + for (size_t vId = 0; vId < pMission->numVehicles(); vId++) { + Vehicle *pVehicle = pMission->vehicle(vId); + + if (pVehicle->getType() == vehicleTypeCriteria_) { + return true; + } + } + return false; + } + + return true; +} + void SearchMissionMenu::handleAction(const int actionId, void *ctx, const int modKeys) { if (actionId == searchButId_) { MissionManager missionMgr; @@ -71,18 +162,32 @@ Mission *pMission = missionMgr.loadMission(misId); if (pMission) { - for (size_t pedId = 0; pedId < pMission->numPeds(); pedId++) { - PedInstance *pPed = pMission->ped(pedId); + bool keepMission = matchMissionWithPedType(pMission); - if (pPed->type() == PedInstance::kPedTypeCriminal) { - g_App.getMissionResultList().push_back(misId); - break; - } + if (keepMission) { + keepMission = matchMissionWithVehicleType(pMission); } + + if (keepMission) { + g_App.getMissionResultList().push_back(misId); + } + delete pMission; } } menu_manager_->gotoMenu(fs_edit_menus::kMenuIdListMis); + } else if (actionId == pPedTypeListBox_->getId()) { + std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); + PedTypeAdapter *pType = static_cast<PedTypeAdapter *> (pPair->second); + + searchOnPedType_ = true; + pedTypeCriteria_ = pType->getType(); + } else if (actionId == pVehicleTypeListBox_->getId()) { + std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); + VehicleTypeAdapter *pType = static_cast<VehicleTypeAdapter *> (pPair->second); + + searchOnVehicleType_ = true; + vehicleTypeCriteria_ = pType->getType(); } } Modified: freesynd/trunk/src/editor/searchmissionmenu.h =================================================================== --- freesynd/trunk/src/editor/searchmissionmenu.h 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/editor/searchmissionmenu.h 2016-07-05 17:21:32 UTC (rev 1007) @@ -26,19 +26,70 @@ * * ************************************************************************/ +#include "utils/seqmodel.h" +#include "ped.h" + +class Mission; + +class PedTypeAdapter { +public: + PedTypeAdapter(PedInstance::PedType type) { + type_ = type; + } + + PedInstance::PedType getType() { return type_; } + std::string getName(); + +private: + PedInstance::PedType type_; +}; + +class VehicleTypeAdapter { +public: + VehicleTypeAdapter(uint8 type) { + type_ = type; + } + + uint8 getType() { return type_; } + std::string getName(); + +private: + uint8 type_; +}; + /*! * Search mission menu. */ class SearchMissionMenu : public Menu { public: SearchMissionMenu(MenuManager *m); + ~SearchMissionMenu(); void handleShow(); void handleLeave(); void handleAction(const int actionId, void *ctx, const int modKeys); protected: + void initPedTypeListAndWidget(); + void initSearchCriterias(); + void initVehicleTypeListAndWidget(); + + bool matchMissionWithPedType(Mission *pMission); + bool matchMissionWithVehicleType(Mission *pMission); + +protected: int searchButId_; + ListBox *pPedTypeListBox_; + ListBox *pVehicleTypeListBox_; + + VectorModel<PedTypeAdapter *> pedTypeList_; + VectorModel<VehicleTypeAdapter *> vehicleTypeList_; + + bool searchOnPedType_; + PedInstance::PedType pedTypeCriteria_; + + bool searchOnVehicleType_; + uint8 vehicleTypeCriteria_; }; #endif // SEARCHMISSIONMENU_H_ Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2016-07-05 17:21:32 UTC (rev 1007) @@ -53,11 +53,12 @@ Menu(m, fs_game_menus::kMenuIdGameplay, fs_game_menus::kMenuIdDebrief, "", "mscrenup.dat"), tick_count_(0), last_animate_tick_(0), last_motion_tick_(0), last_motion_x_(320), last_motion_y_(240), mission_hint_ticks_(0), -mission_hint_(0), mission_(NULL), world_x_(0), -world_y_(0), selection_(), +mission_hint_(0), mission_(NULL), selection_(), target_(NULL), mm_renderer_(), warningTimer_(20000) { + displayOriginPt_.x = 0; + displayOriginPt_.y = 0; scroll_x_ = 0; scroll_y_ = 0; ipa_chng_.ipa_chng = -1; @@ -75,44 +76,44 @@ bool GameplayMenu::scrollOnX() { bool change = false; - int newWorldX = world_x_ + scroll_x_; + int newOriginX = displayOriginPt_.x + scroll_x_; - TilePoint mpt = mission_->get_map()->screenToTilePoint(newWorldX, world_y_); + TilePoint mpt = mission_->get_map()->screenToTilePoint(newOriginX, displayOriginPt_.y); // Scroll to the right if (scroll_x_ > 0) { if (mpt.ty < mission_->minY()) { // we hit the upper right border of the map // so we scroll down until the far right corner - int newWorldY = world_y_ + SCROLL_STEP; - newWorldX += SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newWorldY = displayOriginPt_.y + SCROLL_STEP; + newOriginX += SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.ty < mission_->minY() || mpt.tx > mission_->maxX()) { // We hit the corner so don't scroll return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else if (mpt.tx > mission_->maxX()) { // we hit the lower right border of the map // so we scroll up until the far right corner - int newWorldY = world_y_ - SCROLL_STEP; - newWorldX += SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newWorldY = displayOriginPt_.y - SCROLL_STEP; + newOriginX += SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.ty < mission_->minY() || mpt.tx > mission_->maxX()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else { // This is a regular right scroll - world_x_ = newWorldX; + displayOriginPt_.x = newOriginX; change = true; } @@ -120,33 +121,33 @@ if (mpt.tx < mission_->minX()) { // we hit the upper left border of the map // so we scroll down until the far left corner - int newWorldY = world_y_ + SCROLL_STEP; - newWorldX -= SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newWorldY = displayOriginPt_.y + SCROLL_STEP; + newOriginX -= SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.tx < mission_->minX() || mpt.ty > mission_->maxY()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else if (mpt.ty > mission_->maxY()) { // we hit the lower left border of the map // so we scroll up until the far left corner - int newWorldY = world_y_ - SCROLL_STEP; - newWorldX -= SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newWorldY = displayOriginPt_.y - SCROLL_STEP; + newOriginX -= SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.tx < mission_->minX() || mpt.ty > mission_->maxY()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else { - world_x_ = newWorldX; + displayOriginPt_.x = newOriginX; change = true; } } @@ -164,40 +165,40 @@ bool GameplayMenu::scrollOnY() { bool change = false; - int newWorldY = world_y_ + scroll_y_; + int newWorldY = displayOriginPt_.y + scroll_y_; - TilePoint mpt = mission_->get_map()->screenToTilePoint(world_x_, newWorldY); + TilePoint mpt = mission_->get_map()->screenToTilePoint(displayOriginPt_.x, newWorldY); // Scroll down if (scroll_y_ > 0) { if (mpt.tx > mission_->maxX()) { // we hit the lower right border of the map // so we scroll down until the lower corner - int newWorldX = world_x_ - 2*SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newOriginX = displayOriginPt_.x - 2*SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.ty > mission_->maxY() || mpt.tx > mission_->maxX()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else if (mpt.ty > mission_->maxY()) { // we hit the lower left border of the map // so we scroll down until the lower corner - int newWorldX = world_x_ + 2*SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newOriginX = displayOriginPt_.x + 2*SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.ty > mission_->maxY() || mpt.tx > mission_->maxX()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else { - world_y_ = newWorldY; + displayOriginPt_.y = newWorldY; change = true; } @@ -205,31 +206,31 @@ if (mpt.tx < mission_->minX()) { // we hit the upper right border of the map // so we scroll up until the upper corner - int newWorldX = world_x_ + 2*SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newOriginX = displayOriginPt_.x + 2*SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.ty < mission_->minY() || mpt.tx < mission_->minX()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else if (mpt.ty < mission_->minY()) { // we hit the upper left border of the map // so we scroll up until the upper corner - int newWorldX = world_x_ - 2*SCROLL_STEP; - mpt = mission_->get_map()->screenToTilePoint(newWorldX, newWorldY); + int newOriginX = displayOriginPt_.x - 2*SCROLL_STEP; + mpt = mission_->get_map()->screenToTilePoint(newOriginX, newWorldY); if (mpt.ty < mission_->minY() || mpt.tx < mission_->minX()) { return false; } else { - world_x_ = newWorldX; - world_y_ = newWorldY; + displayOriginPt_.x = newOriginX; + displayOriginPt_.y = newWorldY; change = true; } } else { - world_y_ = newWorldY; + displayOriginPt_.y = newWorldY; change = true; } } @@ -275,8 +276,8 @@ ScreenPoint msp; mission_->get_map()->tileToScreenPoint(mpt.tx, mpt.ty, mission_->mmax_z_ + 1, 0, 0, &msp); - world_x_ = msp.x; - world_y_ = msp.y; + displayOriginPt_.x = msp.x; + displayOriginPt_.y = msp.y; } /*! @@ -399,7 +400,7 @@ void GameplayMenu::handleRender(DirtyList &dirtyList) { g_Screen.clear(0); - map_renderer_.render(world_x_, world_y_, &selection_); + map_renderer_.render(displayOriginPt_.x, displayOriginPt_.y, &selection_); g_Screen.drawRect(0,0, 129, GAME_SCREEN_HEIGHT); agt_sel_renderer_.render(selection_, mission_->getSquad()); drawSelectAllButton(); @@ -481,8 +482,8 @@ last_motion_y_ = 240; mission_hint_ticks_ = 0; mission_hint_ = 0; - world_x_ = 0; - world_y_ = 0; + displayOriginPt_.x = 0; + displayOriginPt_.y = 0; target_ = NULL; mission_ = NULL; scroll_x_ = 0; @@ -550,8 +551,8 @@ int py = scPt.y - (1 + p->tileZ()) * TILE_HEIGHT/3 - (p->offZ() * TILE_HEIGHT/3) / 128; - if (x - 129 + world_x_ >= px && y + world_y_ >= py && - x - 129 + world_x_ < px + 21 && y + world_y_ < py + 34) + if (x - 129 + displayOriginPt_.x >= px && y + displayOriginPt_.y >= py && + x - 129 + displayOriginPt_.x < px + 21 && y + displayOriginPt_.y < py + 34) { // mouse pointer is on the object, so it's the new target target_ = p; @@ -569,8 +570,8 @@ int px = scPt.x - 20; int py = scPt.y - 10 - v->tileZ() * TILE_HEIGHT/3; - if (x - 129 + world_x_ >= px && y + world_y_ >= py && - x - 129 + world_x_ < px + 40 && y + world_y_ < py + 32) + if (x - 129 + displayOriginPt_.x >= px && y + displayOriginPt_.y >= py && + x - 129 + displayOriginPt_.x < px + 40 && y + displayOriginPt_.y < py + 32) { target_ = v; inrange = selection_.isTargetInRange(mission_, target_); @@ -589,8 +590,8 @@ int py = scPt.y + 4 - w->tileZ() * TILE_HEIGHT/3 - (w->offZ() * TILE_HEIGHT/3) / 128; - if (x - 129 + world_x_ >= px && y + world_y_ >= py && - x - 129 + world_x_ < px + 20 && y + world_y_ < py + 15) + if (x - 129 + displayOriginPt_.x >= px && y + displayOriginPt_.y >= py && + x - 129 + displayOriginPt_.x < px + 20 && y + displayOriginPt_.y < py + 15) { target_ = w; break; @@ -609,8 +610,8 @@ int py = scPt.y + 4 - s->tileZ() * TILE_HEIGHT/3 - (s->offZ() * TILE_HEIGHT/3) / 128; - if (x - 129 + world_x_ >= px && y + world_y_ >= py && - x - 129 + world_x_ < px + 20 && y + world_y_ < py + 15) + if (x - 129 + displayOriginPt_.x >= px && y + displayOriginPt_.y >= py && + x - 129 + displayOriginPt_.x < px + 20 && y + displayOriginPt_.y < py + 15) { target_ = s; break; @@ -765,8 +766,8 @@ } void GameplayMenu::handleClickOnMap(int x, int y, int button, const int modKeys) { - TilePoint mapPt = mission_->get_map()->screenToTilePoint(world_x_ + x - 129, - world_y_ + y); + TilePoint mapPt = mission_->get_map()->screenToTilePoint(displayOriginPt_.x + x - 129, + displayOriginPt_.y + y); #ifdef _DEBUG if ((modKeys & KMD_ALT) != 0) { printf("Tile x:%d, y:%d, z:%d, ox:%d, oy:%d\n", @@ -850,8 +851,8 @@ locationSet = true; } else { // Player is shooting on the ground - TilePoint mapLocT = mission_->get_map()->screenToTilePoint(world_x_ + x - 129, - world_y_ + y); + TilePoint mapLocT = mission_->get_map()->screenToTilePoint(displayOriginPt_.x + x - 129, + displayOriginPt_.y + y); mapLocT.tz = 0; if (mission_->getShootableTile(&mapLocT)) { locationSet = true; Modified: freesynd/trunk/src/menus/gameplaymenu.h =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.h 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/menus/gameplaymenu.h 2016-07-05 17:21:32 UTC (rev 1007) @@ -108,10 +108,10 @@ int last_motion_tick_, last_motion_x_, last_motion_y_; int mission_hint_ticks_, mission_hint_; Mission *mission_; - /*! Holds the X coordinate of the screen origin (top left corner) in the world coordinate.*/ - int world_x_; - /*! Holds the Y coordinate of the screen origin (top left corner) in the world coordinate.*/ - int world_y_; + + /*! This is a projection in 2D of a point on a the map. This point represents the top + * left corner of the screen and it moves inside the map's borders.*/ + ScreenPoint displayOriginPt_; /*! Holds the amount of scroll on the X axis.*/ int scroll_x_; /*! Holds the amount of scroll on the Y axis.*/ Modified: freesynd/trunk/src/missionmanager.cpp =================================================================== --- freesynd/trunk/src/missionmanager.cpp 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/missionmanager.cpp 2016-07-05 17:21:32 UTC (rev 1007) @@ -584,6 +584,7 @@ gamdata.mapposy[0], oz); pVehicle->setDirection(gamdata.orientation); + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - position %d, %d, %d, %d, %d, %d\n", gamdata.mapposx[1], gamdata.mapposy[1], z, gamdata.mapposx[0],gamdata.mapposy[0], oz)) LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 1 %u", gamdata.unkn1)) LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 2 %u", gamdata.unkn2)) LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 3 %u", gamdata.unkn3)) Modified: freesynd/trunk/src/model/vehicle.h =================================================================== --- freesynd/trunk/src/model/vehicle.h 2016-06-04 06:16:14 UTC (rev 1006) +++ freesynd/trunk/src/model/vehicle.h 2016-07-05 17:21:32 UTC (rev 1007) @@ -102,6 +102,8 @@ bool animate(int elapsed); void draw(int x, int y); + //! Return type of vehicle + uint8 getType() { return type_; } //! Return true if vehicle is a car bool isCar() { return type_ != kVehicleTypeTrainHead && type_ != kVehicleTypeTrainBody; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-06-04 06:16:17
|
Revision: 1006 http://sourceforge.net/p/freesynd/code/1006 Author: benblan Date: 2016-06-04 06:16:14 +0000 (Sat, 04 Jun 2016) Log Message: ----------- Train implementation - fixed compilation warnings - renamed Vehicleinstance to GenericCar - instanciation of TrainBody and TrainElement instead of Vehicleinstance Modified Paths: -------------- freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/ia/actions.h freesynd/trunk/src/mapobject.cpp freesynd/trunk/src/menus/squadselection.cpp freesynd/trunk/src/missionmanager.cpp freesynd/trunk/src/model/objectivedesc.cpp freesynd/trunk/src/model/train.cpp freesynd/trunk/src/model/train.h freesynd/trunk/src/model/vehicle.cpp freesynd/trunk/src/model/vehicle.h freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/pedactions.cpp Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/ia/actions.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -594,7 +594,7 @@ return true; } -DriveVehicleAction::DriveVehicleAction(VehicleInstance *pVehicle, const TilePoint &dest) : +DriveVehicleAction::DriveVehicleAction(GenericCar *pVehicle, const TilePoint &dest) : MovementAction(kActTypeUndefined, false, true) { pVehicle_ = pVehicle; dest_ = dest; Modified: freesynd/trunk/src/ia/actions.h =================================================================== --- freesynd/trunk/src/ia/actions.h 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/ia/actions.h 2016-06-04 06:16:14 UTC (rev 1006) @@ -32,7 +32,7 @@ class PedInstance; class WeaponInstance; class Vehicle; -class VehicleInstance; +class GenericCar; /*! @@ -456,14 +456,14 @@ */ class DriveVehicleAction : public MovementAction { public: - DriveVehicleAction(VehicleInstance *pVehicle, const TilePoint &dest); + DriveVehicleAction(GenericCar *pVehicle, const TilePoint &dest); protected: void doStart(Mission *pMission, PedInstance *pPed); bool doExecute(int elapsed, Mission *pMission, PedInstance *pPed); protected: /*! Vehicle to drive.*/ - VehicleInstance *pVehicle_; + GenericCar *pVehicle_; /*! Destination point.*/ TilePoint dest_; }; Modified: freesynd/trunk/src/mapobject.cpp =================================================================== --- freesynd/trunk/src/mapobject.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/mapobject.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -135,48 +135,48 @@ */ void MapObject::setDirection(int posx, int posy, int * dir) { - int direction = -1; + int newDirection = -1; if (posx == 0) { if (posy < 0) { - direction = 128; + newDirection = 128; } else if (posy > 0) { - direction = 0; + newDirection = 0; } } else if (posy == 0) { if (posx > 0) { - direction = 64; + newDirection = 64; } else if (posx < 0) { - direction = 192; + newDirection = 192; } } else if (posx < 0) { if (posy > 0) { posx = -posx; - direction = (int)((128.0 + newDirection = (int)((128.0 * atan((double)posy / (double)posx)) / PI + 192.0); } else { // posy < 0 int swapx = -posx; posx = -posy; posy = swapx; - direction = (int)((128.0 + newDirection = (int)((128.0 * atan((double)posy / (double)posx)) / PI + 128.0); } } else if (posx > 0 && posy < 0) { posy = -posy; - direction = (int)((128.0 + newDirection = (int)((128.0 * atan((double)posy / (double)posx)) / PI + 64.0); } else { // posx > 0 && posy > 0 int swapx = posx; posx = posy; posy = swapx; - direction = (int)((128.0 + newDirection = (int)((128.0 * atan((double)posy / (double)posx)) / PI); } - if (direction != -1) { + if (newDirection != -1) { if (dir == NULL) - dir_ = direction; + dir_ = newDirection; else - *dir = direction; + *dir = newDirection; } } @@ -198,21 +198,21 @@ int MapObject::getDirection(int snum) { assert(snum > 0); - int direction = 0; + int newDirection = 0; int sinc = 256 / snum; int sdec = sinc / 2; do { - int s = direction * sinc; - if (direction == 0) { + int s = newDirection * sinc; + if (newDirection == 0) { if ((256 - sdec) <= dir_ || (s + sdec) > dir_) break; } else if ((s - sdec) <= dir_ && (s + sdec) > dir_) break; - direction++; - } while (direction < snum); - assert(direction < snum); + newDirection++; + } while (newDirection < snum); + assert(newDirection < snum); - return direction; + return newDirection; } /* @@ -953,7 +953,7 @@ int x = tileX(); int y = tileY(); int z = tileZ(); - MapObject::ObjectNature nature; + MapObject::ObjectNature aNature; int si; char inc_rel = 0, rel_inc = 0; char *i = 0, *j = 0; @@ -971,10 +971,10 @@ } assert(i != 0 && j != 0); for(*i = 0; *i < 2; *i += 1) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc, z, &nature, &si, true)); + y + rel_inc, z, &aNature, &si, true)); if (!p && state_ == Static::sttdoor_Open && (!found)) { state_ = Static::sttdoor_Closing; setExcludedFromBlockers(false); @@ -998,10 +998,10 @@ } assert(i != 0 && j != 0); *i = 1; - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc, z, &nature, &si, true)); + y + rel_inc, z, &aNature, &si, true)); if (p && p->isAlive()) { if (!found) { state_ = Static::sttdoor_Opening; @@ -1019,10 +1019,10 @@ } } while (p); *i = 0; - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc, z, &nature, &si, true)); + y + rel_inc, z, &aNature, &si, true)); if (p && p->isAlive()) { if (!found) { state_ = Static::sttdoor_Opening; @@ -1091,12 +1091,12 @@ bool LargeDoor::animate(int elapsed, Mission *obj) { // TODO: there must be somewhere locked door - VehicleInstance *v = NULL; + GenericCar *v = NULL; PedInstance *p = NULL; int x = tileX(); int y = tileY(); int z = tileZ(); - MapObject::ObjectNature nature; + MapObject::ObjectNature aNature; int si; char inc_rel = 0, rel_inc = 0; char *i = 0, *j = 0; @@ -1122,9 +1122,9 @@ assert(i != 0 && j != 0); *j = -1; for(*i = -2; *i < 3; (*i)++) { - nature = MapObject::kNatureVehicle; si = 0; - v = (VehicleInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc,z, &nature, &si, true)); + aNature = MapObject::kNatureVehicle; si = 0; + v = (GenericCar *)(obj->findObjectWithNatureAtPos(x + inc_rel, + y + rel_inc,z, &aNature, &si, true)); if (!v && !found) { state_ = Static::sttdoor_Closing; setExcludedFromBlockers(false); @@ -1137,9 +1137,9 @@ } *j = 1; for(*i = -2; *i < 3; (*i)++) { - nature = MapObject::kNatureVehicle; si = 0; - v = (VehicleInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc,z,&nature,&si,true)); + aNature = MapObject::kNatureVehicle; si = 0; + v = (GenericCar *)(obj->findObjectWithNatureAtPos(x + inc_rel, + y + rel_inc,z,&aNature,&si,true)); if (!v && !found) { state_ = Static::sttdoor_Closing; setExcludedFromBlockers(false); @@ -1152,10 +1152,10 @@ } *j = -1; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds.push_back(p); if (!found && p->hasAccessCard()) { @@ -1168,10 +1168,10 @@ } *j = 1; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds.push_back(p); if (!found && p->hasAccessCard()) { @@ -1184,10 +1184,10 @@ } *j = 0; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds_mid.push_back(p); if (!found && p->hasAccessCard()) { @@ -1253,9 +1253,9 @@ assert(i != 0 && j != 0); *j = -1 * sign; *i = -2; - nature = MapObject::kNatureVehicle; si = 0; - v = (VehicleInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc,z, &nature, &si,true)); + aNature = MapObject::kNatureVehicle; si = 0; + v = (GenericCar *)(obj->findObjectWithNatureAtPos(x + inc_rel, + y + rel_inc,z, &aNature, &si,true)); if (v) { if (!found) { state_ = Static::sttdoor_Opening; @@ -1267,9 +1267,9 @@ } *j = 1 * sign; *i = 2; - nature = MapObject::kNatureVehicle; si = 0; - v = (VehicleInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc,z, &nature, &si,true)); + aNature = MapObject::kNatureVehicle; si = 0; + v = (GenericCar *)(obj->findObjectWithNatureAtPos(x + inc_rel, + y + rel_inc,z, &aNature, &si,true)); if (v) { if (!found) { state_ = Static::sttdoor_Opening; @@ -1281,10 +1281,10 @@ } *j = -1; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds.push_back(p); if (!found && p->hasAccessCard()) { @@ -1297,10 +1297,10 @@ } *j = 1; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds.push_back(p); if (!found && p->hasAccessCard()) { @@ -1355,28 +1355,28 @@ *j = -1 * sign; *i = -2; set_wayFree = state_ == Static::sttdoor_Opening ? 1 : 2; - nature = MapObject::kNatureVehicle; si = 0; - v = (VehicleInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc,z, &nature, &si,true)); + aNature = MapObject::kNatureVehicle; si = 0; + v = (GenericCar *)(obj->findObjectWithNatureAtPos(x + inc_rel, + y + rel_inc,z, &aNature, &si,true)); if (v) { v->hold_on_.wayFree = 1; v->hold_on_.pathBlocker = this; } *j = 1 * sign; *i = 2; - nature = MapObject::kNatureVehicle; si = 0; - v = (VehicleInstance *)(obj->findObjectWithNatureAtPos(x + inc_rel, - y + rel_inc,z, &nature, &si,true)); + aNature = MapObject::kNatureVehicle; si = 0; + v = (GenericCar *)(obj->findObjectWithNatureAtPos(x + inc_rel, + y + rel_inc,z, &aNature, &si,true)); if (v) { v->hold_on_.wayFree = 1; v->hold_on_.pathBlocker = this; } *j = -1; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds.push_back(p); } @@ -1384,10 +1384,10 @@ } *j = 1; for (*i = -1; *i <= 1; (*i)++ ) { - nature = MapObject::kNaturePed; si = 0; + aNature = MapObject::kNaturePed; si = 0; do { p = (PedInstance *)(obj->findObjectWithNatureAtPos(x + rel_inc, - y + inc_rel, z, &nature, &si, true)); + y + inc_rel, z, &aNature, &si, true)); if (p) { found_peds.push_back(p); } Modified: freesynd/trunk/src/menus/squadselection.cpp =================================================================== --- freesynd/trunk/src/menus/squadselection.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/menus/squadselection.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -262,7 +262,7 @@ if (pVehicle->speed() != 0 && pVehicle->isCar()) { pVehicle->clearDestination(); // tells the driver to stop - VehicleInstance *pVi = dynamic_cast<VehicleInstance *>(pVehicle); + GenericCar *pVi = dynamic_cast<GenericCar *>(pVehicle); pVi->getDriver()->destroyAllActions(); } // Ped can get off only if vehicle is stopped @@ -292,7 +292,7 @@ if (pVehicle) { if (pVehicle->isCar()) { // Agent is in drivable vehicle - VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(pVehicle); + GenericCar *pCar = dynamic_cast<GenericCar *>(pVehicle); if (pCar->isDriver(pAgent)) { int stx = mapPt.tx; Modified: freesynd/trunk/src/missionmanager.cpp =================================================================== --- freesynd/trunk/src/missionmanager.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/missionmanager.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -34,6 +34,7 @@ #include "core/missionbriefing.h" #include "model/objectivedesc.h" #include "model/vehicle.h" +#include "model/train.h" #include "mission.h" #include "core/squad.h" #include "pedmanager.h" @@ -510,93 +511,87 @@ /*! * */ -Vehicle * MissionManager::createVehicleInstance(const LevelData::Cars &gamdata, uint16 id, uint16 map) -{ - // TODO: check all maps - // TODO: train, join somehow +Vehicle * MissionManager::createVehicleInstance(const LevelData::Cars &gamdata, uint16 id, uint16 map) { int hp = READ_LE_INT16(gamdata.health); int dir = gamdata.orientation >> 5; + int cur_anim = READ_LE_UINT16(gamdata.index_current_anim) - dir; VehicleAnimation *vehicleanim = new VehicleAnimation(); - int cur_anim = READ_LE_UINT16(gamdata.index_current_anim) - dir; - //setVehicleBaseAnim(vehicleanim, cur_anim); vehicleanim->set_base_anims(cur_anim); - Vehicle *vehicle_new = new VehicleInstance(vehicleanim, id, gamdata.sub_type, map); - vehicle_new->setHealth(hp); - vehicle_new->setStartHealth(hp); - switch (gamdata.sub_type) { - case 0x01: - // large armored - break; - case 0x04: - // large armored damaged - // it is actually base animation and they have 8 directions - //setVehicleBaseAnim(vehicleanim, cur_anim - 12 + (dir >> 1)); - vehicleanim->set_base_anims(cur_anim - 12 + (dir >> 1)); - vehicle_new->setStartHealth(0); - vehicle_new->setHealth(-1); - vehicleanim->set_animation_type(VehicleAnimation::kBurntAnim); - break; - case 0x05: - // train head - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Head %d", id)) - break; - case 0x09: - // train body - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Body %d", id)) - break; - case 0x0D: - // grey vehicle - break; - case 0x11: - // firefighters vehicle - break; - case 0x1C: - // small armored vehicle - break; - case 0x24: - // police vehicle - break; - case 0x28: - // medical vehicle - break; -#if _DEBUG - default: - printf("uknown vehicle type %02X , %02X, %X\n", gamdata.sub_type, - gamdata.orientation, - READ_LE_UINT16(gamdata.index_current_frame)); - printf("x = %i, xoff = %i, ", gamdata.mapposx[1], - gamdata.mapposx[0]); - printf("y = %i, yoff = %i, ", gamdata.mapposy[1], - gamdata.mapposy[0]); - printf("z = %i, zoff = %i\n", gamdata.mapposz[1], - gamdata.mapposz[0]); - break; -#endif + Vehicle *pVehicle = NULL; + if (gamdata.sub_type == Vehicle::kVehicleTypeTrainHead) { + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Head %d", id)) + pVehicle = new TrainHead(id, Vehicle::kVehicleTypeTrainHead, vehicleanim); + } else if (gamdata.sub_type == Vehicle::kVehicleTypeTrainBody) { + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Body %d", id)) + pVehicle = new TrainBody(id, Vehicle::kVehicleTypeTrainHead, vehicleanim); + } else { + // standard car + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create generic car %d", id)) + pVehicle = new GenericCar(vehicleanim, id, gamdata.sub_type, map); + pVehicle->setHealth(hp); + pVehicle->setStartHealth(hp); + + switch (gamdata.sub_type) { + case 0x04: + // large armored damaged + // it is actually base animation and they have 8 directions + //setVehicleBaseAnim(vehicleanim, cur_anim - 12 + (dir >> 1)); + vehicleanim->set_base_anims(cur_anim - 12 + (dir >> 1)); + pVehicle->setStartHealth(0); + pVehicle->setHealth(-1); + vehicleanim->set_animation_type(VehicleAnimation::kBurntAnim); + break; + // remaining cases are just here to detect unknown vehicle types + case 0x01: // large armored + case 0x0D: // grey vehicle + case 0x11: // firefighters vehicle + case 0x1C: // small armored vehicle + case 0x24: // police vehicle + case 0x28: // medical vehicle + break; + default: + #if _DEBUG + printf("uknown vehicle type %02X , %02X, %X\n", gamdata.sub_type, + gamdata.orientation, + READ_LE_UINT16(gamdata.index_current_frame)); + printf("x = %i, xoff = %i, ", gamdata.mapposx[1], + gamdata.mapposx[0]); + printf("y = %i, yoff = %i, ", gamdata.mapposy[1], + gamdata.mapposy[0]); + printf("z = %i, zoff = %i\n", gamdata.mapposz[1], + gamdata.mapposz[0]); + #endif + break; + + } } - int z = READ_LE_UINT16(gamdata.mapposz) >> 7; - // TODO: the size should be adjusted on orientation/direction change - // and it should be different per vehicle type - vehicle_new->setSizeX(256); - vehicle_new->setSizeY(256); - vehicle_new->setSizeZ(192); + if (pVehicle) { + int z = READ_LE_UINT16(gamdata.mapposz) >> 7; - int oz = gamdata.mapposz[0] & 0x7F; - vehicle_new->setPosition(gamdata.mapposx[1], gamdata.mapposy[1], - z, gamdata.mapposx[0], - gamdata.mapposy[0], oz); - vehicle_new->setDirection(gamdata.orientation); + // TODO: the size should be adjusted on orientation/direction change + // and it should be different per vehicle type + pVehicle->setSizeX(256); + pVehicle->setSizeY(256); + pVehicle->setSizeZ(192); - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 1 %u", gamdata.unkn1)) - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 2 %u", gamdata.unkn2)) - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 3 %u", gamdata.unkn3)) - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 4 %u", gamdata.unkn4)) - LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 6 %u", gamdata.unkn6)) + int oz = gamdata.mapposz[0] & 0x7F; + pVehicle->setPosition(gamdata.mapposx[1], gamdata.mapposy[1], + z, gamdata.mapposx[0], + gamdata.mapposy[0], oz); + pVehicle->setDirection(gamdata.orientation); - return vehicle_new; + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 1 %u", gamdata.unkn1)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 2 %u", gamdata.unkn2)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 3 %u", gamdata.unkn3)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 4 %u", gamdata.unkn4)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 6 %u", gamdata.unkn6)) + } + + return pVehicle; } void MissionManager::createPeds(const LevelData::LevelDataAll &level_data, DataIndex &di, Mission *pMission) { @@ -655,7 +650,7 @@ pVehicle->addPassenger(p); if (setDriver) { - VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(pVehicle); + GenericCar *pCar = dynamic_cast<GenericCar *>(pVehicle); pCar->setDriver(p); } } @@ -720,7 +715,7 @@ if (v) { if (v->isCar()) { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive car %d to (%d, %d, %d) (%d, %d)", v->id(), locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) - VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(v); + GenericCar *pCar = dynamic_cast<GenericCar *>(v); pPed->addToDefaultActions(new DriveVehicleAction(pCar, locT)); } else { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train %d to (%d, %d, %d) (%d, %d)", v->id(), locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) @@ -752,7 +747,7 @@ } else { if (v->isCar()) { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive car %d to (%d, %d, %d) (%d, %d)", v->id(), v->tileX(), v->tileY(), v->tileZ(), v->offX(), v->offY())) - VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(v); + GenericCar *pCar = dynamic_cast<GenericCar *>(v); pPed->addToDefaultActions( new DriveVehicleAction(pCar, v->position())); } else { Modified: freesynd/trunk/src/model/objectivedesc.cpp =================================================================== --- freesynd/trunk/src/model/objectivedesc.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/model/objectivedesc.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -127,7 +127,7 @@ * \param pMission */ void ObjDestroyVehicle::evaluate(Mission *pMission) { - VehicleInstance *pVehicle = static_cast<VehicleInstance *>(p_target_); + Vehicle *pVehicle = static_cast<Vehicle *>(p_target_); if (pVehicle->isDead()) { endObjective(true); @@ -148,7 +148,7 @@ * \param pMission */ void ObjUseVehicle::evaluate(Mission *pMission) { - VehicleInstance *pVehicle = static_cast<VehicleInstance *>(p_target_); + GenericCar *pVehicle = static_cast<GenericCar *>(p_target_); if (pVehicle->isDead()) { endObjective(false); Modified: freesynd/trunk/src/model/train.cpp =================================================================== --- freesynd/trunk/src/model/train.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/model/train.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -1,6 +1,6 @@ #include "train.h" -TrainHead::TrainHead(uint16 anId, uint8 aType) : TrainBody(anId, aType) { +TrainHead::TrainHead(uint16 anId, uint8 aType, VehicleAnimation *pAnimation) : TrainBody(anId, aType, pAnimation) { } TrainHead::~TrainHead() { @@ -11,9 +11,18 @@ return false; } -TrainBody::TrainBody(uint16 anId, uint8 aType) : Vehicle(anId, aType, -1) { +TrainBody::TrainBody(uint16 anId, uint8 aType, VehicleAnimation *pAnimation) : Vehicle(anId, aType, -1, pAnimation) { } TrainBody::~TrainBody() { } + +/*! + * Moves a vehicle on the map. + * \param elapsed Elapsed time sine last frame. + */ +bool TrainBody::move_vehicle(int elapsed) +{ + return false; +} Modified: freesynd/trunk/src/model/train.h =================================================================== --- freesynd/trunk/src/model/train.h 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/model/train.h 2016-06-04 06:16:14 UTC (rev 1006) @@ -37,9 +37,15 @@ */ class TrainBody : public Vehicle { public: - TrainBody(uint16 id, uint8 aType); + TrainBody(uint16 id, uint8 aType, VehicleAnimation *pAnimation); ~TrainBody(); + bool move_vehicle(int elapsed); + + //! Set the destination to reach at given speed + bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1) { + return false; + } }; /*! @@ -47,7 +53,7 @@ */ class TrainHead : public TrainBody { public: - TrainHead(uint16 id, uint8 aType); + TrainHead(uint16 id, uint8 aType, VehicleAnimation *pAnimation); ~TrainHead(); //! Animates the train Modified: freesynd/trunk/src/model/vehicle.cpp =================================================================== --- freesynd/trunk/src/model/vehicle.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/model/vehicle.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -70,6 +70,39 @@ anims_burnt_ = anims + 12; } +void Vehicle::draw(int x, int y) +{ + y += TILE_HEIGHT / 3; + addOffs(x, y); + + // ensure on map + if (x < 90 || y < -20) + return; + + animation_->draw(x, y, getDirection(4), frame_); +} + +bool Vehicle::animate(int elapsed) +{ + bool updated = false; + + if (health_ > 0) { + updated = move_vehicle(elapsed); + } + + if (animation_->animation_type() == VehicleAnimation::kOnFireAnim) { + if (leftTimeShowAnim(elapsed)) + updated |= MapObject::animate(elapsed); + else { + animation_->set_animation_type(VehicleAnimation::kBurntAnim); + frame_ = 0; + updated = true; + } + } + + return updated; +} + /** * Adds given ped to the list of passengers. * \param pPed PedInstance* @@ -126,47 +159,14 @@ return false; } -VehicleInstance::VehicleInstance(VehicleAnimation * vehicle, uint16 anId, uint8 aType, int m): - Vehicle(anId, aType, m), vehicle_(vehicle) +GenericCar::GenericCar(VehicleAnimation * pAnimation, uint16 anId, uint8 aType, int m): + Vehicle(anId, aType, m, pAnimation) { pDriver_ = NULL; hold_on_.wayFree = 0; } -bool VehicleInstance::animate(int elapsed) -{ - bool updated = false; - - if (health_ > 0) { - updated = move_vehicle(elapsed); - } - - if (vehicle_->animation_type() == VehicleAnimation::kOnFireAnim) { - if (leftTimeShowAnim(elapsed)) - updated |= MapObject::animate(elapsed); - else { - vehicle_->set_animation_type(VehicleAnimation::kBurntAnim); - frame_ = 0; - updated = true; - } - } - - return updated; -} - -void VehicleInstance::draw(int x, int y) -{ - y += TILE_HEIGHT / 3; - addOffs(x, y); - - // ensure on map - if (x < 90 || y < -20) - return; - - vehicle_->draw(x, y, getDirection(4), frame_); -} - -uint16 VehicleInstance::tileDir(int x, int y, int z) { +uint16 GenericCar::tileDir(int x, int y, int z) { uint16 dir = 0x0; int near_tile; Map *pMap = g_App.maps().map(map()); @@ -331,7 +331,7 @@ return dir; } -bool VehicleInstance::dirWalkable(TilePoint *p, int x, int y, int z) { +bool GenericCar::dirWalkable(TilePoint *p, int x, int y, int z) { Map *pMap = g_App.maps().map(map()); if(!(pMap->isTileWalkableByCar(x,y,z))) return false; @@ -370,13 +370,13 @@ * \param newSpeed Speed of movement * \return true if destination has been set correctly. */ -bool VehicleInstance::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { +bool GenericCar::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { speed_ = newSpeed; setDestinationV(locT.tx, locT.ty, locT.tz, locT.ox, locT.oy, newSpeed); return !dest_path_.empty(); } -void VehicleInstance::setDestinationV(int x, int y, int z, int ox, int oy, int new_speed) +void GenericCar::setDestinationV(int x, int y, int z, int ox, int oy, int new_speed) { std::map < TilePoint, uint16 > open; std::set < TilePoint > closed; @@ -665,7 +665,7 @@ * Moves a vehicle on the map. * \param elapsed Elapsed time sine last frame. */ -bool VehicleInstance::move_vehicle(int elapsed) +bool GenericCar::move_vehicle(int elapsed) { bool updated = false; int used_time = elapsed; @@ -776,7 +776,7 @@ * Method called when object is hit by a weapon shot. * \param d Damage description */ -void VehicleInstance::handleHit(ShootableMapObject::DamageInflictType &d) { +void GenericCar::handleHit(ShootableMapObject::DamageInflictType &d) { if (health_ <= 0) return; @@ -788,7 +788,7 @@ case MapObject::dmg_Laser: case MapObject::dmg_Burn: case MapObject::dmg_Explosion: - vehicle_->set_animation_type(VehicleAnimation::kOnFireAnim); + animation_->set_animation_type(VehicleAnimation::kOnFireAnim); setTimeShowAnim(10000); break; } @@ -810,7 +810,7 @@ * has no driver, ped becomes the driver. * \param p The ped */ -void VehicleInstance::addPassenger(PedInstance *p) { +void GenericCar::addPassenger(PedInstance *p) { Vehicle::addPassenger(p); if (pDriver_ == NULL) { // Ped becomes the driver @@ -822,7 +822,7 @@ * Overload initial method to manage driver. * \param pPed The ped to remove. */ -void VehicleInstance::dropPassenger(PedInstance *pPed) { +void GenericCar::dropPassenger(PedInstance *pPed) { Vehicle::dropPassenger(pPed); if (pDriver_ == pPed) { pDriver_ = NULL; @@ -847,7 +847,7 @@ * \return void * */ -void VehicleInstance::setDriver(PedInstance *pPed, bool forceDriver) { +void GenericCar::setDriver(PedInstance *pPed, bool forceDriver) { if (pPed != NULL) { if (pDriver_ == NULL || forceDriver) { pDriver_ = pPed; Modified: freesynd/trunk/src/model/vehicle.h =================================================================== --- freesynd/trunk/src/model/vehicle.h 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/model/vehicle.h 2016-06-04 06:16:14 UTC (rev 1006) @@ -90,10 +90,18 @@ static const uint8 kVehicleTypePolice; static const uint8 kVehicleTypeMedics; - Vehicle(uint16 anId, uint8 aType, int m) : ShootableMovableMapObject(anId, m, MapObject::kNatureVehicle) { + Vehicle(uint16 anId, uint8 aType, int m, VehicleAnimation *pAnimation) : ShootableMovableMapObject(anId, m, MapObject::kNatureVehicle) { type_ = aType; + animation_ = pAnimation; } + virtual ~Vehicle() { + delete animation_; + } + + bool animate(int elapsed); + void draw(int x, int y); + //! Return true if vehicle is a car bool isCar() { return type_ != kVehicleTypeTrainHead && type_ != kVehicleTypeTrainBody; } @@ -112,9 +120,14 @@ bool containsOurAgents(); //! Returns true if the vehicle contains peds considered hostile by the given ped bool containsHostilesForPed(PedInstance *p, unsigned int hostile_desc_alt); + protected: + virtual bool move_vehicle(int elapsed) = 0; +protected: /*! The passengers of the vehicle.*/ std::set <PedInstance *> passengers_; + /*! Animation for vehicle.*/ + VehicleAnimation *animation_; private: /*! Type of vehicle.*/ @@ -122,17 +135,14 @@ }; /*! - * This class represents a Vehicle on a map. + * This class represents a playable car on a map. */ -class VehicleInstance : public Vehicle +class GenericCar : public Vehicle { public: - VehicleInstance(VehicleAnimation *vehicle, uint16 id, uint8 aType, int m); - virtual ~VehicleInstance() { delete vehicle_;} + GenericCar(VehicleAnimation *pAnimation, uint16 id, uint8 aType, int m); + virtual ~GenericCar() {} - bool animate(int elapsed); - void draw(int x, int y); - //! Set the destination to reach at given speed (todo : replace setDestinationV()) bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1); @@ -171,7 +181,6 @@ bool dirWalkable(TilePoint *p, int x, int y, int z); protected: - VehicleAnimation *vehicle_; //! Vehicle driver PedInstance *pDriver_; }; Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/ped.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -1370,7 +1370,7 @@ if (smo->isDead() || (smo->nature() == MapObject::kNaturePed && isFriendWith((PedInstance *)(smo))) || (smo->nature() == MapObject::kNatureVehicle - && ((VehicleInstance *)smo)->containsHostilesForPed(this, hostile_desc_)) + && ((Vehicle *)smo)->containsHostilesForPed(this, hostile_desc_)) || (m->checkIfBlockersInShootingLine(cur_xyz, &smo, NULL, false, false, check_rng, &distTo) != 1)) { Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/ped.h 2016-06-04 06:16:14 UTC (rev 1006) @@ -44,7 +44,7 @@ class Agent; class Mission; class Squad; -class VehicleInstance; +class GenericCar; class Vehicle; #define NUM_ANIMS 10 @@ -335,7 +335,7 @@ MovementAction * createActionEnterVehicle(Vehicle *pVehicle); //! Adds action to drive vehicle to destination void addActionDriveVehicle( - VehicleInstance *pVehicle, const TilePoint &destination, bool appendAction); + GenericCar *pVehicle, const TilePoint &destination, bool appendAction); //! Return true if ped can use a weapon bool canAddUseWeaponAction(WeaponInstance *pWeapon = NULL); //! Adds action to shoot somewhere Modified: freesynd/trunk/src/pedactions.cpp =================================================================== --- freesynd/trunk/src/pedactions.cpp 2016-06-01 22:27:06 UTC (rev 1005) +++ freesynd/trunk/src/pedactions.cpp 2016-06-04 06:16:14 UTC (rev 1006) @@ -281,7 +281,7 @@ //! Adds action to drive vehicle to destination void PedInstance::addActionDriveVehicle( - VehicleInstance *pVehicle, const TilePoint &destination, bool appendAction) { + GenericCar *pVehicle, const TilePoint &destination, bool appendAction) { DriveVehicleAction *pAction = new DriveVehicleAction(pVehicle, destination); addMovementAction(pAction, appendAction); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-06-01 22:27:09
|
Revision: 1005 http://sourceforge.net/p/freesynd/code/1005 Author: benblan Date: 2016-06-01 22:27:06 +0000 (Wed, 01 Jun 2016) Log Message: ----------- Train implementation - moved vehicle files to model directory and added train files - Changed Vehicle::isDrivable() by Vehicle::isCar() - removed unnecessary warning message - fixed some warnings - hacked mission 22 with car position Modified Paths: -------------- freesynd/trunk/src/CMakeLists.txt freesynd/trunk/src/ia/actions.cpp freesynd/trunk/src/mapobject.cpp freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/menus/maprenderer.cpp freesynd/trunk/src/menus/minimaprenderer.cpp freesynd/trunk/src/menus/selectmenu.cpp freesynd/trunk/src/menus/squadselection.cpp freesynd/trunk/src/mission.cpp freesynd/trunk/src/missionmanager.cpp freesynd/trunk/src/missionmanager.h freesynd/trunk/src/model/train.cpp freesynd/trunk/src/model/train.h freesynd/trunk/src/ped.cpp freesynd/trunk/src/pedmanager.cpp freesynd/trunk/src/weapon.cpp Added Paths: ----------- freesynd/trunk/src/model/vehicle.cpp freesynd/trunk/src/model/vehicle.h Removed Paths: ------------- freesynd/trunk/src/vehicle.cpp freesynd/trunk/src/vehicle.h Modified: freesynd/trunk/src/CMakeLists.txt =================================================================== --- freesynd/trunk/src/CMakeLists.txt 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/CMakeLists.txt 2016-06-01 22:27:06 UTC (rev 1005) @@ -14,6 +14,8 @@ model/objectivedesc.cpp model/weaponholder.cpp model/shot.cpp + model/vehicle.cpp + model/train.cpp core/squad.cpp core/gamesession.cpp core/gamecontroller.cpp @@ -79,7 +81,6 @@ utils/log.cpp utils/portablefile.cpp utils/seqmodel.cpp - vehicle.cpp weapon.cpp weaponmanager.cpp ) @@ -115,7 +116,7 @@ resources.h system.h system_sdl.h - vehicle.h + model/vehicle.h version.h weapon.h weaponmanager.h @@ -142,6 +143,7 @@ model/leveldata.h model/shot.h model/weaponholder.h + model/train.h menus/agentselectorrenderer.h menus/maprenderer.h menus/minimaprenderer.h @@ -218,7 +220,7 @@ editor/animmenu.h editor/searchmissionmenu.h editor/listmissionmenu.h) - + add_executable (dump dump.cpp gfx/dirtylist.cpp @@ -253,7 +255,7 @@ mod.cpp modmanager.cpp missionmanager.cpp - vehicle.cpp + model/vehicle.cpp weapon.cpp weaponmanager.cpp core/gamecontroller.cpp @@ -287,7 +289,7 @@ ${DEV_TOOLS_HEADERS} ) target_link_libraries (dump ${PNG_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY}) - + target_compile_definitions (dump PRIVATE EDITOR_) else () # We only define an install target if we're doing a release build. Modified: freesynd/trunk/src/ia/actions.cpp =================================================================== --- freesynd/trunk/src/ia/actions.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/ia/actions.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -29,7 +29,7 @@ #include "app.h" #include "ped.h" #include "weapon.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "mission.h" #include "agentmanager.h" #include "core/squad.h" @@ -601,7 +601,7 @@ } void DriveVehicleAction::doStart(Mission *pMission, PedInstance *pPed) { - if (pVehicle_->isDead() || !pVehicle_->isInsideVehicle(pPed)) { + if (pVehicle_->isDead() || !pVehicle_->containsPed(pPed)) { setFailed(); } Modified: freesynd/trunk/src/mapobject.cpp =================================================================== --- freesynd/trunk/src/mapobject.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/mapobject.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -28,7 +28,7 @@ #include "common.h" #include "utils/log.h" #include "app.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "core/gamesession.h" #include "mission.h" Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -33,7 +33,7 @@ #include "menus/gamemenuid.h" #include "gfx/fliplayer.h" #include "utils/file.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "mission.h" #include "model/shot.h" @@ -993,7 +993,7 @@ uint8 weapon_idx = (uint8) key.keyFunc - (uint8) KFC_F5; handleWeaponSelection(weapon_idx, ctrl); return true; - } else if (isLetterD(key.unicode) && ctrl) { // selected agents are killed with 'd' + } else if ((isLetterD(key.unicode)) && ctrl) { // selected agents are killed with 'd' // save current selection as it will be modified when agents die std::vector<PedInstance *> agents_suicide; for (SquadSelection::Iterator it = selection_.begin(); @@ -1431,9 +1431,9 @@ if (mission_->getSquad()->isAllDead()) { mission_->endWithStatus(Mission::kMissionStatusFailed); // clear signal on minimap - GameEvent evt; - evt.type = GameEvent::kObjFailed; - mm_renderer_.handleGameEvent(evt); + GameEvent sigEvt; + sigEvt.type = GameEvent::kObjFailed; + mm_renderer_.handleGameEvent(sigEvt); } // Anyway update selection Modified: freesynd/trunk/src/menus/maprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/maprenderer.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/menus/maprenderer.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -28,7 +28,7 @@ #include "menus/maprenderer.h" #include "common.h" #include "mission.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "agentmanager.h" #include "mapobject.h" #include "core/squad.h" Modified: freesynd/trunk/src/menus/minimaprenderer.cpp =================================================================== --- freesynd/trunk/src/menus/minimaprenderer.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/menus/minimaprenderer.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -25,7 +25,7 @@ #include "core/missionbriefing.h" #include "mission.h" #include "gfx/screen.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "ped.h" const int MinimapRenderer::kMiniMapSizePx = 128; Modified: freesynd/trunk/src/menus/selectmenu.cpp =================================================================== --- freesynd/trunk/src/menus/selectmenu.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/menus/selectmenu.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -88,8 +88,8 @@ /*! * Draws a dashed line around the currently selected agent selector. - * \param x Coordinates of the top left corner - * \param y Coordinates of the top left corner + * \param x Coordinates of the top left corner + * \param y Coordinates of the top left corner */ void SelectMenu::drawAgentSelector(int x, int y) { // First create a transparent sprite @@ -259,7 +259,7 @@ tick_count_ += elapsed; // Updates the moving agent selector if (tick_count_ > 300) { - rnd_ = ++rnd_ % 8; + rnd_ = (rnd_ + 1) % 8; tick_count_ = 0; needRendering(); } @@ -270,7 +270,7 @@ } } -/*! +/*! * Update the game time display */ void SelectMenu::updateClock() { @@ -347,7 +347,7 @@ g_Screen.drawRect(502, 268, 124, 2, fs_cmn::kColorDarkGreen); g_Screen.drawRect(502, 292, 124, 2, fs_cmn::kColorDarkGreen); g_Screen.drawRect(502, 318, 124, 2, fs_cmn::kColorDarkGreen); - + getMenuFont(FontManager::SIZE_1)->drawText(x, y, pSelectedMod_->getName(), true); char tmp[100]; sprintf(tmp, "COST :%d", pSelectedMod_->cost()); @@ -693,7 +693,7 @@ // get the selected agent from the team listbox std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); Agent *pNewAgent = static_cast<Agent *> (pPair->second); - + bool found = false; // check if selected agent is already part of the mission squad for (size_t j = 0; j < AgentManager::kMaxSlot; j++) { @@ -717,7 +717,7 @@ // redraw agent buttons dirtyAgentSelector(); } - + } else if (actionId == pModsLBox_->getId()) { std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); pSelectedMod_ = static_cast<Mod *> (pPair->second); @@ -785,7 +785,7 @@ } showItemList(); } - + } else if (actionId == sellButId_ && selectedWInstId_) { addDirtyRect(360, 305, 135, 70); Agent *selected = g_gameCtrl.agents().squadMember(cur_agent_); Modified: freesynd/trunk/src/menus/squadselection.cpp =================================================================== --- freesynd/trunk/src/menus/squadselection.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/menus/squadselection.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -22,7 +22,7 @@ #include "menus/squadselection.h" #include "ped.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "core/gameevent.h" #include "mission.h" @@ -245,22 +245,21 @@ */ void SquadSelection::enterOrLeaveVehicle(Vehicle *pVehicle, bool addAction) { // true means every one get in the vehicle - bool getIn = leader()->inVehicle() == NULL; + bool leaderIsInVehicle = leader()->inVehicle() == NULL; for (SquadSelection::Iterator it = begin(); it != end(); ++it) { PedInstance *pAgent = *it; - if (getIn && !pAgent->inVehicle()) { - // Agent is out and everybody must get in + if (leaderIsInVehicle && !pAgent->inVehicle()) { + // Agent is out and leader is in MovementAction *pAction = pAgent->createActionEnterVehicle(pVehicle); pAgent->addMovementAction(pAction, addAction); - //pAgent->addActionEnterVehicle(kOrigUser, pVehicle, addAction); - } else if (!getIn && pAgent->inVehicle() == pVehicle) { - // Agent is in the given car and everybody must get out + } else if (!leaderIsInVehicle && pAgent->inVehicle() == pVehicle) { + // Agent is in the given car and leader is out // first stops the vehicle if it's a car - if (pVehicle->speed() != 0 && pVehicle->isDrivable()) { + if (pVehicle->speed() != 0 && pVehicle->isCar()) { pVehicle->clearDestination(); // tells the driver to stop VehicleInstance *pVi = dynamic_cast<VehicleInstance *>(pVehicle); @@ -291,7 +290,7 @@ PedInstance *pAgent = *it; Vehicle *pVehicle = pAgent->inVehicle(); if (pVehicle) { - if (pVehicle->isDrivable()) { + if (pVehicle->isCar()) { // Agent is in drivable vehicle VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(pVehicle); if (pCar->isDriver(pAgent)) Modified: freesynd/trunk/src/mission.cpp =================================================================== --- freesynd/trunk/src/mission.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/mission.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -35,7 +35,7 @@ #include "app.h" #include "model/objectivedesc.h" #include "utils/log.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "core/squad.h" #include "model/shot.h" Modified: freesynd/trunk/src/missionmanager.cpp =================================================================== --- freesynd/trunk/src/missionmanager.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/missionmanager.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -33,11 +33,16 @@ #include "core/gamecontroller.h" #include "core/missionbriefing.h" #include "model/objectivedesc.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "mission.h" #include "core/squad.h" #include "pedmanager.h" +/*! + * Offset in the game data from the start to find the scenario section. + */ +const uint32 kScenarioOffset = 97128; + class LoadMissionException : public std::exception { public: @@ -194,20 +199,26 @@ if (missionId == 10) { // Western Europe // Change the second destination of the car for ped #168 // as in original scenario that destination seems non walkable - uint8 *scen_start = data + 97128 + 8 * 8; + uint8 *scen_start = data + kScenarioOffset + 8 * 8; scen_start[4] = 74; scen_start[5] = 120; scen_start[6] = 2; - }else if (missionId == 40) { - // Kenya map, adding additional walking points to scenarios - uint8 *scen_start = data + 97128 + 8 * 86; + } else if (missionId == 22) { // Siberia + // Change destination of second action for ped #192 (police) + // because in original it is not walkable + uint8 *scen_start = data + kScenarioOffset + 8 * 7; + scen_start[5] = 120; + scen_start[6] = 3; + } else if (missionId == 40) { // Kenya + // adding additional walking points to scenarios + uint8 *scen_start = data + kScenarioOffset + 8 * 86; // coord offsets changing for next point scen_start[4] = ((scen_start[4] & 0xFE) | 1); scen_start[5] = (scen_start[5] & 0xFE); - scen_start = data + 97128 + 8 * 87; + scen_start = data + kScenarioOffset + 8 * 87; WRITE_LE_UINT16(scen_start, 90 * 8); - scen_start = data + 97128 + 8 * 90; + scen_start = data + kScenarioOffset + 8 * 90; WRITE_LE_UINT16(scen_start, 91 *8); scen_start += 4; // coords x = 72,ox = 128, y = 32, oy = 128, z = 2 @@ -483,7 +494,7 @@ // car.sub_type 0x09 - train if (car.type == 0x0) continue; - VehicleInstance *v = + Vehicle *v = createVehicleInstance(car, i, pMission->mapId()); if (v) { di.vindx[i] = pMission->numVehicles(); @@ -499,7 +510,7 @@ /*! * */ -VehicleInstance * MissionManager::createVehicleInstance(const LevelData::Cars &gamdata, uint16 id, uint16 map) +Vehicle * MissionManager::createVehicleInstance(const LevelData::Cars &gamdata, uint16 id, uint16 map) { // TODO: check all maps // TODO: train, join somehow @@ -511,10 +522,10 @@ int cur_anim = READ_LE_UINT16(gamdata.index_current_anim) - dir; //setVehicleBaseAnim(vehicleanim, cur_anim); vehicleanim->set_base_anims(cur_anim); - VehicleInstance *vehicle_new = new VehicleInstance(vehicleanim, id, map); + Vehicle *vehicle_new = new VehicleInstance(vehicleanim, id, gamdata.sub_type, map); vehicle_new->setHealth(hp); vehicle_new->setStartHealth(hp); - vehicle_new->setType(gamdata.sub_type); + switch (gamdata.sub_type) { case 0x01: // large armored @@ -530,8 +541,11 @@ break; case 0x05: // train head + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Head %d", id)) + break; case 0x09: // train body + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", ("Create Train Body %d", id)) break; case 0x0D: // grey vehicle @@ -576,6 +590,12 @@ gamdata.mapposy[0], oz); vehicle_new->setDirection(gamdata.orientation); + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 1 %u", gamdata.unkn1)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 2 %u", gamdata.unkn2)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 3 %u", gamdata.unkn3)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 4 %u", gamdata.unkn4)) + LOG(Log::k_FLG_GAME, "MissionManager","createVehicleInstance", (" - field unknown 6 %u", gamdata.unkn6)) + return vehicle_new; } @@ -698,9 +718,14 @@ pPed->addToDefaultActions(new TriggerAction(6 * 256, locW)); } if (v) { - LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive car to (%d, %d, %d) (%d, %d)", locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) - VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(v); - pPed->addToDefaultActions(new DriveVehicleAction(pCar, locT)); + if (v->isCar()) { + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive car %d to (%d, %d, %d) (%d, %d)", v->id(), locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) + VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(v); + pPed->addToDefaultActions(new DriveVehicleAction(pCar, locT)); + } else { + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train %d to (%d, %d, %d) (%d, %d)", v->id(), locT.tx, locT.ty, locT.tz, locT.ox, locT.oy)) + // TODO : add drive train action + } } else { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Walk toward location (%d, %d, %d)", locT.tx, locT.ty, locT.tz)) pPed->addToDefaultActions(new WalkToDirectionAction(locW)); @@ -711,7 +736,7 @@ } } else if (sc.type == LevelData::kScenarioTypeUseVehicle) { if (!isInVehicle) { - LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Enter car")) + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Enter vehicle")) uint16 bindx = READ_LE_UINT16(sc.offset_object); // TODO: test all maps for objects other then vehicle assert(bindx >= 0x5C02 && bindx < 0x6682); @@ -725,10 +750,14 @@ pPed->addToDefaultActions(pAction); } } else { - LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive to (%d, %d, %d) (%d, %d)", v->tileX(), v->tileY(), v->tileZ(), v->offX(), v->offY())) - VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(v); - pPed->addToDefaultActions( + if (v->isCar()) { + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive car %d to (%d, %d, %d) (%d, %d)", v->id(), v->tileX(), v->tileY(), v->tileZ(), v->offX(), v->offY())) + VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(v); + pPed->addToDefaultActions( new DriveVehicleAction(pCar, v->position())); + } else { + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Drive train %d to (%d, %d, %d) (%d, %d)", v->id(), v->tileX(), v->tileY(), v->tileZ(), v->offX(), v->offY())) + } } } else if (sc.type == LevelData::kScenarioTypeEscape) { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Escape")) @@ -737,7 +766,7 @@ LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - Reset actions")) pPed->addToDefaultActions(new ResetScriptedAction(Action::kActionDefault)); } else if (sc.type == 10) { - printf("Scenario type 10\n"); + LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" scenario type 10")) } else { LOG(Log::k_FLG_GAME, "MissionManager","createScriptedActionsForPed", (" - unknown type %d", sc.type)) } Modified: freesynd/trunk/src/missionmanager.h =================================================================== --- freesynd/trunk/src/missionmanager.h 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/missionmanager.h 2016-06-01 22:27:06 UTC (rev 1005) @@ -81,7 +81,7 @@ void createVehicles(const LevelData::LevelDataAll &level_data, DataIndex &di, Mission *pMission); //! Creates a vehicle from the game data - VehicleInstance * createVehicleInstance(const LevelData::Cars &gamdata, uint16 id, uint16 map); + Vehicle * createVehicleInstance(const LevelData::Cars &gamdata, uint16 id, uint16 map); //! Creates all peds void createPeds(const LevelData::LevelDataAll &level_data, DataIndex &di, Mission *pMission); Modified: freesynd/trunk/src/model/train.cpp =================================================================== --- freesynd/trunk/src/model/train.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/model/train.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -1,24 +1,19 @@ #include "train.h" -Train::Train() { +TrainHead::TrainHead(uint16 anId, uint8 aType) : TrainBody(anId, aType) { } -Train::~Train() { - for (std::list < TrainElement * >::iterator it = elements_.begin(); - it != elements_.end(); it++) { - TrainElement *elem = *it; - delete elem; - } - elements_.clear(); +TrainHead::~TrainHead() { + } -bool Train::animate(int elapsed) { +bool TrainHead::animate(int elapsed) { return false; } -TrainElement::TrainElement() : Vehicle(-1, false) { -//TrainElement::TrainElement() : Vehicle(-1) { +TrainBody::TrainBody(uint16 anId, uint8 aType) : Vehicle(anId, aType, -1) { + } -TrainElement::~TrainElement() { -} \ No newline at end of file +TrainBody::~TrainBody() { +} Modified: freesynd/trunk/src/model/train.h =================================================================== --- freesynd/trunk/src/model/train.h 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/model/train.h 2016-06-01 22:27:06 UTC (rev 1005) @@ -35,27 +35,25 @@ /*! * . */ -class TrainElement : public Vehicle { +class TrainBody : public Vehicle { public: - TrainElement(); - ~TrainElement(); + TrainBody(uint16 id, uint8 aType); + ~TrainBody(); }; /*! * . */ -class Train { +class TrainHead : public TrainBody { public: - Train(); - ~Train(); + TrainHead(uint16 id, uint8 aType); + ~TrainHead(); - std::list<TrainElement *> & elements() { return elements_; } - //! Animates the train bool animate(int elapsed); private: - std::list<TrainElement *> elements_; + }; -#endif // MODEL_TRAIN_H_ \ No newline at end of file +#endif // MODEL_TRAIN_H_ Copied: freesynd/trunk/src/model/vehicle.cpp (from rev 1004, freesynd/trunk/src/vehicle.cpp) =================================================================== --- freesynd/trunk/src/model/vehicle.cpp (rev 0) +++ freesynd/trunk/src/model/vehicle.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -0,0 +1,860 @@ +/************************************************************************ + * * + * FreeSynd - a remake of the classic Bullfrog game "Syndicate". * + * * + * Copyright (C) 2005 Stuart Binge <sk...@gm...> * + * Copyright (C) 2005 Joost Peters <jo...@us...> * + * Copyright (C) 2006 Trent Waddington <qg...@bi...> * + * Copyright (C) 2006 Tarjei Knapstad <tar...@gm...> * + * Copyright (C) 2010 Bohdan Stelmakh <ch...@us...> * + * Copyright (C) 2013 Benoit Blancard <be...@us...>* + * * + * This program is free software; you can redistribute it and / or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You can view the GNU General Public License, online, at the GNU * + * project's web site; see <http://www.gnu.org/licenses/gpl.html>. * + * The full text of the license is also included in the file COPYING. * + * * + ************************************************************************/ + +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "app.h" +#include "core/gamesession.h" +#include "gfx/screen.h" +#include "vehicle.h" +#include "model/shot.h" + +const uint8 Vehicle::kVehicleTypeLargeArmored = 0x01; +const uint8 Vehicle::kVehicleTypeLargeArmoredDamaged = 0x04; +const uint8 Vehicle::kVehicleTypeTrainHead = 0x05; +const uint8 Vehicle::kVehicleTypeTrainBody = 0x09; +const uint8 Vehicle::kVehicleTypeRegularCar = 0x0D; +const uint8 Vehicle::kVehicleTypeFireFighter = 0x11; +const uint8 Vehicle::kVehicleTypeSmallArmored = 0x1C; +const uint8 Vehicle::kVehicleTypePolice = 0x24; +const uint8 Vehicle::kVehicleTypeMedics = 0x28; + +VehicleAnimation::VehicleAnimation() { + vehicle_anim_ = kNormalAnim; +} + +void VehicleAnimation::draw(int x, int y, int dir, int frame) +{ + switch (vehicle_anim_) { + case kNormalAnim: + g_App.gameSprites().drawFrame(anims_ + dir * 2, frame, x, y); + break; + case kOnFireAnim: + g_App.gameSprites().drawFrame(anims_burning_ + dir, frame, x, y); + break; + case kBurntAnim: + g_App.gameSprites().drawFrame(anims_burnt_ + dir, frame, x, y); + break; + } +} + +void VehicleAnimation::set_base_anims(int anims) { + anims_ = anims; + anims_burning_ = anims + 8; + anims_burnt_ = anims + 12; +} + +/** + * Adds given ped to the list of passengers. + * \param pPed PedInstance* + * \return void + * + */ +void Vehicle::addPassenger(PedInstance *pPed) { + if(!containsPed(pPed)) { + passengers_.insert(pPed); + pPed->putInVehicle(this); + } +} + +/*! + * Removes given passenger from vehicle. + * \param pPed Ped to remove + */ +void Vehicle::dropPassenger(PedInstance *pPed) { + if(containsPed(pPed)) { + pPed->leaveVehicle(); + passengers_.erase(passengers_.find(pPed)); + } +} + +/*! + * Returns true if at least one of our agent is inside the vehicle. + */ +bool Vehicle::containsOurAgents() { + for (std::set<PedInstance *>::iterator it = passengers_.begin(); + it != passengers_.end(); it++) + { + if ((*it)->isOurAgent()) { + return true; + } + } + return false; +} + +/*! + * Returns true if the vehicle contains peds considered hostile by the given ped. + * \param pPed The ped evaluating the hostility of the vehicle + * \param hostile_desc_alt Parameter for evaluating the hostility + * \return True if at least one hostile ped is found. + */ +bool Vehicle::containsHostilesForPed(PedInstance* p, + unsigned int hostile_desc_alt) +{ + for (std::set<PedInstance *>::iterator it = passengers_.begin(); + it != passengers_.end(); it++) + { + if (p->isHostileTo((ShootableMapObject *)(*it), hostile_desc_alt)) + return true; + } + return false; +} + +VehicleInstance::VehicleInstance(VehicleAnimation * vehicle, uint16 anId, uint8 aType, int m): + Vehicle(anId, aType, m), vehicle_(vehicle) +{ + pDriver_ = NULL; + hold_on_.wayFree = 0; +} + +bool VehicleInstance::animate(int elapsed) +{ + bool updated = false; + + if (health_ > 0) { + updated = move_vehicle(elapsed); + } + + if (vehicle_->animation_type() == VehicleAnimation::kOnFireAnim) { + if (leftTimeShowAnim(elapsed)) + updated |= MapObject::animate(elapsed); + else { + vehicle_->set_animation_type(VehicleAnimation::kBurntAnim); + frame_ = 0; + updated = true; + } + } + + return updated; +} + +void VehicleInstance::draw(int x, int y) +{ + y += TILE_HEIGHT / 3; + addOffs(x, y); + + // ensure on map + if (x < 90 || y < -20) + return; + + vehicle_->draw(x, y, getDirection(4), frame_); +} + +uint16 VehicleInstance::tileDir(int x, int y, int z) { + uint16 dir = 0x0; + int near_tile; + Map *pMap = g_App.maps().map(map()); + + switch(pMap->tileAt(x, y, z)){ + case 80: + if(g_App.maps().map(map())->tileAt(x + 1, y, z) == 80) + dir = (0)|(0xFFF0); + if(pMap->tileAt(x - 1, y, z) == 80) + dir = (4<<8)|(0xF0FF); + break; + case 81: + if(pMap->tileAt(x, y - 1, z) == 81) + dir = (2<<4)|(0xFF0F); + if(pMap->tileAt(x, y + 1, z) == 81) + dir = (6<<12)|(0x0FFF); + break; + case 106: + dir = (0)|(2<<4)|(6<<12)|(0x0F00); + + if(pMap->tileAt(x + 1, y - 1, z) != 118) + dir |= 0x0FF0; + if(pMap->tileAt(x + 1, y + 1, z) != 118) + dir |= 0xFF00; + near_tile = pMap->tileAt(x + 1, y, z); + if (near_tile == 108 || near_tile == 109) + dir = (dir & 0x0FFF) | 0x6000; + + break; + case 107: + dir = (2<<4)|(4<<8)|(6<<12)|(0x000F); + + if(pMap->tileAt(x - 1, y - 1, z) != 118) + dir |= 0x00FF; + if(pMap->tileAt(x - 1, y + 1, z) != 118) + dir |= 0xF00F; + near_tile = pMap->tileAt(x - 1, y, z); + if (near_tile == 108 || near_tile == 109) + dir = (dir & 0xFF0F) | 0x0020; + + break; + case 108: + dir = (0)|(2<<4)|(4<<8)|(0xF000); + + if(pMap->tileAt(x + 1, y - 1, z) != 118) + dir |= 0xF00F; + if(pMap->tileAt(x - 1, y - 1, z) != 118) + dir |= 0xFF00; + near_tile = pMap->tileAt(x, y - 1, z); + if (near_tile == 106 || near_tile == 107) + dir = dir & 0xFFF0; + + break; + case 109: + dir = (0)|(4<<8)|(6<<12)|(0x00F0); + + if(pMap->tileAt(x + 1, y + 1, z) != 118) + dir |= 0x00FF; + if(pMap->tileAt(x - 1, y + 1, z) != 118) + dir |= 0x0FF0; + near_tile = pMap->tileAt(x, y + 1, z); + if (near_tile == 106 || near_tile == 107) + dir = (dir & 0xF0FF) | 0x0400; + + break; + case 110: + dir = (0) | (2<<4)|(0xFF00); + break; + case 111: + dir = (0) | (6<<12)|(0x0FF0); + break; + case 112: + dir = (2<<4)|(4<<8)|(0xF00F); + break; + case 113: + dir = (4<<8)|(6<<12)|(0x00FF); + break; + /*case 119: + // TODO: Greenland map needs fixing + dir = 0xFFFF; + near_tile = pMap->tileAt(x, y + 1, z); + if (near_tile == 107 || near_tile == 225 || near_tile == 226) + dir = (dir & 0xF0FF) | 0x0400; + near_tile = pMap->tileAt(x, y + 1, z); + if (near_tile == 106 || near_tile == 225 || near_tile == 226) + dir &= 0xFFF0; + near_tile = pMap->tileAt(x + 1, y, z); + if (near_tile == 109 || near_tile == 225 || near_tile == 226) + dir = (dir & 0xFF0F) | 0x0020; + near_tile = pMap->tileAt(x - 1, y, z); + if (near_tile == 108 || near_tile == 225 || near_tile == 226) + dir = (dir & 0x0FFF) | 0x6000; + if (dir ==0xFFFF) + dir = 0x0; + break;*/ + case 120: + dir = (0)|(2<<4)|(0xFF00); + break; + case 121: + dir = (0)|(6<<12)|(0x0FF0); + break; + case 122: + dir = (4<<8)|(6<<12)|(0x00FF); + break; + case 123: + dir = (2<<4)|(4<<8)|(0xF00F); + break; + case 225:/* + if(g_App.maps().map(map())->getTileAt(x + 1, y, z)->type() == Tile::kRoadPedCross) + dir = (0)|(0xFFF0); + else if(g_App.maps().map(map())->getTileAt(x - 1, y, z)->type() == Tile::kRoadPedCross) + dir = (4<<8)|(0xF0FF); + else {*/ + dir = 0xFFFF; + near_tile = pMap->tileAt(x, y + 1, z); + if (/*near_tile == 119 || */near_tile == 106 + || near_tile == 107 || near_tile == 80 || near_tile == 225) + dir = (dir & 0xF0FF) | 0x0400; + near_tile = pMap->tileAt(x, y - 1, z); + if (/*near_tile == 119 || */near_tile == 106 + || near_tile == 107 || near_tile == 80 || near_tile == 225) + dir &= 0xFFF0; + near_tile = pMap->tileAt(x + 1, y, z); + if (/*near_tile == 119 || */near_tile == 108 || near_tile == 81) + dir = (dir & 0xFF0F) | 0x0020; + near_tile = pMap->tileAt(x - 1, y, z); + if (/*near_tile == 119 || */near_tile == 109 || near_tile == 81) + dir = (dir & 0x0FFF) | 0x6000; + if (dir == 0xFFFF) + dir = 0x0; + //} + break; + case 226:/* + if(g_App.maps().map(map())->getTileAt(x, y - 1, z)->type() == Tile::kRoadPedCross) + dir = (2<<4)|(0xFF0F); + else if(g_App.maps().map(map())->getTileAt(x, y + 1, z)->type() == Tile::kRoadPedCross) + dir = (6<<12)|(0x0FFF); + else {*/ + dir = 0xFFFF; + near_tile = pMap->tileAt(x, y + 1, z); + if (/*near_tile == 119 || */near_tile == 106 || near_tile == 80) + dir = (dir & 0xF0FF) | 0x0400; + near_tile = pMap->tileAt(x, y - 1, z); + if (/*near_tile == 119 || */near_tile == 107 || near_tile == 80) + dir &= 0xFFF0; + near_tile = pMap->tileAt(x + 1, y, z); + if (/*near_tile == 119 || */near_tile == 108 || near_tile == 109 + || near_tile == 81 || near_tile == 226) + dir = (dir & 0xFF0F) | 0x0020; + near_tile = pMap->tileAt(x - 1, y, z); + if (/*near_tile == 119 || */near_tile == 108 || near_tile == 109 + || near_tile == 81 || near_tile == 226) + dir = (dir & 0x0FFF) | 0x6000; + if (dir == 0xFFFF) + dir = 0; + //} + break; + default: + dir = 0xFFFF; + } + + return dir; +} + +bool VehicleInstance::dirWalkable(TilePoint *p, int x, int y, int z) { + Map *pMap = g_App.maps().map(map()); + if(!(pMap->isTileWalkableByCar(x,y,z))) + return false; + + uint16 dirStart = tileDir(p->tx,p->ty,p->tz); + uint16 dirEnd = tileDir(x,y,z); + if (dirStart == 0x0 || dirEnd == 0x0) + return false; + if (dirStart == 0xFFFF || dirEnd == 0xFFFF) + return true; + + if (((dirStart & 0xF000) != 0xF000) + || ((dirEnd & 0xF000) != 0xF000)) + if ((dirStart & 0xF000) == (dirEnd & 0xF000)) + return true; + if (((dirStart & 0x0F00) != 0x0F00) + || ((dirEnd & 0x0F00) != 0x0F00)) + if ((dirStart & 0x0F00) == (dirEnd & 0x0F00)) + return true; + if (((dirStart & 0x00F0) != 0x00F0) + || ((dirEnd & 0x00F0) != 0x00F0)) + if ((dirStart & 0x00F0) == (dirEnd & 0x00F0)) + return true; + if (((dirStart & 0x000F) != 0x000F) + || ((dirEnd & 0x000F) != 0x000F)) + if ((dirStart & 0x000F) == (dirEnd & 0x000F)) + return true; + + return false; +} + +/*! + * Sets a destination point for the vehicle to reach at given speed. + * \param m + * \param locT destination point + * \param newSpeed Speed of movement + * \return true if destination has been set correctly. + */ +bool VehicleInstance::setDestination(Mission *m, const TilePoint &locT, int newSpeed) { + speed_ = newSpeed; + setDestinationV(locT.tx, locT.ty, locT.tz, locT.ox, locT.oy, newSpeed); + return !dest_path_.empty(); +} + +void VehicleInstance::setDestinationV(int x, int y, int z, int ox, int oy, int new_speed) +{ + std::map < TilePoint, uint16 > open; + std::set < TilePoint > closed; + std::map < TilePoint, TilePoint > parent; + int basex = pos_.tx, basey = pos_.ty; + std::vector < TilePoint > path2add; + path2add.reserve(16); + Map *pMap = g_App.maps().map(map_); + + pMap->adjXYZ(x, y, z); + // NOTE: we will be using lower tiles, later will restore Z coord + z = pos_.tz - 1; + + dest_path_.clear(); + setSpeed(0); + + if (map_ == -1 || health_ <= 0 || !(pMap->isTileWalkableByCar(x, y, z))) { +#if 0 +#if _DEBUG + if (!(map_ == -1 || health_ <= 0)) { + printf("non-walking tile is target to drive\n"); + printf("tileAt %i\n", + (unsigned int)g_App.maps().map(map())->tileAt(x, y, z)); + printf("tile x = %i, y = %i, z = %i\n", x, y, z); + } +#endif +#endif + return; + } + + if (!pMap->isTileWalkableByCar(pos_.tx, pos_.ty, z)) { + int dBest = 100000, dCur; + std::vector < TilePoint > path2wtile; + path2wtile.reserve(16); + // we got somewhere we shouldn't, we need to find somewhere that is walkable + TilePoint pntile(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); + for (int i = 1; i < 16; i++) { + if (pos_.tx + i >= pMap->maxX()) + break; + pntile.tx = pos_.tx + i; + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, z)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + path2add = path2wtile; + basex = pos_.tx + i; + basey = pos_.ty; + break; + } + } + } + + path2wtile.clear(); + pntile = TilePoint(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); + for (int i = -1; i > -16; --i) { + if (pos_.tx + i < 0) + break; + pntile.tx = (pos_.tx + i); + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, z)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + path2add = path2wtile; + basex = pos_.tx + i; + basey = pos_.ty; + break; + } + } + } + + path2wtile.clear(); + pntile = TilePoint(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); + for (int i = -1; i > -16; --i) { + if (pos_.ty + i < 0) + break; + pntile.ty = (pos_.ty + i); + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, z)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + path2add = path2wtile; + basex = pos_.tx; + basey = pos_.ty + i; + break; + } + } + } + + path2wtile.clear(); + pntile = TilePoint(pos_.tx , pos_.ty, z, pos_.ox, pos_.oy); + for (int i = 1; i < 16; i++) { + if (pos_.ty + i >= pMap->maxY()) + break; + pntile.ty = pos_.ty + i; + path2wtile.push_back(pntile); + if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, z)) { + dCur = i * i; + if(dCur < dBest) { + dBest = dCur; + path2add = path2wtile; + basex = pos_.tx; + basey = pos_.ty + i; + break; + } + } + } + if(dBest == 100000) + return; + } + + TilePoint closest; + float closest_dist = 100000; + + uint16 wrong_dir = (uint16)getDirection(4); + if (wrong_dir == 0x0) + wrong_dir = 0x0400; + else if(wrong_dir == 0x1) + wrong_dir = 0x6000; + else if(wrong_dir == 0x2) + wrong_dir = 0x0; + else if(wrong_dir == 0x3) + wrong_dir = 0x0020; + open.insert(std::pair< TilePoint, uint16 >(TilePoint(basex, basey, z, pos_.ox, pos_.oy), + wrong_dir)); + int watchDog = 1000; + + while (!open.empty()) { + watchDog--; + float dist = 100000; + TilePoint p; + std::map < TilePoint, uint16 >::iterator pit; + for (std::map < TilePoint, uint16 >::iterator it = open.begin(); + it != open.end(); it++) + { + float d = + sqrt((float) (x - it->first.tx) * (x - it->first.tx) + + (y - it->first.ty) * (y - it->first.ty)); + if (d < dist) { + dist = d; + p = it->first; + pit = it; // it cannot be const_iterator because of this assign + wrong_dir = it->second; + } + } + if (dist < closest_dist) { + closest = p; + closest_dist = dist; + } + //printf("found best dist %f in %i nodes\n", dist, open.size()); + open.erase(pit); + closed.insert(p); + + if ((p.tx == x && p.ty == y && p.tz == z) + || watchDog < 0) + { + if (watchDog < 0) { + p = closest; + dest_path_. + push_front(TilePoint + (p.tx, p.ty, p.tz, ox, oy)); + } else + dest_path_.push_front(TilePoint(x, y, z, ox, oy)); + while (parent.find(p) != parent.end()) { + p = parent[p]; + if (p.tx == pos_.tx && p.ty == pos_.ty + && p.tz == z) + break; + dest_path_.push_front(p); + } + break; + } + + std::map <TilePoint, uint16> neighbours; + uint16 goodDir = tileDir(p.tx, p.ty, p.tz); + + if (wrong_dir != 0x6000 && p.tx > 0) { + if (dirWalkable(&p, p.tx - 1, p.ty, p.tz) + && ((goodDir & 0xF000) == 0x6000 || goodDir == 0xFFFF)) + neighbours[TilePoint(p.tx - 1, p.ty, p.tz)] = 0x0020; + } + + if (wrong_dir != 0x0020 && p.tx < g_App.maps().map(map())->maxX()) { + if (dirWalkable(&p, p.tx + 1, p.ty, p.tz) + && ((goodDir & 0x00F0) == 0x0020 || goodDir == 0xFFFF)) + neighbours[TilePoint(p.tx + 1, p.ty, p.tz)] = 0x6000; + } + + if (wrong_dir != 0x0400 && p.ty > 0) + if (dirWalkable(&p, p.tx, p.ty - 1, p.tz) + && ((goodDir & 0x0F00) == 0x0400 || goodDir == 0xFFFF)) + neighbours[TilePoint(p.tx, p.ty - 1, p.tz)] = 0x0; + + if (wrong_dir != 0x0000 && p.ty < g_App.maps().map(map())->maxY()) + if (dirWalkable(&p, p.tx, p.ty + 1, p.tz) + && ((goodDir & 0x000F) == 0x0 || goodDir == 0xFFFF)) + neighbours[TilePoint(p.tx, p.ty + 1, p.tz)] = 0x0400; + + for (std::map <TilePoint, uint16>::iterator it = neighbours.begin(); + it != neighbours.end(); it++) + if (dirWalkable(&p, it->first.tx, it->first.ty, + it->first.tz) + && open.find(it->first) == open.end() + && closed.find(it->first) == closed.end()) + { + parent[it->first] = p; + open.insert(*it); + } + } + + if(!dest_path_.empty()) { + // Adjusting offsets for correct positioning + speed_ = new_speed; + int curox = pos_.ox; + int curoy = pos_.oy; + for(std::list < TilePoint >::iterator it = dest_path_.begin(); + it != dest_path_.end(); it++) + { + // TODO : adjust offsets respecting direction relative to + // close next tiles + switch(tileDir(it->tx, it->ty, it->tz)) { + case 0xFFF0: + case 0xFF20: + it->ox = 200; + it->oy = 32; + curox = 200; + curoy = 32; + break; + case 0xF4FF: + it->ox = 32; + it->oy = 200; + curox = 32; + curoy = 200; + break; + case 0xFF2F: + case 0xF42F: + it->ox = 32; + it->oy = 32; + curox = 32; + curoy = 32; + break; + case 0x6FFF: + case 0x64FF: + it->ox = 32; + it->oy = 200; + curox = 32; + curoy = 200; + break; + case 0x6FF0: + it->ox = 200; + it->oy = 200; + curox = 200; + curoy = 200; + break; + default: +#if 0 +#if _DEBUG + printf("hmm tileDir %X at %i, %i, %i\n", + (unsigned int)tileDir(it->tileX(), it->tileY(), + it->tileZ()), it->tileX(), it->tileY(), it->tileZ()); + printf("tileAt %i\n", + (unsigned int)g_App.maps().map(map())->tileAt( + it->tileX(), it->tileY(), it->tileZ())); +#endif +#endif + it->ox = curox; + it->oy = curoy; + break; + } + it->tz = pos_.tz; + } + } + if((!path2add.empty()) && (!dest_path_.empty())) { + for (std::vector < TilePoint >::reverse_iterator it = path2add.rbegin(); + it != path2add.rend(); it++) + { + it->tz = pos_.tz; + dest_path_.push_front(*it); + } + } +} + +/*! + * Moves a vehicle on the map. + * \param elapsed Elapsed time sine last frame. + */ +bool VehicleInstance::move_vehicle(int elapsed) +{ + bool updated = false; + int used_time = elapsed; + + while ((!dest_path_.empty()) && used_time != 0) { + if (hold_on_.wayFree == 1) { // Must wait + return updated; + } else if (hold_on_.wayFree == 2){ + // Must stop : clear destination and stop + clearDestination(); + return updated; + } + + // Get distance between car and next NodePath + int adx = + dest_path_.front().tx * 256 + dest_path_.front().ox; + int ady = + dest_path_.front().ty * 256 + dest_path_.front().oy; + int atx = pos_.tx * 256 + pos_.ox; + int aty = pos_.ty * 256 + pos_.oy; + int diffx = adx - atx, diffy = ady - aty; + + if (abs(diffx) < 16 && abs(diffy) < 16) { + // We reached the next point : remove it from path + pos_.oy = dest_path_.front().oy; + pos_.ox = dest_path_.front().ox; + pos_.ty = dest_path_.front().ty; + pos_.tx = dest_path_.front().tx; + dest_path_.pop_front(); + // There's no following point so stop moving + if (dest_path_.size() == 0) + speed_ = 0; + updated = true; + } else { + setDirection(diffx, diffy, &dir_); + int dx = 0, dy = 0; + double d = sqrt((double)(diffx * diffx + diffy * diffy)); + // This is the time for all the remaining distance to the node + double avail_time_use = (d / (double)speed_) * 1000.0; + // correcting time available regarding the time we have + if (avail_time_use > used_time) + avail_time_use = used_time; + + // computes distance travelled by vehicle in the available time + if (abs(diffx) > 0) + // dx = diffx * (speed_ * used_time / 1000) / d; + dx = (int)((diffx * (speed_ * avail_time_use) / d) / 1000); + if (abs(diffy) > 0) + // dy = diffy * (speed_ * used_time / 1000) / d; + dy = (int)((diffy * (speed_ * avail_time_use) / d) / 1000); + + // Updates the available time + if (dx || dy) { + int prv_time = used_time; + if (dx) { + used_time -= (int)(((double) dx * 1000.0 * d) + / (double)(diffx * speed_)); + } else if (dy) { + used_time -= (int)(((double) dy * 1000.0 * d) + / (double)(diffy * speed_)); + } else + used_time = 0; + if (used_time < 0 || prv_time == used_time) + used_time = 0; + } else + used_time = 0; + + // Moves vehicle + updatePlacement(pos_.ox + dx, pos_.oy + dy); +#if 0 + if (updatePlacement(pos_.ox + dx, pos_.oy + dy)) { + ; + } else { + // TODO: avoid obstacles. + speed_ = 0; + } +#endif + if(dest_path_.front().tx == pos_.tx + && dest_path_.front().ty == pos_.ty + && dest_path_.front().ox == pos_.ox + && dest_path_.front().oy == pos_.oy) + dest_path_.pop_front(); + if (dest_path_.size() == 0) + speed_ = 0; + + updated = true; + } + } + + if (dest_path_.empty() && speed_) { + printf("Destination Unknown, full speed driving = %i ... doing full stop\n", + speed_); + speed_ = 0; + } + if (!passengers_.empty()) { + for (std::set<PedInstance *>::iterator it = passengers_.begin(); + it != passengers_.end(); it++ + ) { + (*it)->setPosition(pos_); + } + } + + return updated; +} + + +/*! + * Method called when object is hit by a weapon shot. + * \param d Damage description + */ +void VehicleInstance::handleHit(ShootableMapObject::DamageInflictType &d) { + if (health_ <= 0) + return; + + decreaseHealth(d.dvalue); + if (health_ == 0) { + clearDestination(); + switch ((unsigned int)d.dtype) { + case MapObject::dmg_Bullet: + case MapObject::dmg_Laser: + case MapObject::dmg_Burn: + case MapObject::dmg_Explosion: + vehicle_->set_animation_type(VehicleAnimation::kOnFireAnim); + setTimeShowAnim(10000); + break; + } + pDriver_ = NULL; + while (passengers_.size() != 0) + { + PedInstance *p = *(passengers_.begin()); + dropPassenger(p); + } + + Explosion::createExplosion(g_Session.getMission(), this, 512.0); + } else {// NOTE: maybe reduce speed on hit? + // TODO: let passengers know that vehicle is attacked + } +} + +/*! + * Adds the given ped to the passenger but if the vehicle + * has no driver, ped becomes the driver. + * \param p The ped + */ +void VehicleInstance::addPassenger(PedInstance *p) { + Vehicle::addPassenger(p); + if (pDriver_ == NULL) { + // Ped becomes the driver + pDriver_ = p; + } +} + +/*! + * Overload initial method to manage driver. + * \param pPed The ped to remove. + */ +void VehicleInstance::dropPassenger(PedInstance *pPed) { + Vehicle::dropPassenger(pPed); + if (pDriver_ == pPed) { + pDriver_ = NULL; + clearDestination(); + + // find another driver in the remaining passengers + for (std::set<PedInstance *>::iterator it = passengers_.begin(); + it != passengers_.end(); it++) { + // take the first one + pDriver_ = *it; + break; + } + } +} + +/** + * Set this ped as the driver of the vehicle and add him as a passenger + * if he's not already in the vehicle. + * \param pPed PedInstance* + * \param forceDriver bool if true, set the driver even if there is already + * another driver + * \return void + * + */ +void VehicleInstance::setDriver(PedInstance *pPed, bool forceDriver) { + if (pPed != NULL) { + if (pDriver_ == NULL || forceDriver) { + pDriver_ = pPed; + } + + if (!containsPed(pPed)) { + Vehicle::addPassenger(pPed); + } + } +} Copied: freesynd/trunk/src/model/vehicle.h (from rev 1004, freesynd/trunk/src/vehicle.h) =================================================================== --- freesynd/trunk/src/model/vehicle.h (rev 0) +++ freesynd/trunk/src/model/vehicle.h 2016-06-01 22:27:06 UTC (rev 1005) @@ -0,0 +1,179 @@ +/************************************************************************ + * * + * FreeSynd - a remake of the classic Bullfrog game "Syndicate". * + * * + * Copyright (C) 2005 Stuart Binge <sk...@gm...> * + * Copyright (C) 2005 Joost Peters <jo...@us...> * + * Copyright (C) 2006 Trent Waddington <qg...@bi...> * + * Copyright (C) 2006 Tarjei Knapstad <tar...@gm...> * + * Copyright (C) 2010 Bohdan Stelmakh <ch...@us...> * + * Copyright (C) 2013 Benoit Blancard <be...@us...>* + * * + * This program is free software; you can redistribute it and / or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You can view the GNU General Public License, online, at the GNU * + * project's web site; see <http://www.gnu.org/licenses/gpl.html>. * + * The full text of the license is also included in the file COPYING. * + * * + ************************************************************************/ + +#ifndef VEHICLE_H +#define VEHICLE_H + +#include <string> + +#include "mapobject.h" +#include "ped.h" +#include "map.h" + +/*! + * This class holds informations about the animation of a vehicle. + */ +class VehicleAnimation { +public: + /*! + * This enumeration lists the type of animations. + */ + enum AnimationType { + //! Vehicule under normal condition + kNormalAnim, + //! Burning vehicle + kOnFireAnim, + //! Burnt vehicle + kBurntAnim, + } ; + + VehicleAnimation(); + virtual ~VehicleAnimation() {} + + //! Draw the vehicle + void draw(int x, int y, int dir, int frame); + + void set_base_anims(int anims); + //void setAnimsBurning(int anims) { anims_burning_ = anims; } + //void setAnimsBurnt(int anims) { anims_burnt_ = anims; } + //! Sets the current animation for the vehicle + void set_animation_type(AnimationType anim) { + vehicle_anim_ = anim; + } + //! Returns the current vehicle animation + AnimationType animation_type() { + return vehicle_anim_; + } +protected: + int anims_, anims_burning_, anims_burnt_; + //! Current type of animation + AnimationType vehicle_anim_; +}; + +/*! + * Generic class for all transports. + * Transport can be driven or not. + */ +class Vehicle : public ShootableMovableMapObject{ +public: + static const uint8 kVehicleTypeLargeArmored; + static const uint8 kVehicleTypeLargeArmoredDamaged; + static const uint8 kVehicleTypeTrainHead; + static const uint8 kVehicleTypeTrainBody; + static const uint8 kVehicleTypeRegularCar; + static const uint8 kVehicleTypeFireFighter; + static const uint8 kVehicleTypeSmallArmored; + static const uint8 kVehicleTypePolice; + static const uint8 kVehicleTypeMedics; + + Vehicle(uint16 anId, uint8 aType, int m) : ShootableMovableMapObject(anId, m, MapObject::kNatureVehicle) { + type_ = aType; + } + + //! Return true if vehicle is a car + bool isCar() { return type_ != kVehicleTypeTrainHead && type_ != kVehicleTypeTrainBody; } + + //void setType(uint8 type) { type_ = type; } + + //! Adds the given ped to the list of passengers + virtual void addPassenger(PedInstance *p); + //! Removes the passenger from the vehicle + virtual void dropPassenger(PedInstance *p); + + //! Returns true if given ped is in the vehicle + bool containsPed(PedInstance *p) { + return (passengers_.find(p) != passengers_.end()); + } + //! Returns true if the vehicle contains one of our agent + bool containsOurAgents(); + //! Returns true if the vehicle contains peds considered hostile by the given ped + bool containsHostilesForPed(PedInstance *p, unsigned int hostile_desc_alt); +protected: + /*! The passengers of the vehicle.*/ + std::set <PedInstance *> passengers_; + +private: + /*! Type of vehicle.*/ + uint8 type_; +}; + +/*! + * This class represents a Vehicle on a map. + */ +class VehicleInstance : public Vehicle +{ +public: + VehicleInstance(VehicleAnimation *vehicle, uint16 id, uint8 aType, int m); + virtual ~VehicleInstance() { delete vehicle_;} + + bool animate(int elapsed); + void draw(int x, int y); + + //! Set the destination to reach at given speed (todo : replace setDestinationV()) + bool setDestination(Mission *m, const TilePoint &locT, int newSpeed = -1); + + void addDestinationV(int x, int y, int z, int ox = 128, int oy = 128, + int new_speed = 160) { + dest_path_.push_back(TilePoint(x, y, z, ox, oy)); + speed_ = new_speed; + } + + void setDestinationV(int x, int y, int z, int ox = 128, int oy = 128, int new_speed = 160); + + //! Adds the given ped to the list of passengers + void addPassenger(PedInstance *p); + //! Removes the passenger from the vehicle + void dropPassenger(PedInstance *p); + + PedInstance *getDriver(void) { + return pDriver_; + } + //! Set this ped as the new driver + void setDriver(PedInstance *pPed, bool forceDriver = true); + + /*! + * Return true given ped is the driver of this vehicle. + * \param pPed a Ped. + */ + bool isDriver(PedInstance *pPed) { + return (pPed != NULL && pDriver_ == pPed); + } + + void handleHit(ShootableMapObject::DamageInflictType &d); + +protected: + bool move_vehicle(int elapsed); + uint16 tileDir(int x, int y, int z); + bool dirWalkable(TilePoint *p, int x, int y, int z); + +protected: + VehicleAnimation *vehicle_; + //! Vehicle driver + PedInstance *pDriver_; +}; + +#endif Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2016-05-03 20:11:20 UTC (rev 1004) +++ freesynd/trunk/src/ped.cpp 2016-06-01 22:27:06 UTC (rev 1005) @@ -28,7 +28,7 @@ #include "common.h" #include "app.h" #include "utils/log.h" -#include "vehicle.h" +#include "model/vehicle.h" #include "mission.h" #include "core/squad.h" #include "core/gamesession.h" Modified: freesynd/trunk/src/pedmanager.cpp =... [truncated message content] |
From: <be...@us...> - 2016-05-03 20:11:23
|
Revision: 1004 http://sourceforge.net/p/freesynd/code/1004 Author: benblan Date: 2016-05-03 20:11:20 +0000 (Tue, 03 May 2016) Log Message: ----------- - PedInstance::inVehicle() now returns Vehicle - Removed state constants pa_smGetInCar and pa_smUsingCar Modified Paths: -------------- freesynd/trunk/CMakeLists.txt freesynd/trunk/src/menus/squadselection.cpp freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/vehicle.cpp Modified: freesynd/trunk/CMakeLists.txt =================================================================== --- freesynd/trunk/CMakeLists.txt 2016-05-03 17:58:46 UTC (rev 1003) +++ freesynd/trunk/CMakeLists.txt 2016-05-03 20:11:20 UTC (rev 1004) @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 2.6) project (FreeSynd) -set (FREESYND_VERSION "0.7.5") +set (FREESYND_VERSION "0.8") if (WIN32) # Search the bundled libs directory when using MSVC. @@ -11,7 +11,7 @@ ${CMAKE_SOURCE_DIR}/../libs/MSVC/include ) endif () - + if (MSVC) # Add extra definitions just for MSVC. add_definitions (-D_CONSOLE -D_CRT_SECURE_NO_WARNINGS) @@ -26,9 +26,9 @@ else () set (EXTRA_C_FLAGS "-Wall -Wshadow -Wno-multichar") endif () - + set (EXTRA_CXX_FLAGS "${EXTRA_C_FLAGS} -Wreorder -Wnon-virtual-dtor") - + # Set debug flag. set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") Modified: freesynd/trunk/src/menus/squadselection.cpp =================================================================== --- freesynd/trunk/src/menus/squadselection.cpp 2016-05-03 17:58:46 UTC (rev 1003) +++ freesynd/trunk/src/menus/squadselection.cpp 2016-05-03 20:11:20 UTC (rev 1004) @@ -289,11 +289,12 @@ for (SquadSelection::Iterator it = begin(); it != end(); ++it, i++) { PedInstance *pAgent = *it; - if (pAgent->inVehicle()) { - if (pAgent->inVehicle()->isDrivable()) { + Vehicle *pVehicle = pAgent->inVehicle(); + if (pVehicle) { + if (pVehicle->isDrivable()) { // Agent is in drivable vehicle - VehicleInstance *pVehicle = pAgent->inVehicle(); - if (pVehicle->isDriver(pAgent)) + VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(pVehicle); + if (pCar->isDriver(pAgent)) { int stx = mapPt.tx; int sty = mapPt.ty; @@ -306,7 +307,7 @@ //soy = sty % 256; sty = sty / 256; TilePoint posT = TilePoint(stx, sty, 0, 128, 128); - pAgent->addActionDriveVehicle(pVehicle, posT, addAction); + pAgent->addActionDriveVehicle(pCar, posT, addAction); } } } else { Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2016-05-03 17:58:46 UTC (rev 1003) +++ freesynd/trunk/src/ped.cpp 2016-05-03 20:11:20 UTC (rev 1004) @@ -212,12 +212,12 @@ break; case pa_smStanding: state_ &= (pa_smAll ^(pa_smFollowing - | pa_smUsingCar | pa_smInCar)); + | pa_smInCar)); state_ |= pa_smStanding; break; case pa_smWalking: state_ &= (pa_smAll ^(pa_smFollowing - | pa_smUsingCar | pa_smInCar)); + | pa_smInCar)); state_ |= pa_smWalking; break; case pa_smWalkingBurning: @@ -248,12 +248,6 @@ case pa_smBurning: state_ = pa_smBurning; break; - case pa_smGetInCar: - state_ = pa_smStanding | pa_smGetInCar; - break; - case pa_smUsingCar: - state_ = pa_smStanding | pa_smUsingCar; - break; case pa_smInCar: state_ = pa_smStanding | pa_smInCar; break; @@ -307,12 +301,6 @@ case pa_smWalkingBurning: state_ = pa_smStanding; break; - case pa_smGetInCar: - state_ &= pa_smAll ^ (pa_smStanding | pa_smGetInCar); - break; - case pa_smUsingCar: - state_ &= pa_smAll ^ (pa_smStanding | pa_smUsingCar); - break; case pa_smInCar: state_ &= pa_smAll ^ (pa_smStanding | pa_smInCar); break; @@ -354,7 +342,7 @@ setDrawnAnim(PedInstance::ad_PickupAnim); } else if ((state_ & pa_smPutDown) != 0) { setDrawnAnim(PedInstance::ad_PutdownAnim); - } else if ((state_ & (pa_smUsingCar | pa_smInCar)) != 0) { + } else if ((state_ & pa_smInCar) != 0) { setDrawnAnim(PedInstance::ad_StandAnim); } else if ((state_ & pa_smHit) != 0) { setDrawnAnim(PedInstance::ad_HitAnim); @@ -1005,18 +993,15 @@ return (state_ & pa_smPickUp) != 0; } -VehicleInstance *PedInstance::inVehicle() const -{ - return (state_ & (PedInstance::pa_smInCar - | PedInstance::pa_smUsingCar)) != 0 ? in_vehicle_ : NULL; +Vehicle *PedInstance::inVehicle() const { + return in_vehicle_; } -void PedInstance::putInVehicle(VehicleInstance * v, - pedActionStateMasks add_state) +void PedInstance::putInVehicle(Vehicle * pVehicle) { map_ = -1; - in_vehicle_ = v; - switchActionStateTo((uint32)add_state); + in_vehicle_ = pVehicle; + switchActionStateTo(PedInstance::pa_smInCar); } void PedInstance::leaveVehicle() { @@ -1024,8 +1009,7 @@ map_ = in_vehicle_->map(); setPosition(in_vehicle_->position()); in_vehicle_ = NULL; - switchActionStateFrom(state_ & (PedInstance::pa_smInCar - | PedInstance::pa_smUsingCar)); + switchActionStateFrom(state_ & PedInstance::pa_smInCar); } int PedInstance::map() { Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2016-05-03 17:58:46 UTC (rev 1003) +++ freesynd/trunk/src/ped.h 2016-05-03 20:11:20 UTC (rev 1004) @@ -254,10 +254,6 @@ pa_smPickUp = 0x0020, pa_smPutDown = 0x0040, pa_smBurning = 0x0080, - pa_smGetInCar = 0x0100, - // only driver can have this set after finished - pa_smUsingCar = 0x0200, - // passenger only pa_smInCar = 0x0400, pa_smHitByPersuadotron = 0x0800, pa_smDead = 0x1000, @@ -411,9 +407,9 @@ void setNewOwner(PedInstance *pPed); bool inSightRange(MapObject *t); - VehicleInstance * inVehicle() const; + Vehicle * inVehicle() const; - void putInVehicle(VehicleInstance *v, pedActionStateMasks add_state); + void putInVehicle(Vehicle *v); void leaveVehicle(); int map(); @@ -717,7 +713,7 @@ uint32 obj_group_id_; uint32 old_obj_group_id_; - //! time wait before checking enviroment (enemies, friends etc) + //! time wait before checking environment (enemies, friends etc) int32 tm_before_check_; //! base value that influences accuracy during fire @@ -726,7 +722,7 @@ AnimationDrawn drawn_anim_; int sight_range_; - VehicleInstance *in_vehicle_; + Vehicle *in_vehicle_; //! This flag tells if this is our agent, assuming it's an agent. bool is_our_; //! controller of ped - for persuaded Modified: freesynd/trunk/src/vehicle.cpp =================================================================== --- freesynd/trunk/src/vehicle.cpp 2016-05-03 17:58:46 UTC (rev 1003) +++ freesynd/trunk/src/vehicle.cpp 2016-05-03 20:11:20 UTC (rev 1004) @@ -69,6 +69,7 @@ void Vehicle::addPassenger(PedInstance *pPed) { if(!isInsideVehicle(pPed)) { passengers_.insert(pPed); + pPed->putInVehicle(this); } } @@ -801,8 +802,6 @@ */ void VehicleInstance::addPassenger(PedInstance *p) { Vehicle::addPassenger(p); - // TODO : move putInVehicle() in Vehicle::addPassenger() - p->putInVehicle(this, PedInstance::pa_smInCar); if (pDriver_ == NULL) { // Ped becomes the driver pDriver_ = p; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-05-03 17:58:48
|
Revision: 1003 http://sourceforge.net/p/freesynd/code/1003 Author: benblan Date: 2016-05-03 17:58:46 +0000 (Tue, 03 May 2016) Log Message: ----------- code refactoring Modified Paths: -------------- freesynd/trunk/AUTHORS freesynd/trunk/NEWS freesynd/trunk/README freesynd/trunk/src/freesynd.cpp freesynd/trunk/src/map.cpp freesynd/trunk/src/map.h freesynd/trunk/src/mapobject.h freesynd/trunk/src/menus/gameplaymenu.cpp freesynd/trunk/src/missionmanager.cpp freesynd/trunk/src/ped.cpp freesynd/trunk/src/ped.h freesynd/trunk/src/vehicle.cpp freesynd/trunk/src/vehicle.h Modified: freesynd/trunk/AUTHORS =================================================================== --- freesynd/trunk/AUTHORS 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/AUTHORS 2016-05-03 17:58:46 UTC (rev 1003) @@ -2,7 +2,6 @@ (listed in alphabetical order) current: * Benoit Blancard (Developer): <be...@us...> -* Bohdan Stelmak(Developer): <ch...@us...> in past: * Stuart Binge (Developer) : <sk...@us...> @@ -14,6 +13,7 @@ * Bruce Sutherland <bru...@us...> * Unavowed <una...@us...> * Trent Waddington (Developer): <qua...@us...> +* Bohdan Stelmak(Developer): <ch...@us...> Contributors * Tomas Jakobsson - good advices Modified: freesynd/trunk/NEWS =================================================================== --- freesynd/trunk/NEWS 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/NEWS 2016-05-03 17:58:46 UTC (rev 1003) @@ -1,4 +1,4 @@ -FreeSynd 0.7.5 : Release Notes +FreeSynd 0.8 : Release Notes ---------------------------- Description @@ -11,14 +11,11 @@ Fixed Bugs ---------- - * When player changes its color, if an enemy syndicate already had that - color, change the enemy color. + * Features added ---------- - * Mission ownership on map menu changes to simulate syndicate fighting for terrotories. - * Animation for animated windows - * Agent's life is now restored automatically if he wears an upgraded chest + * Known issues with this release ------------------------------ @@ -29,9 +26,16 @@ History ------- + v0.7.5 + ------ + * When player changes its color, if an enemy syndicate already had that + color, change the enemy color. + * Mission ownership on map menu changes to simulate syndicate fighting for terrotories. + * Animation for animated windows + * Agent's life is now restored automatically if he wears an upgraded chest v0.7.1 - ---- + ------ * Code refactoring * All tabs coverted to spaces * Better animation for impact or detonating explosions Modified: freesynd/trunk/README =================================================================== --- freesynd/trunk/README 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/README 2016-05-03 17:58:46 UTC (rev 1003) @@ -1,4 +1,4 @@ -FreeSynd 0.7.5 +FreeSynd 0.8 ------------ FreeSynd is a free, cross-platform reimplementation of engine for the classic Bullfrog game "Syndicate". For more information see: Modified: freesynd/trunk/src/freesynd.cpp =================================================================== --- freesynd/trunk/src/freesynd.cpp 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/freesynd.cpp 2016-05-03 17:58:46 UTC (rev 1003) @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) { - printf("Freesynd v0.7.5 (may 2016)\n"); + printf("Freesynd v0.8 (may 2016)\n"); #ifdef CHEAP_LEAK_DETECTION initLeakDetection(); @@ -171,7 +171,7 @@ #ifdef _DEBUG // This parameter is used in debug phase to accelerate the starting // of a game and to jump directly to a mission - // Note : the argument is the index of the block in the structure g_MissionNumbers + // Note : the argument is the index of the block in the structure g_MissionNumbers // as defined in briefmenu.cpp and not the mission number itself. if (0 == strcmp("-m", argv[i]) || 0 == strcmp("--mission", argv[i])) { int mission = atoi(argv[i + 1]); Modified: freesynd/trunk/src/map.cpp =================================================================== --- freesynd/trunk/src/map.cpp 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/map.cpp 2016-05-03 17:58:46 UTC (rev 1003) @@ -222,6 +222,59 @@ a_tiles_[(y * max_x_ + x) * max_z_ + z] = tile_manager_->getTile(tileNum); } + +/** + * Return true if tile at given position is traversable by a car. + * \param x int X coordinate + * \param y int Y coordinate + * \param z int Z coordinate + * \return bool + * + */ +bool Map::isTileWalkableByCar(int x, int y, int z) +{ + Tile *pTile = getTileAt(x, y, z); + uint8 tileId = pTile->id(); + + if(tileId == 80) { + Tile::EType near_type = getTileAt(x, y - 1, z)->type(); + if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) + && near_type != Tile::kRoadPedCross) { + return false; + } + near_type = getTileAt(x, y + 1, z)->type(); + if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) + && near_type != Tile::kRoadPedCross) + { + return false; + } + return true; + } + if(tileId == 81) { + Tile::EType near_type = getTileAt(x - 1, y, z)->type(); + if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) + && near_type != Tile::kRoadPedCross) + { + return false; + } + near_type = getTileAt(x + 1, y, z)->type(); + if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) + && near_type != Tile::kRoadPedCross) + { + return false; + } + return true; + } + if(tileId == 72) { + return false; + } + + if(tileId == 119) { + return false; + } + return pTile->isRoad(); +} + const uint8 MiniMap::kOverlayNone = 0; const uint8 MiniMap::kOverlayOurAgent = 1; const uint8 MiniMap::kOverlayEnemyAgent = 2; Modified: freesynd/trunk/src/map.h =================================================================== --- freesynd/trunk/src/map.h 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/map.h 2016-05-03 17:58:46 UTC (rev 1003) @@ -66,6 +66,8 @@ Tile * getTileAt(int x, int y, int z); int tileAt(int x, int y, int z); void patchMap(int x, int y, int z, uint8 tileNum); + //! Return true if tile at given position is traversable by car + bool isTileWalkableByCar(int x, int y, int z); protected: /*! Every map has a unique ID which is used to identify the Modified: freesynd/trunk/src/mapobject.h =================================================================== --- freesynd/trunk/src/mapobject.h 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/mapobject.h 2016-05-03 17:58:46 UTC (rev 1003) @@ -511,8 +511,6 @@ std::list<TilePoint> dest_path_; bool updatePlacement(int nOffX, int nOffY); - - virtual bool walkable(int x, int y, int z) = 0; }; /*! Modified: freesynd/trunk/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/trunk/src/menus/gameplaymenu.cpp 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/menus/gameplaymenu.cpp 2016-05-03 17:58:46 UTC (rev 1003) @@ -776,6 +776,9 @@ printf(" > target(%i) : %s\n", target_->id(), target_->natureName()); } + + int tileid = mission_->get_map()->tileAt(mapPt.tx, mapPt.ty, mapPt.tz); + printf("Tile id %d\n", tileid); return; } #endif //_DEBUG Modified: freesynd/trunk/src/missionmanager.cpp =================================================================== --- freesynd/trunk/src/missionmanager.cpp 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/missionmanager.cpp 2016-05-03 17:58:46 UTC (rev 1003) @@ -636,7 +636,7 @@ pVehicle->addPassenger(p); if (setDriver) { VehicleInstance *pCar = dynamic_cast<VehicleInstance *>(pVehicle); - pCar->forceSetDriver(p); + pCar->setDriver(p); } } Modified: freesynd/trunk/src/ped.cpp =================================================================== --- freesynd/trunk/src/ped.cpp 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/ped.cpp 2016-05-03 17:58:46 UTC (rev 1003) @@ -1022,6 +1022,7 @@ void PedInstance::leaveVehicle() { assert(map_ == -1 && in_vehicle_); map_ = in_vehicle_->map(); + setPosition(in_vehicle_->position()); in_vehicle_ = NULL; switchActionStateFrom(state_ & (PedInstance::pa_smInCar | PedInstance::pa_smUsingCar)); Modified: freesynd/trunk/src/ped.h =================================================================== --- freesynd/trunk/src/ped.h 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/ped.h 2016-05-03 17:58:46 UTC (rev 1003) @@ -738,8 +738,6 @@ //! Tells whether the panic can react to panic or not bool panicImmuned_; - bool walkable(int x, int y, int z) { return true; } - private: inline int getClosestDirs(int dir, int& closest, int& closer); }; Modified: freesynd/trunk/src/vehicle.cpp =================================================================== --- freesynd/trunk/src/vehicle.cpp 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/vehicle.cpp 2016-05-03 17:58:46 UTC (rev 1003) @@ -60,8 +60,16 @@ anims_burnt_ = anims + 12; } -void Vehicle::addPassenger(PedInstance *p) { - passengers_.insert(p); +/** + * Adds given ped to the list of passengers. + * \param pPed PedInstance* + * \return void + * + */ +void Vehicle::addPassenger(PedInstance *pPed) { + if(!isInsideVehicle(pPed)) { + passengers_.insert(pPed); + } } /*! @@ -72,7 +80,6 @@ if(isInsideVehicle(pPed)) { pPed->leaveVehicle(); passengers_.erase(passengers_.find(pPed)); - pPed->setPosition(pos_); } } @@ -109,8 +116,9 @@ } VehicleInstance::VehicleInstance(VehicleAnimation * vehicle, uint16 anId, int m): - Vehicle(anId, m, true), vehicle_(vehicle), vehicle_driver_(NULL) + Vehicle(anId, m, true), vehicle_(vehicle) { + pDriver_ = NULL; hold_on_.wayFree = 0; } @@ -147,51 +155,6 @@ vehicle_->draw(x, y, getDirection(4), frame_); } -bool VehicleInstance::walkable(int x, int y, int z) -{ - Map *pMap = g_App.maps().map(map()); - Tile *p_this_tile = pMap->getTileAt(x, y, z); - uint8 this_tile_id = p_this_tile->id(); - - if(this_tile_id == 80) { - Tile::EType near_type = pMap->getTileAt(x, y - 1, z)->type(); - if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) - && near_type != Tile::kRoadPedCross) { - return false; - } - near_type = pMap->getTileAt(x, y + 1, z)->type(); - if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) - && near_type != Tile::kRoadPedCross) - { - return false; - } - return true; - } - if(this_tile_id == 81) { - Tile::EType near_type = pMap->getTileAt(x - 1, y, z)->type(); - if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) - && near_type != Tile::kRoadPedCross) - { - return false; - } - near_type = pMap->getTileAt(x + 1, y, z)->type(); - if((near_type < Tile::kRoadSideEW || near_type > Tile::kRoadSideNS) - && near_type != Tile::kRoadPedCross) - { - return false; - } - return true; - } - if(this_tile_id == 72) { - return false; - } - - if(this_tile_id == 119) { - return false; - } - return p_this_tile->isRoad(); -} - uint16 VehicleInstance::tileDir(int x, int y, int z) { uint16 dir = 0x0; int near_tile; @@ -358,8 +321,8 @@ } bool VehicleInstance::dirWalkable(TilePoint *p, int x, int y, int z) { - - if(!(walkable(x,y,z))) + Map *pMap = g_App.maps().map(map()); + if(!(pMap->isTileWalkableByCar(x,y,z))) return false; uint16 dirStart = tileDir(p->tx,p->ty,p->tz); @@ -419,7 +382,7 @@ dest_path_.clear(); setSpeed(0); - if (map_ == -1 || health_ <= 0 || !(walkable(x, y, z))) { + if (map_ == -1 || health_ <= 0 || !(pMap->isTileWalkableByCar(x, y, z))) { #if 0 #if _DEBUG if (!(map_ == -1 || health_ <= 0)) { @@ -433,7 +396,7 @@ return; } - if (!walkable(pos_.tx, pos_.ty, z)) { + if (!pMap->isTileWalkableByCar(pos_.tx, pos_.ty, z)) { int dBest = 100000, dCur; std::vector < TilePoint > path2wtile; path2wtile.reserve(16); @@ -444,7 +407,7 @@ break; pntile.tx = pos_.tx + i; path2wtile.push_back(pntile); - if (walkable(pos_.tx + i, pos_.ty, z)) { + if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, z)) { dCur = i * i; if(dCur < dBest) { dBest = dCur; @@ -463,7 +426,7 @@ break; pntile.tx = (pos_.tx + i); path2wtile.push_back(pntile); - if (walkable(pos_.tx + i, pos_.ty, z)) { + if (pMap->isTileWalkableByCar(pos_.tx + i, pos_.ty, z)) { dCur = i * i; if(dCur < dBest) { dBest = dCur; @@ -482,7 +445,7 @@ break; pntile.ty = (pos_.ty + i); path2wtile.push_back(pntile); - if (walkable(pos_.tx, pos_.ty + i, z)) { + if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, z)) { dCur = i * i; if(dCur < dBest) { dBest = dCur; @@ -501,7 +464,7 @@ break; pntile.ty = pos_.ty + i; path2wtile.push_back(pntile); - if (walkable(pos_.tx, pos_.ty + i, z)) { + if (pMap->isTileWalkableByCar(pos_.tx, pos_.ty + i, z)) { dCur = i * i; if(dCur < dBest) { dBest = dCur; @@ -818,7 +781,7 @@ setTimeShowAnim(10000); break; } - vehicle_driver_ = NULL; + pDriver_ = NULL; while (passengers_.size() != 0) { PedInstance *p = *(passengers_.begin()); @@ -838,13 +801,11 @@ */ void VehicleInstance::addPassenger(PedInstance *p) { Vehicle::addPassenger(p); - if (hasDriver()) { - // There's already a driver - p->putInVehicle(this, PedInstance::pa_smInCar); - } else { + // TODO : move putInVehicle() in Vehicle::addPassenger() + p->putInVehicle(this, PedInstance::pa_smInCar); + if (pDriver_ == NULL) { // Ped becomes the driver - vehicle_driver_ = p; - p->putInVehicle(this, PedInstance::pa_smUsingCar); + pDriver_ = p; } } @@ -854,23 +815,37 @@ */ void VehicleInstance::dropPassenger(PedInstance *pPed) { Vehicle::dropPassenger(pPed); - if (vehicle_driver_ == pPed) { - vehicle_driver_ = NULL; + if (pDriver_ == pPed) { + pDriver_ = NULL; clearDestination(); // find another driver in the remaining passengers for (std::set<PedInstance *>::iterator it = passengers_.begin(); it != passengers_.end(); it++) { // take the first one - vehicle_driver_ = *it; + pDriver_ = *it; break; } } } -void VehicleInstance::forceSetDriver(PedInstance *vehicleDriver) { - vehicle_driver_ = vehicleDriver; - if (!isInsideVehicle(vehicleDriver)) { - Vehicle::addPassenger(vehicleDriver); +/** + * Set this ped as the driver of the vehicle and add him as a passenger + * if he's not already in the vehicle. + * \param pPed PedInstance* + * \param forceDriver bool if true, set the driver even if there is already + * another driver + * \return void + * + */ +void VehicleInstance::setDriver(PedInstance *pPed, bool forceDriver) { + if (pPed != NULL) { + if (pDriver_ == NULL || forceDriver) { + pDriver_ = pPed; + } + + if (!isInsideVehicle(pPed)) { + Vehicle::addPassenger(pPed); + } } } Modified: freesynd/trunk/src/vehicle.h =================================================================== --- freesynd/trunk/src/vehicle.h 2016-05-02 20:49:22 UTC (rev 1002) +++ freesynd/trunk/src/vehicle.h 2016-05-03 17:58:46 UTC (rev 1003) @@ -142,32 +142,30 @@ void dropPassenger(PedInstance *p); PedInstance *getDriver(void) { - return vehicle_driver_; + return pDriver_; } - void setDriver(PedInstance *vehicleDriver) { - if (vehicle_driver_ == NULL) - vehicle_driver_ = vehicleDriver; - passengers_.insert(vehicleDriver); + //! Set this ped as the new driver + void setDriver(PedInstance *pPed, bool forceDriver = true); + + /*! + * Return true given ped is the driver of this vehicle. + * \param pPed a Ped. + */ + bool isDriver(PedInstance *pPed) { + return (pPed != NULL && pDriver_ == pPed); } - void forceSetDriver(PedInstance *vehicleDriver); - bool hasDriver() { return (vehicle_driver_ != NULL); } - bool isDriver(PedInstance *vehicleDriver) { - if (vehicle_driver_ == NULL) - return false; - return (vehicle_driver_ == vehicleDriver); - } void handleHit(ShootableMapObject::DamageInflictType &d); protected: bool move_vehicle(int elapsed); - bool walkable(int x, int y, int z); uint16 tileDir(int x, int y, int z); bool dirWalkable(TilePoint *p, int x, int y, int z); protected: VehicleAnimation *vehicle_; - PedInstance *vehicle_driver_; + //! Vehicle driver + PedInstance *pDriver_; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-05-02 20:49:24
|
Revision: 1002 http://sourceforge.net/p/freesynd/code/1002 Author: benblan Date: 2016-05-02 20:49:22 +0000 (Mon, 02 May 2016) Log Message: ----------- make 0.7.5 tag Added Paths: ----------- freesynd/tags/release-0.7.5/ Index: freesynd/tags/release-0.7.5 =================================================================== --- freesynd/trunk 2016-05-01 20:09:23 UTC (rev 1001) +++ freesynd/tags/release-0.7.5 2016-05-02 20:49:22 UTC (rev 1002) Property changes on: freesynd/tags/release-0.7.5 ___________________________________________________________________ Added: svn:ignore ## -0,0 +1,4 ## +CMakeCache.txt +CMakeFiles +Makefile +cmake_install.cmake Added: svn:mergeinfo ## -0,0 +1,3 ## +/freesynd/branches/cmake:496-499 +/freesynd/branches/rework-actions:937-984 +/freesynd/branches/trunk-r608-feature-3202739:610-615 \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-05-01 20:09:25
|
Revision: 1001 http://sourceforge.net/p/freesynd/code/1001 Author: benblan Date: 2016-05-01 20:09:23 +0000 (Sun, 01 May 2016) Log Message: ----------- Display version information when running the application Modified Paths: -------------- freesynd/trunk/src/freesynd.cpp Modified: freesynd/trunk/src/freesynd.cpp =================================================================== --- freesynd/trunk/src/freesynd.cpp 2016-05-01 13:28:39 UTC (rev 1000) +++ freesynd/trunk/src/freesynd.cpp 2016-05-01 20:09:23 UTC (rev 1001) @@ -144,6 +144,8 @@ int main(int argc, char *argv[]) { + printf("Freesynd v0.7.5 (may 2016)\n"); + #ifdef CHEAP_LEAK_DETECTION initLeakDetection(); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-05-01 13:28:40
|
Revision: 1000 http://sourceforge.net/p/freesynd/code/1000 Author: benblan Date: 2016-05-01 13:28:39 +0000 (Sun, 01 May 2016) Log Message: ----------- Updated Install instruction for Linux Modified Paths: -------------- freesynd/trunk/INSTALL Modified: freesynd/trunk/INSTALL =================================================================== --- freesynd/trunk/INSTALL 2016-04-25 22:01:41 UTC (rev 999) +++ freesynd/trunk/INSTALL 2016-05-01 13:28:39 UTC (rev 1000) @@ -40,26 +40,28 @@ * From binary distribution file ============================= - * Windows - --------- + * Windows + --------- 1/ Download and unzip the file in any directory you want. - 2/ Install original game data files (see chapter "Original Game Data). - 3/ Optionnaly edit bin/freesynd.ini to indicate where to find original - game data files (see chapter "Configuring FreeSynd") - 4/ Run bin/freesynd.exe. + This directory will be called FS_ROOT in the following text. + 2/ Install original game data files (see chapter "Original Game Data). + 3/ Optionnaly edit FS_ROOT/bin/freesynd.ini to indicate where to find original + game data files (see chapter "Configuring FreeSynd") + 4/ Run FS_ROOT/bin/freesynd.exe. * Mac Installation ------------------ 1/ Unzip the application bundle and drag it to your "Applications" folder. - * Linux Installation + * Linux Installation ------------------ See next chapter : Building from source * Building from packaged source ============================= - All : + * All + ----- 1/ To build Freesynd, you will need to install Cmake (http://www.cmake.org/) or use your distribution's package manager to install it. 2/ Download and unzip file containing source code in any directory you want @@ -104,13 +106,23 @@ ------- Use your distribution's package manager to install all of the libraries listed in the chapter "Required Libraries". - From the main source folder, run: cmake . - Finally, run: make - The freesynd binary will be in the "src" folder. + From FS_ROOT folder, run the following commands: + Run cmake to create Makefiles in release mode : + ./configure --release + + Build the application. The freesynd binary will be in + the "src" folder : + make - type make install - Type "freesynd". + Install the application : + sudo make install + Run the application + freesynd + + Optionnaly edit freesynd.ini to indicate where to find original + game data files (see chapter "Configuring FreeSynd") + * Mac ----- Install CMake from http://www.cmake.org/ . This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-04-25 22:01:44
|
Revision: 999 http://sourceforge.net/p/freesynd/code/999 Author: benblan Date: 2016-04-25 22:01:41 +0000 (Mon, 25 Apr 2016) Log Message: ----------- added informations in the INSTALL file for building from sources Modified Paths: -------------- freesynd/trunk/INSTALL Modified: freesynd/trunk/INSTALL =================================================================== --- freesynd/trunk/INSTALL 2016-04-25 21:00:50 UTC (rev 998) +++ freesynd/trunk/INSTALL 2016-04-25 22:01:41 UTC (rev 999) @@ -44,7 +44,9 @@ --------- 1/ Download and unzip the file in any directory you want. 2/ Install original game data files (see chapter "Original Game Data). - 3/ Double-click on freesynd.exe. + 3/ Optionnaly edit bin/freesynd.ini to indicate where to find original + game data files (see chapter "Configuring FreeSynd") + 4/ Run bin/freesynd.exe. * Mac Installation ------------------ @@ -61,11 +63,12 @@ 1/ To build Freesynd, you will need to install Cmake (http://www.cmake.org/) or use your distribution's package manager to install it. 2/ Download and unzip file containing source code in any directory you want + This directory will be called FS_ROOT in the following text. * Windows - Visual C++ ---------------------- Run cmake-gui. - Set "Source" to the root folder where you unzipped the file (it should contain a CMakeLists.txt file). + Set "Source" to FS_ROOT/sources. Set "Build" to the folder where your project files should be located. Click "Configure" and select your version of Visual Studio. Click "Finish". @@ -76,13 +79,15 @@ Select "Build | Clean Solution". Select "Build | Build Solution". - To run the application, you need to copy all dll files in the directory of the feesynd.exe file. + To run the application, you need to copy all dll files that are in FS_ROOT/bin + to the directory where the feesynd.exe file has been generated. * Windows - Code::Blocks with MinGW ----------------------------------- Run cmake-gui. - Set "Source" to the root folder where you unzipped the file (it should contain a CMakeLists.txt file). - Set "Build" to the folder where your project files should be located. + Set "Source" to FS_ROOT/sources. + Set "Build" to the folder where your project files should be located + it could be for example FS_ROOT/debug if you use the Debug build configuration. Click "Configure" and select CodeBlocks - MinGW Makefiles. Click "Finish". You can set the CMAKE_BUILD_TYPE variable to "release" or "debug" to enable one of the configuration @@ -92,7 +97,8 @@ Select "Build | Build" The freesynd binary will be in the "src" folder. - To run the application, you need to copy all dll files in the directory of the feesynd.exe file. + To run the application, you need to copy all dll files that are in FS_ROOT/bin + to the directory where the feesynd.exe file has been generated. * Linux ------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2016-04-25 21:00:53
|
Revision: 998 http://sourceforge.net/p/freesynd/code/998 Author: benblan Date: 2016-04-25 21:00:50 +0000 (Mon, 25 Apr 2016) Log Message: ----------- - added info in the INSTALL file - set CMakeLists.txt instructions to be linux specific Modified Paths: -------------- freesynd/trunk/CMakeLists.txt freesynd/trunk/INSTALL freesynd/trunk/src/CMakeLists.txt Modified: freesynd/trunk/CMakeLists.txt =================================================================== --- freesynd/trunk/CMakeLists.txt 2016-04-23 14:52:57 UTC (rev 997) +++ freesynd/trunk/CMakeLists.txt 2016-04-25 21:00:50 UTC (rev 998) @@ -80,7 +80,7 @@ set (BUILD_DEV_TOOLS FALSE) # We only define an install target if we're doing a release build. # Furthermore, on Mac, the data folder is a part of the app bundle. - if (NOT APPLE) + if (UNIX) install (DIRECTORY data DESTINATION ${DATA_DIR} PATTERN .svn EXCLUDE) endif () endif () Modified: freesynd/trunk/INSTALL =================================================================== --- freesynd/trunk/INSTALL 2016-04-23 14:52:57 UTC (rev 997) +++ freesynd/trunk/INSTALL 2016-04-25 21:00:50 UTC (rev 998) @@ -83,10 +83,12 @@ Run cmake-gui. Set "Source" to the root folder where you unzipped the file (it should contain a CMakeLists.txt file). Set "Build" to the folder where your project files should be located. - Click "Configure" and select Code::Blocks-MinGW. + Click "Configure" and select CodeBlocks - MinGW Makefiles. Click "Finish". + You can set the CMAKE_BUILD_TYPE variable to "release" or "debug" to enable one of the configuration + - by default, it's set to "debug". Click "Generate" to generate Code::Blocks project files. - Select "File | Open..." and select "FreeSynd.cbp" in the build folder. + Open CodeBlocks IDE, select "File | Open..." and select "FreeSynd.cbp" in the build folder. Select "Build | Build" The freesynd binary will be in the "src" folder. Modified: freesynd/trunk/src/CMakeLists.txt =================================================================== --- freesynd/trunk/src/CMakeLists.txt 2016-04-23 14:52:57 UTC (rev 997) +++ freesynd/trunk/src/CMakeLists.txt 2016-04-25 21:00:50 UTC (rev 998) @@ -293,7 +293,7 @@ # We only define an install target if we're doing a release build. if (APPLE) install (TARGETS freesynd DESTINATION /Applications) - else () + elseif (UNIX) install (TARGETS freesynd DESTINATION ${BIN_DIR}) endif () endif () This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |