2010-06-03 03:29:43 +02:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_OBJECTBASE
|
|
|
|
#define INCLUDED_OBJECTBASE
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
class CModel;
|
|
|
|
class CSkeletonAnim;
|
2007-01-08 02:56:46 +01:00
|
|
|
class CObjectManager;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2009-11-03 22:46:35 +01:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CStr.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-01-03 19:40:28 +01:00
|
|
|
class CObjectBase
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2009-01-03 19:40:28 +01:00
|
|
|
NONCOPYABLE(CObjectBase);
|
2006-04-24 01:14:18 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
struct Anim {
|
|
|
|
// constructor
|
2010-06-05 02:49:14 +02:00
|
|
|
Anim() : m_Speed(1.f), m_ActionPos(-1.f), m_ActionPos2(-1.f) {}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// name of the animation - "Idle", "Run", etc
|
|
|
|
CStr m_AnimName;
|
|
|
|
// filename of the animation - manidle.psa, manrun.psa, etc
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath m_FileName;
|
2006-04-24 01:14:18 +02:00
|
|
|
// animation speed, as specified in XML actor file
|
|
|
|
float m_Speed;
|
2010-06-05 02:49:14 +02:00
|
|
|
// fraction [0.0, 1.0] of the way through the animation that the interesting bit(s)
|
|
|
|
// happens, or -1.0 if unspecified
|
2007-02-10 04:09:52 +01:00
|
|
|
float m_ActionPos;
|
|
|
|
float m_ActionPos2;
|
2006-04-24 01:14:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Prop {
|
|
|
|
// name of the prop point to attach to - "Prop01", "Prop02", "Head", "LeftHand", etc ..
|
|
|
|
CStr m_PropPointName;
|
|
|
|
// name of the model file - art/actors/props/sword.xml or whatever
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath m_ModelName;
|
2006-04-24 01:14:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Variant
|
|
|
|
{
|
|
|
|
Variant() : m_Frequency(0) {}
|
|
|
|
CStr m_VariantName; // lowercase name
|
|
|
|
int m_Frequency;
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath m_ModelFilename;
|
|
|
|
VfsPath m_TextureFilename;
|
2006-04-24 01:14:18 +02:00
|
|
|
CStr m_Color;
|
|
|
|
|
|
|
|
std::vector<Anim> m_Anims;
|
|
|
|
std::vector<Prop> m_Props;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Variation
|
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath texture;
|
|
|
|
VfsPath model;
|
2006-04-24 01:14:18 +02:00
|
|
|
CStr color;
|
2010-06-03 03:29:43 +02:00
|
|
|
std::multimap<CStr, Prop> props;
|
|
|
|
std::multimap<CStr, Anim> anims;
|
2006-04-24 01:14:18 +02:00
|
|
|
};
|
|
|
|
|
2007-01-08 02:56:46 +01:00
|
|
|
CObjectBase(CObjectManager& objectManager);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-05-31 07:27:02 +02:00
|
|
|
// Get the variation key (indices of chosen variants from each group)
|
|
|
|
// based on the selection strings
|
2006-08-06 20:41:07 +02:00
|
|
|
std::vector<u8> CalculateVariationKey(const std::vector<std::set<CStr> >& selections);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-05-31 07:27:02 +02:00
|
|
|
// Get the final actor data, combining all selected variants
|
2006-04-24 01:14:18 +02:00
|
|
|
const Variation BuildVariation(const std::vector<u8>& variationKey);
|
|
|
|
|
2006-05-31 07:27:02 +02:00
|
|
|
// Get a set of selection strings that are complete enough to specify an
|
|
|
|
// exact variation of the actor, using the initial selections wherever possible
|
|
|
|
// and choosing randomly where a choice is necessary.
|
2006-08-06 20:41:07 +02:00
|
|
|
std::set<CStr> CalculateRandomVariation(const std::set<CStr>& initialSelections);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-05-31 07:27:02 +02:00
|
|
|
// Get a list of variant groups for this object, plus for all possible
|
|
|
|
// props. Duplicated groups are removed, if several props share the same
|
|
|
|
// variant names.
|
2006-08-06 20:41:07 +02:00
|
|
|
std::vector<std::vector<CStr> > GetVariantGroups() const;
|
2006-05-31 07:27:02 +02:00
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
/**
|
|
|
|
* Initialise this object by loading from the given file.
|
|
|
|
* Returns false on error.
|
|
|
|
*/
|
|
|
|
bool Load(const VfsPath& pathname);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
/**
|
|
|
|
* Reload this object from the file that it was previously loaded from.
|
|
|
|
* Returns false on error.
|
|
|
|
*/
|
|
|
|
bool Reload();
|
|
|
|
|
|
|
|
// filename that this was loaded from
|
|
|
|
VfsPath m_Pathname;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// short human-readable name
|
2009-11-03 22:46:35 +01:00
|
|
|
CStrW m_ShortName;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
// automatically flatten terrain when applying object
|
|
|
|
bool m_AutoFlatten;
|
|
|
|
// cast shadows from this object
|
|
|
|
bool m_CastShadows;
|
2006-09-28 04:05:56 +02:00
|
|
|
// float on top of water
|
|
|
|
bool m_FloatOnWater;
|
2006-04-24 01:14:18 +02:00
|
|
|
} m_Properties;
|
|
|
|
|
|
|
|
// the material file
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath m_Material;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector< std::vector<Variant> > m_VariantGroups;
|
2007-01-08 02:56:46 +01:00
|
|
|
CObjectManager& m_ObjectManager;
|
2006-04-24 01:14:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|