2004-06-03 20:38:14 +02:00
# include "precompiled.h"
2006-07-13 05:29:33 +02:00
# include "EntityTemplate.h"
# include "EntityTemplateCollection.h"
2006-06-02 04:10:27 +02:00
# include "graphics/ObjectManager.h"
# include "ps/CStr.h"
# include "ps/Player.h"
2006-07-27 23:20:30 +02:00
# include "scripting/ScriptableComplex.inl"
2005-08-15 01:50:37 +02:00
# include "ps/XML/Xeromyces.h"
2004-05-22 01:46:16 +02:00
2006-06-02 04:10:27 +02:00
# include "ps/CLogger.h"
2004-10-07 21:23:35 +02:00
# define LOG_CATEGORY "entity"
2006-07-13 05:29:33 +02:00
STL_HASH_SET < CStr , CStr_hash_compare > CEntityTemplate : : scriptsLoaded ;
2005-12-29 09:42:44 +01:00
2007-01-13 21:14:03 +01:00
// Utility functions used in reading XML
namespace {
/**
* Converts the given string , consisting of underscores and letters ,
* to camelCase : the first letter of each underscore - separated " word "
* is changed to lowercase . For example , the string MiniMap_Colour
* is converted to miniMap_colour .
*
* @ param const std : : string & str The string to convert .
* @ return std : : string The given string in camelCase .
* */
std : : string toCamelCase ( const std : : string & str )
{
std : : string ret = str ;
for ( size_t i = 0 ; i < ret . size ( ) ; i + + )
{
if ( i = = 0 | | ret [ i - 1 ] = = ' _ ' )
{
ret [ i ] = tolower ( ret [ i ] ) ;
}
}
return ret ;
}
}
2006-07-13 05:29:33 +02:00
CEntityTemplate : : CEntityTemplate ( CPlayer * player )
2004-05-30 04:18:49 +02:00
{
2006-05-14 00:11:46 +02:00
m_player = player ;
2005-03-30 18:14:19 +02:00
m_base = NULL ;
2006-01-16 11:56:47 +01:00
2004-10-07 21:23:35 +02:00
AddProperty ( L " tag " , & m_Tag , false ) ;
2005-03-30 18:14:19 +02:00
AddProperty ( L " parent " , & m_base , false ) ;
2006-05-14 00:11:46 +02:00
AddProperty ( L " unmodified " , & m_unmodified , false ) ;
2004-10-07 21:23:35 +02:00
for ( int t = 0 ; t < EVENT_LAST ; t + + )
2005-04-22 09:12:55 +02:00
{
AddProperty ( EventNames [ t ] , & m_EventHandlers [ t ] , false ) ;
AddHandler ( t , & m_EventHandlers [ t ] ) ;
}
2004-10-23 16:39:28 +02:00
2004-11-11 08:09:32 +01:00
// Initialize, make life a little easier on the scriptors
2005-05-01 21:09:13 +02:00
m_speed = m_turningRadius = 0.0f ;
2006-07-13 00:24:25 +02:00
//m_extant = true;
2006-02-26 10:55:20 +01:00
m_foundation = CStrW ( ) ;
2006-07-10 01:12:37 +02:00
m_socket = CStrW ( ) ;
2006-05-13 06:07:42 +02:00
m_passThroughAllies = false ;
2006-05-29 05:28:54 +02:00
m_sectorDivs = 4 ;
2004-11-11 08:09:32 +01:00
2006-03-04 02:15:32 +01:00
// Sentinel values for stamina and health (so scripts can check if an entity has no stamina or no HP).
2006-07-19 01:59:48 +02:00
m_speed = 0 ;
2006-03-03 21:57:45 +01:00
m_staminaMax = 0 ;
2006-03-04 02:15:32 +01:00
m_healthMax = 0 ;
2006-03-03 21:57:45 +01:00
2004-10-07 21:23:35 +02:00
m_bound_type = CBoundingObject : : BOUND_NONE ;
2004-05-30 04:18:49 +02:00
m_bound_circle = NULL ;
m_bound_box = NULL ;
2006-07-18 06:17:46 +02:00
// If these aren't set, we can get an infinite loop in CEntity::interpolate, which is nasty; they
// should be set in template_entity, but do this in case some entity forgets to inherit from that
m_anchorConformX = 0 ;
m_anchorConformZ = 0 ;
2004-05-30 04:18:49 +02:00
}
2006-07-13 05:29:33 +02:00
CEntityTemplate : : ~ CEntityTemplate ( )
2004-05-30 03:57:26 +02:00
{
if ( m_bound_box )
delete ( m_bound_box ) ;
if ( m_bound_circle )
delete ( m_bound_circle ) ;
}
2007-05-02 14:07:08 +02:00
void CEntityTemplate : : LoadBase ( )
2004-10-07 21:23:35 +02:00
{
2007-01-13 21:14:03 +01:00
// Copy the parent's bounds, unless we're providing a replacement.
2004-10-07 21:23:35 +02:00
if ( m_bound_type = = CBoundingObject : : BOUND_NONE )
{
if ( m_base - > m_bound_type = = CBoundingObject : : BOUND_CIRCLE )
{
m_bound_circle = new CBoundingCircle ( ) ;
2007-05-02 14:07:08 +02:00
m_bound_circle - > SetRadius ( m_base - > m_bound_circle - > m_radius ) ;
m_bound_circle - > SetHeight ( m_base - > m_bound_circle - > m_height ) ;
2004-10-07 21:23:35 +02:00
}
else if ( m_base - > m_bound_type = = CBoundingObject : : BOUND_OABB )
{
m_bound_box = new CBoundingBox ( ) ;
2007-05-02 14:07:08 +02:00
m_bound_box - > SetDimensions ( m_base - > m_bound_box - > GetWidth ( ) , m_base - > m_bound_box - > GetDepth ( ) ) ;
m_bound_box - > SetHeight ( m_base - > m_bound_box - > m_height ) ;
2004-10-07 21:23:35 +02:00
}
m_bound_type = m_base - > m_bound_type ;
}
2007-01-13 21:14:03 +01:00
// Initialize sound group table from the parent's sound group table
for ( SoundGroupTable : : iterator it = m_base - > m_SoundGroupTable . begin ( ) ;
it ! = m_base - > m_SoundGroupTable . end ( ) ; + + it )
{
m_SoundGroupTable [ it - > first ] = it - > second ;
}
2004-10-07 21:23:35 +02:00
SetBase ( m_base ) ;
2005-05-01 21:09:13 +02:00
m_classes . SetParent ( & ( m_base - > m_classes ) ) ;
2005-04-22 09:12:55 +02:00
SetNextObject ( m_base ) ;
2004-10-07 21:23:35 +02:00
}
2007-05-02 14:07:08 +02:00
jsval CEntityTemplate : : GetClassSet ( )
2005-05-01 21:09:13 +02:00
{
2007-05-02 14:07:08 +02:00
CStrW result = m_classes . GetMemberList ( ) ;
2005-05-01 21:09:13 +02:00
return ( ToJSVal ( result ) ) ;
}
2007-05-02 14:07:08 +02:00
void CEntityTemplate : : SetClassSet ( jsval value )
2005-05-01 21:09:13 +02:00
{
2006-07-24 03:33:26 +02:00
CStr memberCmdList = ToPrimitive < CStrW > ( value ) ;
2007-05-02 14:07:08 +02:00
m_classes . SetFromMemberList ( memberCmdList ) ;
2005-05-01 21:09:13 +02:00
2007-05-02 14:07:08 +02:00
RebuildClassSet ( ) ;
2005-05-01 21:09:13 +02:00
}
2007-05-02 14:07:08 +02:00
void CEntityTemplate : : RebuildClassSet ( )
2005-05-01 21:09:13 +02:00
{
m_classes . Rebuild ( ) ;
InheritorsList : : iterator it ;
for ( it = m_Inheritors . begin ( ) ; it ! = m_Inheritors . end ( ) ; it + + )
2007-05-02 14:07:08 +02:00
( * it ) - > RebuildClassSet ( ) ;
2005-05-01 21:09:13 +02:00
}
2007-05-02 14:07:08 +02:00
bool CEntityTemplate : : LoadXml ( const CStr & filename )
2004-05-22 01:46:16 +02:00
{
2004-07-08 17:22:09 +02:00
CXeromyces XeroFile ;
2004-07-29 18:17:21 +02:00
if ( XeroFile . Load ( filename ) ! = PSRETURN_OK )
2004-07-17 19:09:33 +02:00
// Fail
2004-07-08 17:22:09 +02:00
return false ;
2004-05-22 01:46:16 +02:00
2004-07-08 17:22:09 +02:00
// Define all the elements and attributes used in the XML file
2007-05-02 14:07:08 +02:00
# define EL(x) int el_##x = XeroFile.GetElementID(#x)
# define AT(x) int at_##x = XeroFile.GetAttributeID(#x)
2004-10-07 21:23:35 +02:00
// Only the ones we can't load using normal methods.
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
EL ( Entity ) ;
EL ( Script ) ;
EL ( Event ) ;
EL ( Traits ) ;
EL ( Footprint ) ;
EL ( Depth ) ;
EL ( Height ) ;
EL ( Radius ) ;
EL ( Width ) ;
2007-01-13 21:14:03 +01:00
EL ( SoundGroups ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
AT ( Parent ) ;
AT ( On ) ;
AT ( File ) ;
AT ( Function ) ;
2004-07-08 17:22:09 +02:00
# undef AT
# undef EL
2007-05-02 14:07:08 +02:00
XMBElement Root = XeroFile . GetRoot ( ) ;
2004-07-08 17:22:09 +02:00
2007-05-02 14:07:08 +02:00
if ( Root . GetNodeName ( ) ! = el_Entity )
2004-10-07 21:23:35 +02:00
{
2007-12-29 17:22:23 +01:00
LOG ( CLogger : : Error , LOG_CATEGORY , " CEntityTemplate::LoadXml: XML root was not \" Entity \" in file %s. Load failed. " , filename . c_str ( ) ) ;
2004-10-07 21:23:35 +02:00
return ( false ) ;
}
2004-07-08 17:22:09 +02:00
2007-05-02 14:07:08 +02:00
XMBElementList RootChildren = Root . GetChildNodes ( ) ;
2004-07-08 17:22:09 +02:00
2005-03-29 22:50:04 +02:00
m_Tag = CStr ( filename ) . AfterLast ( " / " ) . BeforeLast ( " .xml " ) ;
2004-10-07 21:23:35 +02:00
2007-05-02 14:07:08 +02:00
m_Base_Name = Root . GetAttributes ( ) . GetNamedItem ( at_Parent ) ;
2006-07-13 00:24:25 +02:00
// Load our parent, if we have one
2007-02-01 15:46:14 +01:00
if ( ! m_Base_Name . empty ( ) )
2006-07-13 00:24:25 +02:00
{
2007-05-02 14:07:08 +02:00
CEntityTemplate * base = g_EntityTemplateCollection . GetTemplate ( m_Base_Name , m_player ) ;
2006-07-13 00:24:25 +02:00
if ( base )
{
m_base = base ;
2007-05-02 14:07:08 +02:00
LoadBase ( ) ;
2006-07-13 00:24:25 +02:00
}
else
{
2007-12-29 17:22:23 +01:00
LOG ( CLogger : : Warning , LOG_CATEGORY , " Parent template \" %ls \" does not exist in template \" %ls \" " , m_Base_Name . c_str ( ) , m_Tag . c_str ( ) ) ;
2006-07-13 00:24:25 +02:00
// (The requested entity will still be returned, but with no parent.
// Is this a reasonable thing to do?)
}
}
2004-10-07 21:23:35 +02:00
2004-07-08 17:22:09 +02:00
for ( int i = 0 ; i < RootChildren . Count ; + + i )
2004-05-22 01:46:16 +02:00
{
2007-05-02 14:07:08 +02:00
XMBElement Child = RootChildren . Item ( i ) ;
2004-07-08 17:22:09 +02:00
2007-05-02 14:07:08 +02:00
int ChildName = Child . GetNodeName ( ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
if ( ChildName = = el_Script )
2004-07-08 17:22:09 +02:00
{
2007-05-02 14:07:08 +02:00
CStr Include = Child . GetAttributes ( ) . GetNamedItem ( at_File ) ;
2004-10-07 21:23:35 +02:00
2007-02-01 15:46:14 +01:00
if ( ! Include . empty ( ) & & scriptsLoaded . find ( Include ) = = scriptsLoaded . end ( ) )
2005-12-29 09:42:44 +01:00
{
scriptsLoaded . insert ( Include ) ;
g_ScriptingHost . RunScript ( Include ) ;
}
2004-10-07 21:23:35 +02:00
2007-05-02 14:07:08 +02:00
CStr Inline = Child . GetText ( ) ;
2007-02-01 15:46:14 +01:00
if ( ! Inline . empty ( ) )
2005-12-29 09:42:44 +01:00
{
2007-05-02 14:07:08 +02:00
g_ScriptingHost . RunMemScript ( Inline . c_str ( ) , Inline . length ( ) , filename . c_str ( ) , Child . GetLineNumber ( ) ) ;
2005-12-29 09:42:44 +01:00
}
2004-07-08 17:22:09 +02:00
}
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
else if ( ChildName = = el_Traits )
2004-07-08 17:22:09 +02:00
{
2007-05-02 14:07:08 +02:00
XMBElementList TraitChildren = Child . GetChildNodes ( ) ;
2005-12-15 22:59:48 +01:00
for ( int j = 0 ; j < TraitChildren . Count ; + + j )
2004-10-07 21:23:35 +02:00
{
2007-05-02 14:07:08 +02:00
XMBElement TraitChild = TraitChildren . Item ( j ) ;
int TraitChildName = TraitChild . GetNodeName ( ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
if ( TraitChildName = = el_Footprint )
2005-12-15 22:59:48 +01:00
{
2007-05-02 14:07:08 +02:00
XMBElementList FootprintChildren = TraitChild . GetChildNodes ( ) ;
2005-12-15 22:59:48 +01:00
float radius = 0 , height = 0 , width = 0 , depth = 0 ;
bool hadRadius = false , hadDepth = false ;
for ( int k = 0 ; k < FootprintChildren . Count ; + + k )
{
2007-05-02 14:07:08 +02:00
XMBElement FootprintChild = FootprintChildren . Item ( k ) ;
int FootprintChildName = FootprintChild . GetNodeName ( ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
if ( FootprintChildName = = el_Radius )
2005-12-15 22:59:48 +01:00
{
hadRadius = true ;
2007-05-02 14:07:08 +02:00
radius = CStrW ( FootprintChild . GetText ( ) ) . ToFloat ( ) ;
2005-12-15 22:59:48 +01:00
}
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
else if ( FootprintChildName = = el_Width )
2005-12-15 22:59:48 +01:00
{
2007-05-02 14:07:08 +02:00
width = CStrW ( FootprintChild . GetText ( ) ) . ToFloat ( ) ;
2005-12-15 22:59:48 +01:00
}
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
else if ( FootprintChildName = = el_Height )
2005-12-15 22:59:48 +01:00
{
2007-05-02 14:07:08 +02:00
height = CStrW ( FootprintChild . GetText ( ) ) . ToFloat ( ) ;
2005-12-15 22:59:48 +01:00
}
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
else if ( FootprintChildName = = el_Depth )
2005-12-15 22:59:48 +01:00
{
hadDepth = true ;
2007-05-02 14:07:08 +02:00
depth = CStrW ( FootprintChild . GetText ( ) ) . ToFloat ( ) ;
2005-12-15 22:59:48 +01:00
}
}
if ( hadRadius )
{
// Specifying a circular footprint
if ( ! m_bound_circle )
m_bound_circle = new CBoundingCircle ( ) ;
2007-05-02 14:07:08 +02:00
m_bound_circle - > SetRadius ( radius ) ;
m_bound_circle - > SetHeight ( height ) ;
2005-12-15 22:59:48 +01:00
m_bound_type = CBoundingObject : : BOUND_CIRCLE ;
}
else if ( hadDepth )
{
2006-02-26 10:55:20 +01:00
// Specifying a rectangular footprint
2005-12-15 22:59:48 +01:00
if ( ! m_bound_box )
m_bound_box = new CBoundingBox ( ) ;
2007-05-02 14:07:08 +02:00
m_bound_box - > SetDimensions ( width , depth ) ;
m_bound_box - > SetHeight ( height ) ;
2005-12-15 22:59:48 +01:00
m_bound_type = CBoundingObject : : BOUND_OABB ;
}
2006-02-26 10:55:20 +01:00
// Else, entity has no footprint.
2005-12-15 22:59:48 +01:00
}
2004-10-07 21:23:35 +02:00
}
2005-12-15 22:59:48 +01:00
// important so that scripts can see traits
XMLLoadProperty ( XeroFile , Child , CStrW ( ) ) ;
2004-07-08 17:22:09 +02:00
}
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
else if ( ChildName = = el_Event )
2004-07-08 17:22:09 +02:00
{
2004-10-07 21:23:35 +02:00
// Action...On for consistency with the GUI.
2007-05-02 14:07:08 +02:00
CStrW EventName = L " on " + ( CStrW ) Child . GetAttributes ( ) . GetNamedItem ( at_On ) ;
2004-10-07 21:23:35 +02:00
2007-05-02 14:07:08 +02:00
CStrW Code ( Child . GetText ( ) ) ;
utf16string ExternalFunction = Child . GetAttributes ( ) . GetNamedItem ( at_Function ) ;
2005-04-15 06:23:33 +02:00
2004-10-07 21:23:35 +02:00
// Does a property with this name already exist?
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
for ( size_t eventID = 0 ; eventID < EVENT_LAST ; eventID + + )
2004-10-07 21:23:35 +02:00
{
if ( CStrW ( EventNames [ eventID ] ) = = EventName )
{
2005-05-18 07:32:09 +02:00
if ( ExternalFunction ! = utf16string ( ) )
2005-04-15 06:23:33 +02:00
{
jsval fnval ;
2005-05-18 07:32:09 +02:00
JSBool ret = JS_GetUCProperty ( g_ScriptingHost . GetContext ( ) , g_ScriptingHost . GetGlobalObject ( ) , ExternalFunction . c_str ( ) , ExternalFunction . size ( ) , & fnval ) ;
2005-06-28 06:06:25 +02:00
debug_assert ( ret ) ;
2005-04-15 06:23:33 +02:00
JSFunction * fn = JS_ValueToFunction ( g_ScriptingHost . GetContext ( ) , fnval ) ;
if ( ! fn )
{
2007-12-29 17:22:23 +01:00
LOG ( CLogger : : Error , LOG_CATEGORY , " CEntityTemplate::LoadXml: Function does not exist for event %hs in file %s. Load failed. " , EventName . c_str ( ) , filename . c_str ( ) ) ;
2005-04-15 06:23:33 +02:00
break ;
}
m_EventHandlers [ eventID ] . SetFunction ( fn ) ;
}
else
2007-05-02 14:07:08 +02:00
m_EventHandlers [ eventID ] . Compile ( CStrW ( filename ) + L " :: " + EventName + L " ( " + CStrW ( Child . GetLineNumber ( ) ) + L " ) " , Code ) ;
2004-10-07 21:23:35 +02:00
HasProperty ( EventName ) - > m_Inherited = false ;
break ;
}
}
2004-07-08 17:22:09 +02:00
}
2007-01-13 21:14:03 +01:00
else if ( ChildName = = el_SoundGroups )
{
// Read every child element's value into m_SoundGroupTable with its tag as the key
2007-05-02 14:07:08 +02:00
XMBElementList children = Child . GetChildNodes ( ) ;
2007-01-13 21:14:03 +01:00
for ( int j = 0 ; j < children . Count ; + + j )
{
2007-05-02 14:07:08 +02:00
XMBElement child = children . Item ( j ) ;
CStr8 name = toCamelCase ( XeroFile . GetElementString ( child . GetNodeName ( ) ) ) ;
CStr8 value = child . GetText ( ) ;
2007-01-13 21:14:03 +01:00
m_SoundGroupTable [ name ] = value ;
}
}
2004-10-07 21:23:35 +02:00
else
2004-07-08 17:22:09 +02:00
{
2004-10-07 21:23:35 +02:00
XMLLoadProperty ( XeroFile , Child , CStrW ( ) ) ;
2004-07-08 17:22:09 +02:00
}
2004-10-07 21:23:35 +02:00
}
2006-05-14 00:11:46 +02:00
if ( m_player = = 0 )
{
m_unmodified = this ;
}
else
{
2007-05-02 14:07:08 +02:00
m_unmodified = g_EntityTemplateCollection . GetTemplate ( m_Tag , 0 ) ;
2006-05-14 00:11:46 +02:00
}
2004-10-07 21:23:35 +02:00
return true ;
}
2006-07-20 16:37:58 +02:00
void CEntityTemplate : : XMLLoadProperty ( const CXeromyces & XeroFile , const XMBElement & Source , const CStrW & BasePropertyName )
2004-10-07 21:23:35 +02:00
{
// Add a property, put the node text into it.
2007-05-02 14:07:08 +02:00
CStrW PropertyName = BasePropertyName + CStrW ( toCamelCase ( XeroFile . GetElementString ( Source . GetNodeName ( ) ) ) ) ;
2004-10-07 21:23:35 +02:00
2005-04-22 09:12:55 +02:00
IJSComplexProperty * Existing = HasProperty ( PropertyName ) ;
2004-10-07 21:23:35 +02:00
if ( Existing )
{
if ( ! Existing - > m_Intrinsic )
2007-12-29 17:22:23 +01:00
LOG ( CLogger : : Warning , LOG_CATEGORY , " CEntityTemplate::XMLAddProperty: %ls already defined for %ls. Property trees will be merged. " , PropertyName . c_str ( ) , m_Tag . c_str ( ) ) ;
2007-05-02 14:07:08 +02:00
Existing - > Set ( this , JSParseString ( Source . GetText ( ) ) ) ;
2006-07-13 00:24:25 +02:00
//Existing->m_Inherited = false;
2004-10-07 21:23:35 +02:00
}
else
{
2007-05-02 14:07:08 +02:00
if ( ! Source . GetText ( ) . length ( ) )
2004-06-03 15:27:01 +02:00
{
2004-10-07 21:23:35 +02:00
// Arbitrarily say that if a node has no other value, define it to be 'true'.
// Appears to be the most convenient thing to do in most circumstances.
AddProperty ( PropertyName , JSVAL_TRUE ) ;
2004-07-08 17:22:09 +02:00
}
2004-10-07 21:23:35 +02:00
else
2006-02-26 10:55:20 +01:00
{
2007-05-02 14:07:08 +02:00
AddProperty ( PropertyName , Source . GetText ( ) ) ;
2006-02-26 10:55:20 +01:00
}
2004-10-07 21:23:35 +02:00
}
2004-06-03 15:27:01 +02:00
2004-10-07 21:23:35 +02:00
PropertyName + = CStrW ( L " . " ) ;
2004-05-22 01:46:16 +02:00
2004-10-07 21:23:35 +02:00
// Retrieve any attributes it has and add them as subproperties.
2007-05-02 14:07:08 +02:00
XMBAttributeList AttributeSet = Source . GetAttributes ( ) ;
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
for ( int AttributeID = 0 ; AttributeID < AttributeSet . Count ; AttributeID + + )
2004-10-07 21:23:35 +02:00
{
2007-05-02 14:07:08 +02:00
XMBAttribute Attribute = AttributeSet . Item ( AttributeID ) ;
CStrW AttributeName = PropertyName + CStr8 ( toCamelCase ( XeroFile . GetAttributeString ( Attribute . Name ) ) ) ;
2004-10-07 21:23:35 +02:00
Existing = HasProperty ( AttributeName ) ;
2004-11-24 00:56:10 +01:00
2004-10-07 21:23:35 +02:00
if ( Existing )
{
2005-03-30 18:14:19 +02:00
Existing - > Set ( this , JSParseString ( Attribute . Value ) ) ;
2004-10-07 21:23:35 +02:00
Existing - > m_Inherited = false ;
2004-05-22 01:46:16 +02:00
}
2004-10-07 21:23:35 +02:00
else
AddProperty ( AttributeName , Attribute . Value ) ;
}
2004-05-22 01:46:16 +02:00
2004-10-07 21:23:35 +02:00
// Retrieve any child nodes the property has and, similarly, add them as subproperties.
2007-05-02 14:07:08 +02:00
XMBElementList NodeSet = Source . GetChildNodes ( ) ;
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
for ( int NodeID = 0 ; NodeID < NodeSet . Count ; NodeID + + )
2004-10-07 21:23:35 +02:00
{
2007-05-02 14:07:08 +02:00
XMBElement Node = NodeSet . Item ( NodeID ) ;
2004-10-07 21:23:35 +02:00
XMLLoadProperty ( XeroFile , Node , PropertyName ) ;
}
}
/*
Scripting Interface
*/
// Scripting initialization
2006-07-13 05:29:33 +02:00
void CEntityTemplate : : ScriptingInit ( )
2004-10-07 21:23:35 +02:00
{
2007-05-29 21:01:21 +02:00
AddMethod < CStr , & CEntityTemplate : : ToString > ( " toString " , 0 ) ;
2006-07-13 00:24:25 +02:00
2007-05-29 21:01:21 +02:00
AddClassProperty ( L " traits.id.classes " , static_cast < GetFn > ( & CEntityTemplate : : GetClassSet ) , static_cast < SetFn > ( & CEntityTemplate : : SetClassSet ) ) ;
2006-07-13 00:24:25 +02:00
2006-09-16 22:13:40 +02:00
AddClassProperty ( L " actions.move.speed " , & CEntityTemplate : : m_speed ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
AddClassProperty ( L " actions.move.turningRadius " , & CEntityTemplate : : m_turningRadius ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " actions.move.run.speed " , & CEntityTemplate : : m_runSpeed ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
AddClassProperty ( L " actions.move.run.rangeMin " , & CEntityTemplate : : m_runMinRange ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " actions.move.run.range " , & CEntityTemplate : : m_runMaxRange ) ;
2006-08-08 05:45:13 +02:00
AddClassProperty ( L " actions.move.run.regenRate " , & CEntityTemplate : : m_runRegenRate ) ;
AddClassProperty ( L " actions.move.run.decayRate " , & CEntityTemplate : : m_runDecayRate ) ;
AddClassProperty ( L " actions.move.passThroughAllies " , & CEntityTemplate : : m_passThroughAllies ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " actor " , & CEntityTemplate : : m_actorName ) ;
2007-05-29 21:01:21 +02:00
AddClassProperty ( L " traits.health.max " , & CEntityTemplate : : m_healthMax ) ;
AddClassProperty ( L " traits.health.barHeight " , & CEntityTemplate : : m_healthBarHeight ) ;
2006-08-08 05:45:13 +02:00
AddClassProperty ( L " traits.health.barSize " , & CEntityTemplate : : m_healthBarSize ) ;
AddClassProperty ( L " traits.health.barWidth " , & CEntityTemplate : : m_healthBarWidth ) ;
AddClassProperty ( L " traits.health.borderHeight " , & CEntityTemplate : : m_healthBorderHeight ) ;
AddClassProperty ( L " traits.health.borderWidth " , & CEntityTemplate : : m_healthBorderWidth ) ;
AddClassProperty ( L " traits.health.borderName " , & CEntityTemplate : : m_healthBorderName ) ;
AddClassProperty ( L " traits.health.regenRate " , & CEntityTemplate : : m_healthRegenRate ) ;
AddClassProperty ( L " traits.health.regenStart " , & CEntityTemplate : : m_healthRegenStart ) ;
AddClassProperty ( L " traits.health.decayRate " , & CEntityTemplate : : m_healthDecayRate ) ;
2007-05-29 21:01:21 +02:00
AddClassProperty ( L " traits.stamina.max " , & CEntityTemplate : : m_staminaMax ) ;
AddClassProperty ( L " traits.stamina.barHeight " , & CEntityTemplate : : m_staminaBarHeight ) ;
2006-08-08 05:45:13 +02:00
AddClassProperty ( L " traits.stamina.barSize " , & CEntityTemplate : : m_staminaBarSize ) ;
AddClassProperty ( L " traits.stamina.barWidth " , & CEntityTemplate : : m_staminaBarWidth ) ;
AddClassProperty ( L " traits.stamina.borderHeight " , & CEntityTemplate : : m_staminaBorderHeight ) ;
AddClassProperty ( L " traits.stamina.borderWidth " , & CEntityTemplate : : m_staminaBorderWidth ) ;
AddClassProperty ( L " traits.stamina.borderName " , & CEntityTemplate : : m_staminaBorderName ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " traits.rally.name " , & CEntityTemplate : : m_rallyName ) ;
AddClassProperty ( L " traits.rally.width " , & CEntityTemplate : : m_rallyWidth ) ;
AddClassProperty ( L " traits.rally.height " , & CEntityTemplate : : m_rallyHeight ) ;
2006-08-08 05:45:13 +02:00
AddClassProperty ( L " traits.flankPenalty.sectors " , & CEntityTemplate : : m_sectorDivs ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " traits.pitch.sectors " , & CEntityTemplate : : m_pitchDivs ) ;
2006-09-16 22:13:40 +02:00
AddClassProperty ( L " traits.pitch.value " , & CEntityTemplate : : m_pitchValue ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " traits.rank.width " , & CEntityTemplate : : m_rankWidth ) ;
AddClassProperty ( L " traits.rank.height " , & CEntityTemplate : : m_rankHeight ) ;
AddClassProperty ( L " traits.rank.name " , & CEntityTemplate : : m_rankName ) ;
2006-09-09 02:00:23 +02:00
AddClassProperty ( L " traits.ai.stance.curr " , & CEntityTemplate : : m_stanceName ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
AddClassProperty ( L " traits.miniMap.type " , & CEntityTemplate : : m_minimapType ) ;
AddClassProperty ( L " traits.miniMap.red " , & CEntityTemplate : : m_minimapR ) ;
AddClassProperty ( L " traits.miniMap.green " , & CEntityTemplate : : m_minimapG ) ;
AddClassProperty ( L " traits.miniMap.blue " , & CEntityTemplate : : m_minimapB ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " traits.anchor.type " , & CEntityTemplate : : m_anchorType ) ;
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and
attribute names to lowercase, so that we can have camelCase names. We
should now be able to convert all the multi-word entity properties, like
pass_through_allies, to camelCase, like passThroughAllies, which is more
consistent with the rest of our JavaScript naming conventions. To
support the existing code that assumes lowercase element names, I made
the getElementID and getAttributeID methods (used in the EL and AT
macros) ignore case, and I changed any code that directly accessed
element names to use the right case. CEntityTemplate now converts
Names_LikeThis to names_likeThis (changing each separate "word" in the
name to camelCase). Changed the version letter in XMB filenames from A
to B to support this without requiring people to delete old XMBs.
- Enhanced the pathfinder's handling of contact paths, resulting in a
very large speedup for actions like attacking, construction, etc. The
problem was that the pathfinder used to not count a given state as the
goal unless it was exactly coincident with the target location. This is
fine when you order a unit to go exactly to a certain spot, but if
you're ordering a unit to build, gather or attack something, then the
target tile is impassable (because your target is there) and therefore
the pathfinder never declares a state final. As a result, the pathfinder
tries hundreds of extra tiles in case there is a long path that gets to
the goal, and after failing to find any path that reaches the goal, it
gives you one to the closest point it got to. To fix it, I made the
pathfinder take into account a radius around the goal in which it's OK
to be, which depends on the size of the target unit and the range of
your action.
This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
AddClassProperty ( L " traits.anchor.conformX " , & CEntityTemplate : : m_anchorConformX ) ;
AddClassProperty ( L " traits.anchor.conformZ " , & CEntityTemplate : : m_anchorConformZ ) ;
2006-07-13 05:29:33 +02:00
AddClassProperty ( L " traits.vision.los " , & CEntityTemplate : : m_los ) ;
2006-08-08 05:45:13 +02:00
AddClassProperty ( L " traits.vision.permanent " , & CEntityTemplate : : m_visionPermanent ) ;
2006-07-16 21:32:48 +02:00
AddClassProperty ( L " traits.display.bars.enabled " , & CEntityTemplate : : m_barsEnabled ) ;
AddClassProperty ( L " traits.display.bars.offset " , & CEntityTemplate : : m_barOffset ) ;
AddClassProperty ( L " traits.display.bars.height " , & CEntityTemplate : : m_barHeight ) ;
AddClassProperty ( L " traits.display.bars.width " , & CEntityTemplate : : m_barWidth ) ;
AddClassProperty ( L " traits.display.bars.border " , & CEntityTemplate : : m_barBorder ) ;
2006-08-08 05:45:13 +02:00
AddClassProperty ( L " traits.display.bars.borderSize " , & CEntityTemplate : : m_barBorderSize ) ;
AddClassProperty ( L " traits.isTerritoryCentre " , & CEntityTemplate : : m_isTerritoryCentre ) ;
AddClassProperty ( L " traits.creation.foundation " , & CEntityTemplate : : m_foundation ) ;
AddClassProperty ( L " traits.creation.socket " , & CEntityTemplate : : m_socket ) ;
AddClassProperty ( L " traits.creation.territoryRestriction " , & CEntityTemplate : : m_territoryRestriction ) ;
2007-07-14 08:15:19 +02:00
AddClassProperty ( L " traits.creation.buildingLimitCategory " , & CEntityTemplate : : m_buildingLimitCategory ) ;
2006-07-13 05:29:33 +02:00
CJSComplex < CEntityTemplate > : : ScriptingInit ( " EntityTemplate " ) ;
2004-05-22 01:46:16 +02:00
}
2004-10-07 21:23:35 +02:00
// Script-bound functions
2006-07-13 05:29:33 +02:00
JSObject * CEntityTemplate : : GetScriptExecContext ( IEventTarget * target )
2005-04-22 09:12:55 +02:00
{
return ( target - > GetScriptExecContext ( target ) ) ;
}
2007-05-29 21:01:21 +02:00
CStr CEntityTemplate : : ToString ( JSContext * UNUSED ( cx ) , uintN UNUSED ( argc ) , jsval * UNUSED ( argv ) )
2004-10-07 21:23:35 +02:00
{
2006-05-14 00:11:46 +02:00
if ( m_player = = 0 )
2007-05-29 21:01:21 +02:00
return " [object EntityTemplate: " + CStr ( m_Tag ) + " base] " ;
2006-05-14 00:11:46 +02:00
else
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
return " [object EntityTemplate: " + CStr ( m_Tag ) + " for player " + CStr ( ( unsigned ) m_player - > GetPlayerID ( ) ) + " ] " ;
2004-11-07 22:30:47 +01:00
}