Some general questions about flags, enum, and PushMission

General Tso

Panzer General
Joined
Oct 12, 2007
Messages
1,548
Location
U. S. of A.
These questions are all concerned with using Unit:PushMission from within Lua. First question: are the values required for the passed variable "flags" available in Lua? I couldn't find them. I found this mess in CvAStar.h

Code:
// PATHFINDER FLAGS
// WARNING: Some of these flags are passed into the unit mission and stored in the missions iFlags member.
//          Because the mission's iFlags are sharing space with the pathfinder flags, we currently have mission
//			modifier flags listed below that really don't have anything to do with the pathfinder.
//			A fix for this would be to have the mission contain separate pathfinder and modifier flags.
// These flags determine plots that can be entered
#define MOVE_TERRITORY_NO_UNEXPLORED		(0x00000001)
#define MOVE_TERRITORY_NO_ENEMY				(0x00000002)
#define MOVE_IGNORE_STACKING                (0x00000004)
// These two tell about presence of enemy units
#define MOVE_UNITS_IGNORE_DANGER			(0x00000008)
#define MOVE_UNITS_THROUGH_ENEMY			(0x00000010)
// Used for human player movement
#define MOVE_DECLARE_WAR					(0x00000020)
// Used for AI group attacks (??). Not really a pathfinder flag
#define MISSION_MODIFIER_DIRECT_ATTACK		(0x00000040)
#define MISSION_MODIFIER_NO_DEFENSIVE_SUPPORT (0x00000100)

#define MOVE_MAXIMIZE_EXPLORE				(0x00000080)
//
// Used for route information
#define MOVE_ANY_ROUTE					    (0x80000000) // because we're passing in the player number as well as the route flag
#define MOVE_ROUTE_ALLOW_UNEXPLORED			(0x40000000) // When searching for a route, allow the search to use unrevealed plots
//#define MOVE_NON_WAR_ROUTE				 // we're passing the player id and other flags in as well. This flag checks to see if it can get from point to point without going into territory with a team we're at war with

I manually copied the values over to Lua and some of them seems to work the way they should. Is there some way to use these values in Lua in the same way that most other things are done (GameDefines, GameInfo etc.)? I can keep using my current method but I'm uncomfortable with the fact that future changes within the dll could cause problems. My other question in regards to these values is: Since Lua doesn't have a Bitwise Or, can I just add these values together to get the same result (sorry for the basic question - it's been a lot of years since I last went to math class :lol:). So basically since these are single bit values, if I use something like (MOVE_ANY_ROUTE + MOVE_IGNORE_STACKING) would that be the same as (MOVE_ANY_ROUTE | MOVE_IGNORE_STACKING)?

Next up is a question about the passed variable "missionAI" (again for PushMission). It looks like it takes an Enum value that's defined in CvEnums.h but I can't find it anywhere in Lua. So again I manually created the values. Am I missing something - are they available to Lua? One other basic question. Here's the Enum for missionAI:

Code:
enum MissionAITypes		
{
	NO_MISSIONAI = -1,

	MISSIONAI_SHADOW,
	MISSIONAI_GROUP,
	MISSIONAI_LOAD_ASSAULT,
	MISSIONAI_LOAD_SETTLER,
	MISSIONAI_LOAD_SPECIAL,
	MISSIONAI_GUARD_CITY,
	MISSIONAI_GUARD_RESOURCE,
	MISSIONAI_GUARD_TRADE_NET,
	MISSIONAI_GUARD_SPY,
	MISSIONAI_ATTACK_SPY,
	MISSIONAI_SPREAD,
	MISSIONAI_CONSTRUCT,
	MISSIONAI_HURRY,
	MISSIONAI_GREAT_WORK,
	MISSIONAI_EXPLORE,
	MISSIONAI_BLOCKADE,
	MISSIONAI_PILLAGE,
	MISSIONAI_FOUND,
	MISSIONAI_BUILD,
	MISSIONAI_ASSAULT,
	MISSIONAI_CARRIER,
	MISSIONAI_PICKUP,

	NUM_MISSIONAI_TYPES
};

If I need to manually assign the values would it be correct to assume that MISSIONAI_SHADOW = 0, MISSIONAI_GROUP = 1, MISSIONAI_LOAD_ASSAULT = 2, ....
 
These questions are all concerned with using Unit:PushMission from within Lua.

First question: are the values required for the passed variable "flags" available in Lua? Is there some way to use these values in Lua in the same way that most other things are done (GameDefines, GameInfo etc.)? I can keep using my current method but I'm uncomfortable with the fact that future changes within the dll could cause problems.
They are C++ #defines, so unless the devs have created the equivalent Lua structures/entries (which, if they have, I then wouldn't expect them to be #defines), they arn't. General rule of thumb - unless the devs needed something from the C++ DLL in the UI or a DLC scenario don't expect it to be available in Lua - and there are no PushMission() calls in any of the game core Lua files. You're going to have to create your own Lua values for these flags. I wouldn't worry too much about their values changing. You could possibly get some new ones added, but I doubt anyone would want to be responsible for breaking the route finding code by changing one of these!

My other question in regards to these values is: Since Lua doesn't have a Bitwise Or, can I just add these values together to get the same result
For these particular values you can. But as you're going to have to create your own values for them, personally I'd create any combos you need as well, eg

Code:
local MOVE_TERRITORY_NO_UNEXPLORED = 1
local MOVE_TERRITORY_NO_ENEMY = 2
local MOVE_IGNORE_STACKING = 4
local MOVE_TERRITORY_NO_ENEMY_AND_IGNORE_STACKING = 6
local MOVE_UNITS_IGNORE_DANGER = 8

Next up is a question about the passed variable "missionAI" (again for PushMission). It looks like it takes an Enum value that's defined in CvEnums.h but I can't find it anywhere in Lua. So again I manually created the values. Am I missing something - are they available to Lua?
No (a simple test with FireTuner shows that MissionAITypes.MISSIONAI_SHADOW is undefined)

One other basic question. If I need to manually assign the values would it be correct to assume that MISSIONAI_SHADOW = 0, MISSIONAI_GROUP = 1, MISSIONAI_LOAD_ASSAULT = 2, ....
Yes, that's how enums work - see http://www.learncpp.com/cpp-tutorial/45-enumerated-types/
 
Thank you for all of the great answers whoward69!

Now if I could just get the ranged units to act in a consistent manor I'll be happy. :lol:
 
Woo Hoo! I got the the little ranged buggers to act in a somewhat intelligent manner. I used Mr. Howard's PlotRingIterator in combination with Plot:CanSeePlot() to find the proper destinations for ranged units (relative to their target). I'm using my code in a very limited situation - the beginning of a game and it's assumed that the city is not protected. But with that said the AI now captures a city over 75% of the time with minimal units. Such as 3 or 4 warriors and 2 catapults. Now I need to work on making it a little more flexible.
 
Back
Top Bottom