PDA

View Full Version : Extending enumerators


Misiur
20/02/2013, 01:12 PM
I have list of all vehicles, and vehicle types. Basically each vehicle has assigned vehicle type specific data, and additionaly vehicle specific values. So currently I'm doing it like:

#define MAX_TYPES 20

enum(<<= 1){
TYPE_TRUCK,
TYPE_SPECIAL,
TYPE_TRAILER
}

enum CType {
modelId,
price,
maxFuel,
maxLoad,
type
}

enum CMeta {
currentFuel,
bool:engine,
typePointerIndex
}

static CarType[MAX_TYPES][CType];
static Cars[MAX_VEHICLES][CMeta];

stock CreateCar(tid, Float:x, Float:y, Float:z, Float:rot, c1 = -1, c2 =- 2) {
new vid = CreateVehicle(CarType[tid][modelId], x, z, y, c1, c2, 0) - 1;
Cars[vid][currentFuel] = CarType[tid][maxFuel];
Cars[vid][engine] = false;
Cars[vid][typePointerIndex] = tid;
return vid;
}

public OnGameModeInit() {
CarType[0][modelId] = 435;
CarType[0][price] = 1000;
CarType[0][maxFuel] = 150;
CarType[0][maxLoad] = 4000;
CarType[0][type] = TYPE_SPECIAL | TYPE_TRAILER;

new car = CreateCar(0, 0.0, 0.0, 0.0, 0.0);
return 1;
}

Now when I need to fetch something from type info for specific car, I have to do something like
stock GetMaxFuel(cid) {
return cid >= 0 && cid <= MAX_VEHICLES - 1 ? CarType[Cars[cid][typePointerIndex]][maxFuel] : 0;
}
This is really not handy when you have to type all that stuff. I know I could nest enum inside enum, but this way I'll quickly run out of heap/stack because type enum would be created for every vehicle. Is there some easier, more lightweight way of extending enumerators? So I could do
Cars[0][maxFuel]; or something not as painful as current option?