trouble with UnitDef.h

trouble with UnitDef.h

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
sanderbakkes
Posts: 27
Joined: 16 Aug 2006, 15:49

trouble with UnitDef.h

Post by sanderbakkes »

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.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Because CUnitDef is passed around to AIs, ie. modifying it in any way breaks ABI compatibility, so you need to recompile AIs.
User avatar
sanderbakkes
Posts: 27
Joined: 16 Aug 2006, 15:49

Post by sanderbakkes »

makes sense, but still i have to extend that structure 8)

anyone knowns how to hack into the UnitDef without breaking compatibility?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

There is none. You must recompile the AIs.
User avatar
sanderbakkes
Posts: 27
Joined: 16 Aug 2006, 15:49

Post by sanderbakkes »

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

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;
};
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.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

The devs would kill you for adding an unnecessary class. Spring needs less hacky code, not more.
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

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...
User avatar
sanderbakkes
Posts: 27
Joined: 16 Aug 2006, 15:49

Post by sanderbakkes »

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...
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.

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.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

why can't you just use something like

Code: Select all

class CExtendedUnitDef {
  CUnitDef* ud;
  float weight;
  int aiclass;
  // etc.
};
in your AI?

or even

Code: Select all

class CExtendedUnitDef : public CUnitDef {
  float weight;
  int aiclass;
};
if you don't mind copying the entire unitdef (as opposed to just storing a pointer to it).
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Tobi wrote:why can't you just use something like

Code: Select all

class CExtendedUnitDef {
  CUnitDef* ud;
  float weight;
  int aiclass;
  // etc.
};
in your AI?
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...
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

I'm not sure he's writing an AI, perhaps he's implementing a new feature into the engine itself?
Post Reply

Return to “AI”