bool IsBuilding(map_id mapID);
bool IsVehicle(map_id mapID);
bool IsUnit(map_id mapID);
// Returns true if the map_id is a building.
bool IsBuilding(map_id mapType)
{
switch (mapType)
{
case mapCommonOreMine:
case mapRareOreMine:
case mapGuardPost:
case mapLightTower:
case mapCommonStorage:
case mapRareStorage:
case mapForum:
case mapCommandCenter:
case mapMHDGenerator:
case mapResidence:
case mapRobotCommand:
case mapTradeCenter:
case mapBasicLab:
case mapMedicalCenter:
case mapNursery:
case mapSolarPowerArray:
case mapRecreationFacility:
case mapUniversity:
case mapAgridome:
case mapDIRT:
case mapGarage:
case mapMagmaWell:
case mapMeteorDefense:
case mapGeothermalPlant:
case mapArachnidFactory:
case mapConsumerFactory:
case mapStructureFactory:
case mapVehicleFactory:
case mapStandardLab:
case mapAdvancedLab:
case mapObservatory:
case mapReinforcedResidence:
case mapAdvancedResidence:
case mapCommonOreSmelter:
case mapSpaceport:
case mapRareOreSmelter:
case mapGORF:
case mapTokamak:
return true;
}
return false;
}
// Returns true if the building is a vehicle.
bool IsVehicle(map_id mapType)
{
switch (mapType)
{
case mapCargoTruck:
case mapConVec:
case mapSpider:
case mapScorpion:
case mapLynx:
case mapPanther:
case mapTiger:
case mapRoboSurveyor:
case mapRoboMiner:
case mapGeoCon:
case mapScout:
case mapRoboDozer:
case mapEvacuationTransport:
case mapRepairVehicle:
case mapEarthworker:
return true;
}
return false;
}
// Returns true if the map_id is either a vehicle or a building.
bool IsUnit(map_id mapType)
{
return IsBuilding(mapType) || IsVehicle(mapType);
}
#pragma once
#include <Outpost2DLL/Outpost2DLL.h>
#include <array>
// Details of map_id enum are not needed here so just forward declare it
// This way we don't need to include Outpost2DLL.h (which speeds up the compile)
//enum map_id;
bool IsEdenOnlyWeapon(map_id weaponType);
bool IsPlymouthOnlyWeapon(map_id weaponType);
bool IsCommonWeapon(map_id weaponType);
bool IsEdenWeapon(map_id weaponType);
bool IsPlymouthWeapon(map_id weaponType);
bool IsBuilding(map_id mapID);
bool IsVehicle(map_id mapID);
bool IsUnit(map_id mapID);
extern std::array<map_id, 38> BuildingTypes;
extern std::array<map_id, 15> VehicleTypes;
#include "ColonyType.h"
//#include <Outpost2DLL/Outpost2DLL.h> // Main Outpost 2 header to interface with the game
// Returns true only if the weapon is Eden specific
bool IsEdenOnlyWeapon(map_id weaponType)
{
// Use switch case fallthrough (no break statement)
switch(weaponType)
{
case mapLaser:
case mapRailGun:
case mapThorsHammer:
case mapAcidCloud:
return true; // Yep
}
return false; // Nope
}
// Returns true only if the weapon is Plymouth specific
bool IsPlymouthOnlyWeapon(map_id weaponType)
{
// Use switch case fallthrough (no break statement)
switch(weaponType)
{
case mapMicrowave:
case mapStickyfoam:
case mapRPG:
case mapESG:
case mapSupernova:
case mapSupernova2:
case mapEnergyCannon:
return true; // Yep
}
return false; // Nope
}
// Returns true if weapon can be built by both colonies
bool IsCommonWeapon(map_id weaponType)
{
// Use switch case fallthrough (no break statement)
switch(weaponType)
{
case mapEMP:
case mapStarflare:
case mapStarflare2:
case mapNormalUnitExplosion:
return true; // Yep
}
return false; // Nope
}
// Returns true if Eden can build the weapon
bool IsEdenWeapon(map_id weaponType)
{
return (IsCommonWeapon(weaponType) || IsEdenOnlyWeapon(weaponType));
}
// Returns true if Plymouth can build the weapon
bool IsPlymouthWeapon(map_id weaponType)
{
return (IsCommonWeapon(weaponType) || IsPlymouthOnlyWeapon(weaponType));
}
// Returns true if the map_id is a building.
bool IsBuilding(map_id mapType)
{
return std::find(BuildingTypes.begin(), BuildingTypes.end(), mapType) != BuildingTypes.end();
}
// Returns true if the building is a vehicle.
bool IsVehicle(map_id mapType)
{
return std::find(VehicleTypes.begin(), VehicleTypes.end(), mapType) != VehicleTypes.end();
}
// Returns true if the map_id is either a vehicle or a building.
bool IsUnit(map_id mapType)
{
return IsBuilding(mapType) || IsVehicle(mapType);
}
std::array<map_id, 38> BuildingTypes{
mapCommonOreMine,
mapRareOreMine,
mapGuardPost,
mapLightTower,
mapCommonStorage,
mapRareStorage,
mapForum,
mapCommandCenter,
mapMHDGenerator,
mapResidence,
mapRobotCommand,
mapTradeCenter,
mapBasicLab,
mapMedicalCenter,
mapNursery, mapSolarPowerArray,
mapRecreationFacility,
mapUniversity,
mapAgridome,
mapDIRT,
mapGarage,
mapMagmaWell,
mapMeteorDefense,
mapGeothermalPlant,
mapArachnidFactory,
mapConsumerFactory,
mapStructureFactory,
mapVehicleFactory,
mapStandardLab,
mapAdvancedLab,
mapObservatory,
mapReinforcedResidence,
mapAdvancedResidence,
mapCommonOreSmelter,
mapSpaceport,
mapRareOreSmelter,
mapGORF,
mapTokamak
};
std::array<map_id, 15> VehicleTypes{
mapCargoTruck,
mapConVec,
mapSpider,
mapScorpion,
mapLynx,
mapPanther,
mapTiger,
mapRoboSurveyor,
mapRoboMiner,
mapGeoCon,
mapScout,
mapRoboDozer,
mapEvacuationTransport,
mapRepairVehicle,
mapEarthworker
};
bool IsVehicle(map_id mapType)
{
return ((mapType >= mapCargoTruck) || (mapType <= mapEarthworker));
}
mapAcidCloud, // 3B Eden
mapEMP, // 3C Both
mapLaser, // 3D Eden
mapMicrowave, // 3E Plymouth
mapRailGun, // 3F Eden
mapRPG, // 40 Plymouth
mapStarflare, // 41 Vehicle Starflare Both
mapSupernova, // 42 Vehicle Supernova Plymouth
mapStarflare2, // 43 GuardPost Starflare Both
mapSupernova2, // 44 GuardPost Supernova Plymouth
mapNormalUnitExplosion, // 45 Both
mapESG, // 46 Plymouth
mapStickyfoam, // 47 Plymouth
mapThorsHammer, // 48 Eden
mapEnergyCannon, // 49 Plymouth
#pragma once
#include <Outpost2DLL/Outpost2DLL.h>
// Returns true if the map_id is a weapon native only to Eden
bool IsEdenOnlyWeapon(map_id weaponType);
// Returns true if the map_id is a weapon native only to Plymouth
bool IsPlymouthOnlyWeapon(map_id weaponType);
// Returns true if the map_id is a weapon that is native to both colonies
bool IsCommonWeapon(map_id weaponType);
// Returns true if the map_id is a weapon that can be built by Eden
bool IsEdenWeapon(map_id weaponType);
// Returns true if the map_id is a weapon that can be built by Plymouth
bool IsPlymouthWeapon(map_id weaponType);
// Returns true if the map_id is a building that is native only to Eden
bool IsEdenOnlyBuilding(map_id buildingType);
// Returns true if the map_id is a building that is native only to Plymouth
bool IsPlymouthOnlyBuilding(map_id buildingType);
// Returns true if the map_id is a building that Eden can construct
bool IsEdenBuilding(map_id buildingType);
// Returns true if the map_id is a building that Plymouth can construct
bool IsPlymouthBuilding(map_id buildingType);
// Returns true if the map_id is a vehicle that is native to Eden only
bool IsEdenOnlyVehicle(map_id vehicleType);
// Returns true if the map_id is a vehicle that is native to Plymouth only
bool IsPlymouthOnlyVehicle(map_id vehicleType);
// Returns true if the map_id is a vehicle that can be built by Eden
bool IsEdenVehicle(map_id vehicleType);
// Returns true if the map_id is a vehicle that can be built by Plymouth
bool IsPlymouthVehicle(map_id vehicleType);
// Returns true if the map_id is a building
bool IsBuilding(map_id mapID);
// Returns true if the map_id is a vehicle
bool IsVehicle(map_id mapID);
// Returns true if the map_id is either a vehicle or a building
bool IsUnit(map_id mapID);
#include "ColonyType.h"
bool IsEdenOnlyWeapon(map_id weaponType)
{
// Use switch case fallthrough (no break statement)
switch(weaponType)
{
case mapLaser:
case mapRailGun:
case mapThorsHammer:
case mapAcidCloud:
return true;
}
return false;
}
bool IsPlymouthOnlyWeapon(map_id weaponType)
{
// Use switch case fallthrough (no break statement)
switch(weaponType)
{
case mapMicrowave:
case mapStickyfoam:
case mapRPG:
case mapESG:
case mapSupernova:
case mapSupernova2:
case mapEnergyCannon:
return true;
}
return false;
}
bool IsCommonWeapon(map_id weaponType)
{
// Use switch case fallthrough (no break statement)
switch(weaponType)
{
case mapEMP:
case mapStarflare:
case mapStarflare2:
case mapNormalUnitExplosion:
return true;
}
return false;
}
bool IsEdenWeapon(map_id weaponType)
{
return (IsCommonWeapon(weaponType) || IsEdenOnlyWeapon(weaponType));
}
bool IsPlymouthWeapon(map_id weaponType)
{
return (IsCommonWeapon(weaponType) || IsPlymouthOnlyWeapon(weaponType));
}
bool IsEdenOnlyBuilding(map_id buildingType)
{
switch (buildingType)
{
case mapMagmaWell:
case mapMeteorDefense:
case mapGeothermalPlant:
case mapConsumerFactory:
case mapObservatory:
case mapAdvancedResidence:
return true;
}
return false;
}
bool IsPlymouthOnlyBuilding(map_id buildingType)
{
switch (buildingType)
{
case mapForum:
case mapMHDGenerator:
case mapArachnidFactory:
case mapReinforcedResidence:
return true;
}
return false;
}
bool IsEdenBuilding(map_id buildingType)
{
return IsBuilding(buildingType) && !IsPlymouthOnlyBuilding(buildingType);
}
bool IsPlymouthBuilding(map_id buildingType)
{
return IsBuilding(buildingType) && !IsEdenOnlyBuilding(buildingType);
}
bool IsEdenOnlyVehicle(map_id vehicleType)
{
switch (vehicleType)
{
case mapGeoCon:
case mapRepairVehicle:
return true;
}
return false;
}
bool IsPlymouthOnlyVehicle(map_id vehicleType)
{
switch (vehicleType)
{
case mapSpider:
case mapScorpion:
return true;
}
return false;
}
bool IsEdenVehicle(map_id vehicleType)
{
return IsVehicle(vehicleType) && !IsPlymouthOnlyVehicle(vehicleType);
}
bool IsPlymouthVehicle(map_id vehicleType)
{
return IsVehicle(vehicleType) && !IsEdenOnlyVehicle(vehicleType);
}
bool IsBuilding(map_id buildingType)
{
// mapCommonOreMine and mapTokamak are respectively the first and last building indices
return ((buildingType >= map_id::mapCommonOreMine && buildingType <= map_id::mapTokamak));
}
bool IsVehicle(map_id vehicleType)
{
// mapCargoTruck and mapEarthworker are respectively the first and last building indices
return ((vehicleType >= map_id::mapCargoTruck) && (vehicleType <= map_id::mapEarthworker));
}
bool IsUnit(map_id unitType)
{
return IsBuilding(unitType) || IsVehicle(unitType);
}
I think you mean && and not || in the sample you provided.*Facepalm* You're right.
I'll sit on this post for a day or two before posting to the repository in case anyone has better naming conventions or implementation suggestions.You can commit now, and then in a few days later make another commit to update the names. There's often a lot of clarity added when updates like that are done as separate commits, and reasons for the changes are added to the commit message.
bool IsCommonBuilding(map_id buildingType)
{
return IsBuilding(buildingType) && !IsEdenOnlyBuilding(buildingType) && !IsPlymouthOnlyBuilding(buildingType);
}
bool IsCommonVehicle(map_id vehicleType)
{
return IsVehicle(vehicleType) && !IsEdenOnlyVehicle(vehicleType) && !IsPlymouthOnlyVehicle(vehicleType);
}
IsUnitID
IsVehicleID
IsCommonBuildingID
IsPlymouthOnlyBuildingID
IsEdenVehicleID
... etc.
I kept comments since the original author had put comments on their functions.According to "svn blame" (or "svn praise" for the glass-is-half-full types), you added those comments in revision 1074.
// Returns true if and only if the weapon if Eden specific
bool IsEdenOnlyWeapon(map_id weaponType)
{
....
}
#include <Outpost2DLL/Outpost2DLL.h>
//enum map_id;
I believe this change was related to the addition of the BuildingTypes and VehicleTypes variables (extern std::array<map_id, N>), which were later removed. It may make sense to revert the #include and forward declare changes.
...
I suspect the include was added to the header file to avoiding a compilation error, when it would have made more sense to add the include to the implementation file. Moving the include to the implementation file can have compile time benefits, as there is less cascading of includes.
The second thing I noticed was the IsWeapon function could make use of first and last indices, rather than calling 3 separate functions to test for each of the values in that range individually. Basically use the same idea behind IsBuilding, and IsVehicle.
bool IsWeapon(map_id mapID)
{
// mapAcidCloud and mapEnergyCannon are respectively the first and last weapon indices
return (mapID >= map_id::mapAcidCloud && mapID <= map_id::mapEnergyCannon);
}
I'm having trouble understanding when it is more appropriate to put an include in the .cpp file versus the .h file
enum EnumName;
void SomeFunction(EnumName parameter); // Doesn't need to see full enum. Actual enum values are not a concern here
void SomeFunction(EnumName parameter = enumValueName); // Full include needed, otherwise enumValueName won't be seen
struct SomeStruct {
int field1;
int field2;
};
void SomeFunction(SomeStruct* structParameter); // Forward declare fine, it's just a pointer to some struct, the details of which are not important here
void SomeFunction(SomeStruct& structParameter); // Forward declare fine, same reason
SomeStruct structInstance; // Full include needed, as space must be allocated for this struct, which can't be calculated without knowing all the fields
class SomeClass {
void MemberFunction();
};
void SomeMethod(SomeClass* pointerToClass) // Forward declare fine for this
{
// ...
pointerToClass->MemberFunction(); // Full include needed for this, otherwise compiler won't know MemberFunction exists for this class type
}
void CreatePreGameDialogue(DialgueData* data); // Just one function, no header file
// ...
{
// ...
CreatePreGameDialogue(&data); // Access external function here
}
// Declare the StartLocation array in BaseData.cpp. (So it is available in this file).
extern StartLocation startLocation[];
Export int InitProc()
{
// Randomize starting locations
RandomizeList(4, startLocation); // Randomize (first) 4 starting locations (Note: 4 is hardcoded here)
//RandomizeList(AutoSize(startLocation)); // Need compile time array size info for this to work
}