[+] Ability to get info about active unit
This commit is contained in:
parent
615bf481a0
commit
3d7052c9b3
2 changed files with 20 additions and 1 deletions
|
@ -299,12 +299,15 @@ UStrInt GetComponent(const CUnit &unit, int index, EnumVariable e, int t)
|
|||
case VariableName:
|
||||
if (index == GIVERESOURCE_INDEX) {
|
||||
val.type = USTRINT_STR;
|
||||
val.i = unit.Type->GivesResource;
|
||||
val.s = DefaultResourceNames[unit.Type->GivesResource].c_str();
|
||||
} else if (index == CARRYRESOURCE_INDEX) {
|
||||
val.type = USTRINT_STR;
|
||||
val.i = unit.CurrentResource;
|
||||
val.s = DefaultResourceNames[unit.CurrentResource].c_str();
|
||||
} else {
|
||||
val.type = USTRINT_STR;
|
||||
val.i = index;
|
||||
val.s = UnitTypeVar.VariableNameLookup[index];
|
||||
}
|
||||
break;
|
||||
|
@ -359,9 +362,11 @@ UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e, int t)
|
|||
case VariableName:
|
||||
if (index == GIVERESOURCE_INDEX) {
|
||||
val.type = USTRINT_STR;
|
||||
val.i = type.GivesResource;
|
||||
val.s = DefaultResourceNames[type.GivesResource].c_str();
|
||||
} else {
|
||||
val.type = USTRINT_STR;
|
||||
val.i = index;
|
||||
val.s = UnitTypeVar.VariableNameLookup[index];
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "animation.h"
|
||||
#include "commands.h"
|
||||
#include "construct.h"
|
||||
#include "interface.h"
|
||||
#include "map.h"
|
||||
#include "pathfinder.h"
|
||||
#include "player.h"
|
||||
|
@ -125,7 +126,16 @@ static int CclResourcesMultiBuildersMultiplier(lua_State *l)
|
|||
*/
|
||||
static CUnit *CclGetUnit(lua_State *l)
|
||||
{
|
||||
return &UnitManager.GetSlotUnit(LuaToNumber(l, -1));
|
||||
int num = LuaToNumber(l, -1);
|
||||
if (num == -1) {
|
||||
if (!Selected.empty()) {
|
||||
return Selected[0];
|
||||
} else if (UnitUnderCursor) {
|
||||
return UnitUnderCursor;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return &UnitManager.GetSlotUnit(num);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1043,6 +1053,10 @@ static int CclGetUnitVariable(lua_State *l)
|
|||
lua_pushstring(l, unit->Type->Ident.c_str());
|
||||
} else if (!strcmp(value, "ResourcesHeld")) {
|
||||
lua_pushnumber(l, unit->ResourcesHeld);
|
||||
} else if (!strcmp(value, "GiveResourceType")) {
|
||||
lua_pushnumber(l, unit->Type->GivesResource);
|
||||
} else if (!strcmp(value, "CurrentResource")) {
|
||||
lua_pushnumber(l, unit->CurrentResource);
|
||||
} else if (!strcmp(value, "Name")) {
|
||||
lua_pushstring(l, unit->Type->Name.c_str());
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue