Bazaar developer reference

CvUnit::canDoCommand(CommandTypes, int, int, bool, bool) const

Defined in
CvUnit.cpp, line 2379
Class
CvUnit
Hook name
CivHooks::CvUnit_canDoCommand
Lua events
GameEvents.CanDoCommand

Hooks

static bool BeforeCvUnit_canDoCommand(const CvUnit* self, CommandTypes eCommand, int iData1, int iData2, bool bTestVisible, bool bTestBusy, bool& result);static void AfterCvUnit_canDoCommand(const CvUnit* self, CommandTypes eCommand, int iData1, int iData2, bool bTestVisible, bool bTestBusy, bool& result);static bool ReplaceCvUnit_canDoCommand(bool (*original)(const CvUnit*, CommandTypes, int, int, bool, bool), const CvUnit* self, CommandTypes eCommand, int iData1, int iData2, bool bTestVisible, bool bTestBusy);CivRegisterBefore<CivHooks::CvUnit_canDoCommand>(host, &BeforeCvUnit_canDoCommand);CivRegisterAfter<CivHooks::CvUnit_canDoCommand>(host, &AfterCvUnit_canDoCommand);CivRegisterReplace<CivHooks::CvUnit_canDoCommand>(host, &ReplaceCvUnit_canDoCommand);

Code

2379bool CvUnit::canDoCommand(CommandTypes eCommand, int iData1, int iData2, bool bTestVisible, bool bTestBusy) const2380{2381	VALIDATE_OBJECT23822383	if(bTestBusy && IsBusy())2384	{2385		return false;2386	}23872388	if (GetAutomateType() == AUTOMATE_TRADE)2389		return false;	// No commands for this type.2390		2391#if defined(MOD_EVENTS_COMMAND)2392	if (MOD_EVENTS_COMMAND) {2393		if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_CanDoCommand, getOwner(), GetID(), eCommand, iData1, iData2, getX(), getY(), bTestVisible) == GAMEEVENTRETURN_FALSE) {2394			return false;2395		}2396	}2397#endif23982399	switch(eCommand)2400	{2401	case COMMAND_PROMOTION:2402		if(canPromote((PromotionTypes)iData1, iData2))2403		{2404			return true;2405		}2406		break;24072408	case COMMAND_UPGRADE:2409		if(CanUpgradeRightNow(bTestVisible))2410		{2411			return true;2412		}2413		break;24142415	case COMMAND_AUTOMATE:2416		if(CanAutomate((AutomateTypes)iData1, bTestVisible))2417		{2418			return true;2419		}2420		break;24212422	case COMMAND_WAKE:2423		if(!IsAutomated() && isWaiting())2424		{2425			return true;2426		}2427		break;24282429	case COMMAND_CANCEL:2430	case COMMAND_CANCEL_ALL:2431		if(!IsAutomated() && (GetLengthMissionQueue() > 0))2432		{2433			return true;2434		}2435		break;24362437	case COMMAND_STOP_AUTOMATION:2438		if(IsAutomated())2439		{2440			return true;2441		}2442		break;24432444	case COMMAND_DELETE:2445		if(canScrap(bTestVisible))2446		{2447			return true;2448		}2449		break;24502451	case COMMAND_GIFT:2452		if(canGift(bTestVisible))2453		{2454			return true;2455		}2456		break;24572458	case COMMAND_HOTKEY:2459		return true;2460		break;24612462	default:2463		CvAssert(false);2464		break;2465	}24662467	return false;2468}

Calls

Called by