Adding a new Array, having troubles.

An explicit cast is when you put a type inside parentheses. It is needed here to convert from int to UnitAITypes:

Code:
UnitAITypes eUnitAI = [B](UnitAITypes)[/B] GC.getUnitInfo(eLoopUnit).getDefaultUnitAIType();
 
UnitAITypes, BuildingTypes, UnitTypes, etc are called enumerations. They are a data type based on an int. A normal int can take on any value that fits in the size specified by the C++ compiler, typically 32 bits. An enumeration is an int with some values specified ahead of time like constants but with compile-time checking.

The compiler will automatically convert between the various numeric data types, but to convert to an enumeration requires an explicit cast. The reason for this is that enumerations are used to enforce data integrity. If a function requires a UnitTypes value, the compiler won't allow a BuildingTypes value unless you override it using a cast.

All of the CvFooInfo class functions take and return ints instead of enumerations. CvUnitInfo.getDefaultUnitAIType() returns an int even though it is designed to be a valid UnitAITypes value. You need to cast it to tell the compiler you know what you're doing. I don't know why the CvInfos were built that way.
 
UnitAITypes, BuildingTypes, UnitTypes, etc are called enumerations. They are a data type based on an int. A normal int can take on any value that fits in the size specified by the C++ compiler, typically 32 bits. An enumeration is an int with some values specified ahead of time like constants but with compile-time checking.

I see. I didn't know that.

The compiler will automatically convert between the various numeric data types, but to convert to an enumeration requires an explicit cast. The reason for this is that enumerations are used to enforce data integrity. If a function requires a UnitTypes value, the compiler won't allow a BuildingTypes value unless you override it using a cast.

Okay. A lot of the code is making much more sense now that I'm actually learning it.

Thanks. I got this up in running. The main reason I wanted this is for a building that would double the production rate of ICBM's. :lol:
 
Top Bottom