Move common code to new func TriggerMatchUnitType.
This changes the behavior of CclGetNumUnitsAt a little. It now checks unit->Constructed even if unittype is a category rather than an individual type. This does not affect the bundled maps because the only use of GetNumUnitsAt is in campaigns/swindler/level01.sms, which searches for "unit-assault", and assault units do not appear on the map before they are fully trained.
This commit is contained in:
parent
c84ac83904
commit
9ac3a69fc3
3 changed files with 33 additions and 27 deletions
|
@ -127,6 +127,32 @@ const CUnitType *TriggerGetUnitType(lua_State *l)
|
|||
return CclGetUnitType(l);
|
||||
}
|
||||
|
||||
/**
|
||||
** Check whether a unit is of the specified type or in the specified
|
||||
** category.
|
||||
**
|
||||
** @param unit Unit to examine; must not be NULL.
|
||||
** @param triggerUnitType As returned by TriggerGetUnitType.
|
||||
**
|
||||
** @return true if the unit matches the type or category, else false.
|
||||
*/
|
||||
bool TriggerMatchUnitType(const CUnit *unit, const CUnitType *triggerUnitType)
|
||||
{
|
||||
if (triggerUnitType == ANY_UNIT) {
|
||||
return true;
|
||||
} else if (triggerUnitType == ALL_UNITS) {
|
||||
// FIXME: ALL_UNITS should be "sum of units and buildings",
|
||||
// but that currently means just ANY_UNIT.
|
||||
return true;
|
||||
} else if (triggerUnitType == ALL_FOODUNITS) {
|
||||
return !unit->Type->Building;
|
||||
} else if (triggerUnitType == ALL_BUILDINGS) {
|
||||
return unit->Type->Building;
|
||||
} else {
|
||||
return unit->Type == triggerUnitType;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
-- Conditions
|
||||
--------------------------------------------------------------------------*/
|
||||
|
@ -231,11 +257,7 @@ static int CclGetNumUnitsAt(lua_State *l)
|
|||
//
|
||||
// Check unit type
|
||||
//
|
||||
// FIXME: ALL_UNITS
|
||||
if (unittype == ANY_UNIT ||
|
||||
(unittype == ALL_FOODUNITS && !unit->Type->Building) ||
|
||||
(unittype == ALL_BUILDINGS && unit->Type->Building) ||
|
||||
(unittype == unit->Type && !unit->Constructed)) {
|
||||
if (TriggerMatchUnitType(unit, unittype) && !unit->Constructed) {
|
||||
//
|
||||
// Check the player
|
||||
//
|
||||
|
@ -310,11 +332,7 @@ static int CclIfNearUnit(lua_State *l)
|
|||
//
|
||||
// Check unit type
|
||||
//
|
||||
// FIXME: ALL_UNITS
|
||||
if (unittype == ANY_UNIT ||
|
||||
(unittype == ALL_FOODUNITS && !unit->Type->Building) ||
|
||||
(unittype == ALL_BUILDINGS && unit->Type->Building) ||
|
||||
(unittype == unit->Type)) {
|
||||
if (TriggerMatchUnitType(unit, unittype)) {
|
||||
//
|
||||
// Check the player
|
||||
//
|
||||
|
@ -402,11 +420,7 @@ static int CclIfRescuedNearUnit(lua_State *l)
|
|||
//
|
||||
// Check unit type
|
||||
//
|
||||
// FIXME: ALL_UNITS
|
||||
if (unittype == ANY_UNIT ||
|
||||
(unittype == ALL_FOODUNITS && !unit->Type->Building) ||
|
||||
(unittype == ALL_BUILDINGS && unit->Type->Building) ||
|
||||
(unittype == unit->Type)) {
|
||||
if (TriggerMatchUnitType(unit, unittype)) {
|
||||
//
|
||||
// Check the player
|
||||
//
|
||||
|
|
|
@ -93,6 +93,7 @@ extern TriggerDataType TriggerData;
|
|||
|
||||
extern int TriggerGetPlayer(lua_State *l);/// get player number.
|
||||
extern const CUnitType *TriggerGetUnitType(lua_State *l); /// get the unit-type
|
||||
extern bool TriggerMatchUnitType(const CUnit *unit, const CUnitType *triggerUnitType);
|
||||
extern void TriggersEachCycle(void); /// test triggers
|
||||
|
||||
extern void TriggerCclRegister(void); /// Register ccl features
|
||||
|
|
|
@ -863,10 +863,7 @@ static int CclOrderUnit(lua_State *l)
|
|||
if (unit->Destroyed || unit->Orders[0]->Action == UnitActionDie) {
|
||||
continue;
|
||||
}
|
||||
if (unittype == ANY_UNIT ||
|
||||
(unittype == ALL_FOODUNITS && !unit->Type->Building) ||
|
||||
(unittype == ALL_BUILDINGS && unit->Type->Building) ||
|
||||
unittype == unit->Type) {
|
||||
if (TriggerMatchUnitType(unit, unittype)) {
|
||||
if (plynr == -1 || plynr == unit->Player->Index) {
|
||||
if (!strcmp(order,"move")) {
|
||||
CommandMove(unit, (dx1 + dx2) / 2, (dy1 + dy2) / 2, 1);
|
||||
|
@ -918,10 +915,7 @@ static int CclKillUnit(lua_State *l)
|
|||
|
||||
for (; j >= 0; --j) {
|
||||
unit = table[j];
|
||||
if (unittype == ANY_UNIT ||
|
||||
(unittype == ALL_FOODUNITS && !unit->Type->Building) ||
|
||||
(unittype == ALL_BUILDINGS && unit->Type->Building) ||
|
||||
unittype == unit->Type) {
|
||||
if (TriggerMatchUnitType(unit, unittype)) {
|
||||
LetUnitDie(unit);
|
||||
lua_pushboolean(l, 1);
|
||||
return 1;
|
||||
|
@ -986,10 +980,7 @@ static int CclKillUnitAt(lua_State *l)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (unittype == ANY_UNIT ||
|
||||
(unittype == ALL_FOODUNITS && !unit->Type->Building) ||
|
||||
(unittype == ALL_BUILDINGS && unit->Type->Building) ||
|
||||
unittype==unit->Type)
|
||||
if (TriggerMatchUnitType(unit, unittype))
|
||||
{
|
||||
if (plynr == -1 || plynr == unit->Player->Index) {
|
||||
LetUnitDie(unit);
|
||||
|
|
Loading…
Add table
Reference in a new issue