[+] Add ability to get unit reference and CUnitType::TileWidth and CUnitType::TileHeight in Lua
[*] GetUnitsAroundUnit now supports 3 parameter for getting all units in range
This commit is contained in:
parent
8d9874a330
commit
fafcad4518
4 changed files with 24 additions and 2 deletions
|
@ -13,6 +13,7 @@ $#include "sound.h"
|
|||
$#include "sound_server.h"
|
||||
$#include "ui.h"
|
||||
$#include "unit.h"
|
||||
$#include "unit_manager.h"
|
||||
$#include "unittype.h"
|
||||
$#include "video.h"
|
||||
$#include "widgets.h"
|
||||
|
|
|
@ -36,6 +36,13 @@ class CPreference
|
|||
std::string SF2Soundfont;
|
||||
};
|
||||
|
||||
class CUnitManager
|
||||
{
|
||||
CUnit &GetSlotUnit(int index) const;
|
||||
};
|
||||
|
||||
CUnitManager UnitManager; /// Unit manager
|
||||
|
||||
CPreference Preference;
|
||||
|
||||
CUnit *GetUnitUnderCursor();
|
||||
|
|
|
@ -10,6 +10,9 @@ class CUnitType
|
|||
int GivesResource;
|
||||
int Supply;
|
||||
int Demand;
|
||||
|
||||
int TileWidth;
|
||||
int TileHeight;
|
||||
};
|
||||
|
||||
CUnitType *UnitTypeByIdent(const std::string ident);
|
||||
|
|
|
@ -956,14 +956,25 @@ static int CclGetUnits(lua_State *l)
|
|||
*/
|
||||
static int CclGetUnitsAroundUnit(lua_State *l)
|
||||
{
|
||||
LuaCheckArgs(l, 2);
|
||||
const int nargs = lua_gettop(l);
|
||||
if (nargs != 2 && nargs != 3) {
|
||||
LuaError(l, "incorrect argument\n");
|
||||
}
|
||||
|
||||
const int slot = LuaToNumber(l, 1);
|
||||
const CUnit &unit = UnitManager.GetSlotUnit(slot);
|
||||
const int range = LuaToNumber(l, 2);
|
||||
bool allUnits = false;
|
||||
if (nargs == 3) {
|
||||
allUnits = LuaToBoolean(l, 3);
|
||||
}
|
||||
lua_newtable(l);
|
||||
std::vector<CUnit *> table;
|
||||
SelectAroundUnit(unit, range, table, HasSamePlayerAs(*unit.Player));
|
||||
if (allUnits) {
|
||||
SelectAroundUnit(unit, range, table, HasNotSamePlayerAs(Players[PlayerNumNeutral]));
|
||||
} else {
|
||||
SelectAroundUnit(unit, range, table, HasSamePlayerAs(*unit.Player));
|
||||
}
|
||||
size_t n = 0;
|
||||
for (size_t i = 0; i < table.size(); ++i) {
|
||||
if (table[i]->IsAliveOnMap()) {
|
||||
|
|
Loading…
Reference in a new issue