trouble with UnitDef.h
Moderators: hoijui, Moderators
- sanderbakkes
- Posts: 27
- Joined: 16 Aug 2006, 15:49
trouble with UnitDef.h
i extended the UnitDef structure with an "int value;". that int is initialised in CUnitDefHandler::CUnitDefHandler(void) of UnitDefHandler.cpp. it compiles and works nicely for my purpose.
yet, when using other already pre-compiled AI .dlls, these AI's are not working properly anymore. KAI crashes instantly, and AAI is idling.
anyone who has got a clue to why a new UnitDef is not accepted?
i compile in VStudio.7 an use default struct-alignment.
yet, when using other already pre-compiled AI .dlls, these AI's are not working properly anymore. KAI crashes instantly, and AAI is idling.
anyone who has got a clue to why a new UnitDef is not accepted?
i compile in VStudio.7 an use default struct-alignment.
- sanderbakkes
- Posts: 27
- Joined: 16 Aug 2006, 15:49
- sanderbakkes
- Posts: 27
- Joined: 16 Aug 2006, 15:49
AF was so kind to suggest the following. perhaps it will help you too:
AF wrote:The problem ehre is not with howto extend UnitDef but the very action fo extending it.
Instead take a different approach and create a class such as for example
That class will store arbitrary float values and your UnitDef pointer, and thus repeat the function and map container for integers strings etc you need to add, or just add member functions for single objects..... If you need to extend UnitDef just extend this class instead.Code: Select all
class CUnitDefinition{ public: CUnitDefinition(UnitDef* u){ ud = u; } virtual ~CUnitDefinition(){} UnitDef* GetEngineDef(){ return ud; } float GetValue(std::string value, float default=1.0f){ if(values.find(value) != values.end()) return fvalues[value]; else return default; } void SetValue(std::string value, float number){ fvalues[value] = number; } std::map<std::string,float>& GetFloatValues(){ return &fvalues; private: const UnitDef* ud; std::map<std::string,float> fvalues; };
- sanderbakkes
- Posts: 27
- Joined: 16 Aug 2006, 15:49
let me then please ask the DEVs to provide more 'space' in the UnitDef. i can only imagine that all AI developers have a need for some redundant properties they can use for their own implementation.Dragon45 wrote:Why not just recompile all AIs? I don't see the problem; if the extension is significant it'll have to be added in next spring ver with new AIs anyhway; if its not significant, noone will care what your special AI modification is...
i for one would love to implement a scoring function, and it makes sense to include a unit.weight for that in the UnitDef structure (though other means are possible). i am confident similar scenarios apply to other AI developers.
why can't you just use something like
in your AI?
or even
if you don't mind copying the entire unitdef (as opposed to just storing a pointer to it).
Code: Select all
class CExtendedUnitDef {
CUnitDef* ud;
float weight;
int aiclass;
// etc.
};
or even
Code: Select all
class CExtendedUnitDef : public CUnitDef {
float weight;
int aiclass;
};
Thats what i did, and what i bet the other AIs do too (in one shape or another) theres no need to change the interface to store additional unit info...Tobi wrote:why can't you just use something like
in your AI?Code: Select all
class CExtendedUnitDef { CUnitDef* ud; float weight; int aiclass; // etc. };