MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Script_General_IsEnemy

Function Script_General_IsEnemy

src/script/general.c:371–387  ·  view source on GitHub ↗

* Check if a Unit/Structure is an enemy. * * Stack: 1 - An encoded index. * * @param script The script engine to operate on. * @return Zero if and only if the Unit/Structure is friendly. */

Source from the content-addressed store, hash-verified

369 * @return Zero if and only if the Unit/Structure is friendly.
370 */
371uint16 Script_General_IsEnemy(ScriptEngine *script)
372{
373 uint8 houseID;
374 uint16 index;
375
376 index = STACK_PEEK(1);
377
378 if (!Tools_Index_IsValid(index)) return 0;
379
380 houseID = (g_scriptCurrentUnit != NULL) ? Unit_GetHouseID(g_scriptCurrentUnit) : g_scriptCurrentObject->houseID;
381
382 switch (Tools_Index_GetType(index)) {
383 case IT_UNIT: return (Unit_GetHouseID(Tools_Index_GetUnit(index)) != houseID) ? 1 : 0;
384 case IT_STRUCTURE: return (Tools_Index_GetStructure(index)->o.houseID != houseID) ? 1 : 0;
385 default: return 0;
386 }
387}
388
389/**
390 * Two sided function. If the parameter is an index, it will return 1 if and

Callers 1

Calls 5

Tools_Index_IsValidFunction · 0.85
Unit_GetHouseIDFunction · 0.85
Tools_Index_GetTypeFunction · 0.85
Tools_Index_GetUnitFunction · 0.85
Tools_Index_GetStructureFunction · 0.85

Tested by

no test coverage detected