Changed: #1469 TPositionOrEntity becomes an abstract class

--HG--
branch : gsoc2012-fabien
hg/feature/gsoc2012-fabien
Fabien_HENON 12 years ago
parent 9d592fdc63
commit 7ab6ede55c

@ -26,7 +26,7 @@
/************************************************************************/ /************************************************************************/
/* Class that can contain either an entity id or a position */ /* Class that can contain either an entity id or a position */
/************************************************************************/ /************************************************************************/
class TPositionOrEntity class CPositionOrEntity
{ {
public: public:
enum PositionOrEntityType enum PositionOrEntityType
@ -38,29 +38,29 @@ public:
EReturnPos EReturnPos
}; };
TPositionOrEntity() CPositionOrEntity()
{ {
_type = EUnknown; _type = EUnknown;
} }
TPositionOrEntity(const NLMISC::CVector& position) CPositionOrEntity(const NLMISC::CVector& position)
{ {
_type = EPosition; _type = EPosition;
Position = position; Position = position;
} }
TPositionOrEntity(const TDataSetIndex& eid) CPositionOrEntity(const TDataSetIndex& eid)
{ {
_type = EEntity; _type = EEntity;
EntityId = eid; EntityId = eid;
} }
TPositionOrEntity(PositionOrEntityType type) CPositionOrEntity(PositionOrEntityType type)
{ {
_type = type; _type = type;
} }
TPositionOrEntity(const TPositionOrEntity& c) CPositionOrEntity(const CPositionOrEntity& c)
{ {
_type = c._type; _type = c._type;
if (c.isPosition()) if (c.isPosition())
@ -69,7 +69,7 @@ public:
EntityId = c.getEntityId(); EntityId = c.getEntityId();
} }
TPositionOrEntity& operator=(const TPositionOrEntity& c) CPositionOrEntity& operator=(const CPositionOrEntity& c)
{ {
_type = c._type; _type = c._type;
if (c.isPosition()) if (c.isPosition())
@ -80,7 +80,7 @@ public:
return *this; return *this;
} }
bool operator==(const TPositionOrEntity& c) bool operator==(const CPositionOrEntity& c)
{ {
if (_type != c._type) if (_type != c._type)
return false; return false;
@ -140,15 +140,11 @@ public:
return Position; return Position;
} }
NLMISC::CVector getDiffPos() const /// This function returns the difference between the player's position and the specified position
{ virtual NLMISC::CVector getDiffPos(const NLMISC::CVector& targetPos) const = 0;
return Position; // TODO => get the real position of the character
}
NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos) /// This function returns the target position given the difference between the player's position and this target position
{ virtual NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos) = 0;
// TODO => set the position from the character's position and the diffpos
}
TDataSetIndex getEntityId() const TDataSetIndex getEntityId() const
{ {
@ -185,7 +181,7 @@ public:
} }
else else
{ {
NLMISC::CVector diffPos = getDiffPos(); NLMISC::CVector diffPos = getDiffPos(getPosition());
NLMISC::serialPositionDifference(f, diffPos); NLMISC::serialPositionDifference(f, diffPos);
} }
} }
@ -193,7 +189,7 @@ public:
f.serial(EntityId); f.serial(EntityId);
} }
private: protected:
PositionOrEntityType _type; PositionOrEntityType _type;
NLMISC::CVector Position; NLMISC::CVector Position;
TDataSetIndex EntityId; TDataSetIndex EntityId;

@ -110,13 +110,13 @@ public:
virtual void sendCameraModifier(NLMISC::CBitMemStream& bms) virtual void sendCameraModifier(NLMISC::CBitMemStream& bms)
{ {
TPositionOrEntity pos = CPositionOrEntityHelper::fromString(SoundPos); CPositionOrEntityHelper pos = CPositionOrEntityHelper::fromString(SoundPos);
if (pos == CPositionOrEntityHelper::Invalid) if (pos == CPositionOrEntityHelper::Invalid)
{ {
nlerror("<CCameraAnimationModifierSoundTrigger parseModifier> invalid soundpos %s", SoundPos.c_str()); nlerror("<CCameraAnimationModifierSoundTrigger parseModifier> invalid soundpos %s", SoundPos.c_str());
} }
bms.serial(const_cast<TPositionOrEntity&>(pos)); bms.serial(const_cast<CPositionOrEntityHelper&>(pos));
bms.serial(const_cast<NLMISC::CSheetId&>(SoundId)); bms.serial(const_cast<NLMISC::CSheetId&>(SoundId));
} }

@ -155,25 +155,25 @@ public:
virtual void sendAnimationStep(NLMISC::CBitMemStream& bms) virtual void sendAnimationStep(NLMISC::CBitMemStream& bms)
{ {
TPositionOrEntity posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget); CPositionOrEntityHelper posLookAtTarget = CPositionOrEntityHelper::fromString(LookAtTarget);
if (posLookAtTarget == CPositionOrEntityHelper::Invalid) if (posLookAtTarget == CPositionOrEntityHelper::Invalid)
{ {
nlerror("<CCameraAnimationStepBasic parseStep> invalid LookAtTarget %s", LookAtTarget.c_str()); nlerror("<CCameraAnimationStepBasic parseStep> invalid LookAtTarget %s", LookAtTarget.c_str());
} }
bms.serial(const_cast<TPositionOrEntity&>(posLookAtTarget)); bms.serial(const_cast<CPositionOrEntityHelper&>(posLookAtTarget));
if (!posLookAtTarget.isPreviousPos()) if (!posLookAtTarget.isPreviousPos())
{ {
NLMISC::serialDuration(bms, DirectionTransitionTime); NLMISC::serialDuration(bms, DirectionTransitionTime);
} }
TPositionOrEntity posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget); CPositionOrEntityHelper posPosTarget = CPositionOrEntityHelper::fromString(PositionTarget);
if (posPosTarget == CPositionOrEntityHelper::Invalid) if (posPosTarget == CPositionOrEntityHelper::Invalid)
{ {
nlerror("<CCameraAnimationStepBasic parseStep> invalid PositionTarget %s", PositionTarget.c_str()); nlerror("<CCameraAnimationStepBasic parseStep> invalid PositionTarget %s", PositionTarget.c_str());
} }
bms.serial(const_cast<TPositionOrEntity&>(posPosTarget)); bms.serial(const_cast<CPositionOrEntityHelper&>(posPosTarget));
if (!posPosTarget.isPreviousPos()) if (!posPosTarget.isPreviousPos())
{ {
NLMISC::serialDistance(bms, DistanceTo); NLMISC::serialDistance(bms, DistanceTo);

@ -28,14 +28,14 @@
#define POS_OR_ENTITY_PREVIOUS_POS_VALUE "_PreviousPos_" #define POS_OR_ENTITY_PREVIOUS_POS_VALUE "_PreviousPos_"
#define POS_OR_ENTITY_RETURN_POS_VALUE "_ReturnPos_" #define POS_OR_ENTITY_RETURN_POS_VALUE "_ReturnPos_"
const TPositionOrEntity CPositionOrEntityHelper::Invalid = TPositionOrEntity(); const CPositionOrEntityHelper CPositionOrEntityHelper::Invalid = CPositionOrEntityHelper();
TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s) CPositionOrEntityHelper CPositionOrEntityHelper::fromString(const std::string& s)
{ {
// If the string is empty it's a previous pos // If the string is empty it's a previous pos
if (s.empty()) if (s.empty())
{ {
return TPositionOrEntity(TPositionOrEntity::EPreviousPos); return CPositionOrEntityHelper(CPositionOrEntity::EPreviousPos);
} }
std::string str = s; std::string str = s;
@ -44,11 +44,11 @@ TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s)
// We already check if it's a special position or entity object // We already check if it's a special position or entity object
if (NLMISC::toLower(str) == POS_OR_ENTITY_PREVIOUS_POS_VALUE) if (NLMISC::toLower(str) == POS_OR_ENTITY_PREVIOUS_POS_VALUE)
{ {
return TPositionOrEntity(TPositionOrEntity::EPreviousPos); return CPositionOrEntityHelper(CPositionOrEntity::EPreviousPos);
} }
else if (NLMISC::toLower(str) == POS_OR_ENTITY_RETURN_POS_VALUE) else if (NLMISC::toLower(str) == POS_OR_ENTITY_RETURN_POS_VALUE)
{ {
return TPositionOrEntity(TPositionOrEntity::EReturnPos); return CPositionOrEntityHelper(CPositionOrEntity::EReturnPos);
} }
std::vector<std::string> resS; std::vector<std::string> resS;
@ -61,23 +61,23 @@ TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s)
if (res.size() != 1) if (res.size() != 1)
{ {
nlerror("TPositionOrentityHelper : no alias for entity name %s", str.c_str()); nlerror("TPositionOrentityHelper : no alias for entity name %s", str.c_str());
return TPositionOrEntity(); return CPositionOrEntityHelper();
} }
TAIAlias alias = res[0]; TAIAlias alias = res[0];
if (alias == CAIAliasTranslator::Invalid) if (alias == CAIAliasTranslator::Invalid)
{ {
nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str.c_str()); nlerror("TPositionOrentityHelper : invalid alias for entity name %s", str.c_str());
return TPositionOrEntity(); return CPositionOrEntityHelper();
} }
NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias); NLMISC::CEntityId eid = CAIAliasTranslator::getInstance()->getEntityId(alias);
if (eid == NLMISC::CEntityId::Unknown) if (eid == NLMISC::CEntityId::Unknown)
{ {
nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias); nlerror("TPositionOrentityHelper : invalid entity id from alias %d", alias);
return TPositionOrEntity(); return CPositionOrEntityHelper();
} }
TDataSetIndex compressedId = TheDataset.getDataSetRow(eid).getCompressedIndex(); TDataSetIndex compressedId = TheDataset.getDataSetRow(eid).getCompressedIndex();
return TPositionOrEntity(compressedId); return CPositionOrEntityHelper(compressedId);
} }
else else
{ {
@ -97,21 +97,31 @@ TPositionOrEntity CPositionOrEntityHelper::fromString(const std::string& s)
if (!NLMISC::fromString(xStr, x)) if (!NLMISC::fromString(xStr, x))
{ {
nlerror("TPositionOrentityHelper : invalid x component from string %s", xStr.c_str()); nlerror("TPositionOrentityHelper : invalid x component from string %s", xStr.c_str());
return TPositionOrEntity(); return CPositionOrEntityHelper();
} }
if (!NLMISC::fromString(yStr, y)) if (!NLMISC::fromString(yStr, y))
{ {
nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr.c_str()); nlerror("TPositionOrentityHelper : invalid y component from string %s", yStr.c_str());
return TPositionOrEntity(); return CPositionOrEntityHelper();
} }
if (!NLMISC::fromString(yStr, x)) if (!NLMISC::fromString(yStr, x))
{ {
nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr.c_str()); nlerror("TPositionOrentityHelper : invalid z component from string %s", zStr.c_str());
return TPositionOrEntity(); return CPositionOrEntityHelper();
} }
return TPositionOrEntity(NLMISC::CVector(x, y, z)); return CPositionOrEntityHelper(NLMISC::CVector(x, y, z));
} }
return TPositionOrEntity(); return CPositionOrEntityHelper();
}
NLMISC::CVector CPositionOrEntityHelper::getDiffPos(const NLMISC::CVector& targetPos) const
{
return Position;
}
NLMISC::CVector CPositionOrEntityHelper::setPositionFromDiffPos(const NLMISC::CVector& diffPos)
{
return Position;
} }

@ -26,16 +26,43 @@
/************************************************************************/ /************************************************************************/
/* Class that can contain either an entity id or a position */ /* Class that can contain either an entity id or a position */
/************************************************************************/ /************************************************************************/
class CPositionOrEntityHelper class CPositionOrEntityHelper: public CPositionOrEntity
{ {
public: public:
CPositionOrEntityHelper(): CPositionOrEntity()
{
}
CPositionOrEntityHelper(const NLMISC::CVector& position): CPositionOrEntity(position)
{
}
CPositionOrEntityHelper(const TDataSetIndex& eid): CPositionOrEntity(eid)
{
}
CPositionOrEntityHelper(PositionOrEntityType type): CPositionOrEntity(type)
{
}
CPositionOrEntityHelper(const CPositionOrEntity& c): CPositionOrEntity(c)
{
}
/************************************************************************/ /************************************************************************/
/* Creates a PositionOrEntity instance from a string */ /* Creates a PositionOrEntity instance from a string */
/************************************************************************/ /************************************************************************/
static TPositionOrEntity fromString(const std::string& s); static CPositionOrEntityHelper fromString(const std::string& s);
static const CPositionOrEntityHelper Invalid;
// Declares abstract methods
/// This function returns the difference between the player's position and the specified position
NLMISC::CVector getDiffPos(const NLMISC::CVector& targetPos) const;
static const TPositionOrEntity Invalid; /// This function returns the target position given the difference between the player's position and this target position
NLMISC::CVector setPositionFromDiffPos(const NLMISC::CVector& diffPos);
}; };

@ -5484,7 +5484,7 @@ class CMissionActionSoundTrigger : public IMissionAction
instance->getEntities(entities); instance->getEntities(entities);
// We get the position or entity // We get the position or entity
TPositionOrEntity pos = CPositionOrEntityHelper::fromString(_SoundPosition); CPositionOrEntityHelper pos = CPositionOrEntityHelper::fromString(_SoundPosition);
if (pos == CPositionOrEntityHelper::Invalid) if (pos == CPositionOrEntityHelper::Invalid)
{ {
nlerror("<sound_trigger mission_action launch> invalid position or entity from %s", _SoundPosition.c_str()); nlerror("<sound_trigger mission_action launch> invalid position or entity from %s", _SoundPosition.c_str());

Loading…
Cancel
Save