mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 03:14:00 +02:00
Tested areCellsFree function
This commit is contained in:
@@ -449,6 +449,7 @@ namespace Game {
|
|||||||
|
|
||||||
luaScript.registerFunction(getStartLocation, "startLocation");
|
luaScript.registerFunction(getStartLocation, "startLocation");
|
||||||
luaScript.registerFunction(getIsUnitAlive, "isUnitAlive");
|
luaScript.registerFunction(getIsUnitAlive, "isUnitAlive");
|
||||||
|
luaScript.registerFunction(areCellsFree, "areCellsFree");
|
||||||
luaScript.registerFunction(getUnitPosition, "unitPosition");
|
luaScript.registerFunction(getUnitPosition, "unitPosition");
|
||||||
luaScript.registerFunction(setUnitPosition, "setUnitPosition");
|
luaScript.registerFunction(setUnitPosition, "setUnitPosition");
|
||||||
luaScript.registerFunction(forceSetUnitPosition, "forceSetUnitPosition");
|
luaScript.registerFunction(forceSetUnitPosition, "forceSetUnitPosition");
|
||||||
@@ -2452,6 +2453,16 @@ namespace Game {
|
|||||||
return world->getStartLocation(factionIndex);
|
return world->getStartLocation(factionIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ScriptManager::areCellsFree(Vec2i pos, int size, int field) {
|
||||||
|
if (SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled)
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugLUA,
|
||||||
|
"In [%s::%s Line: %d]\n",
|
||||||
|
extractFileFromDirectoryPath(__FILE__).
|
||||||
|
c_str(), __FUNCTION__, __LINE__);
|
||||||
|
|
||||||
|
return world->areCellsFree(pos, size, static_cast<Field>(field));
|
||||||
|
}
|
||||||
|
|
||||||
Vec2i
|
Vec2i
|
||||||
ScriptManager::getUnitPosition(int unitId) {
|
ScriptManager::getUnitPosition(int unitId) {
|
||||||
@@ -4468,6 +4479,21 @@ namespace Game {
|
|||||||
return luaArguments.getReturnCount();
|
return luaArguments.getReturnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ScriptManager::areCellsFree(LuaHandle * luaHandle) {
|
||||||
|
LuaArguments
|
||||||
|
luaArguments(luaHandle);
|
||||||
|
|
||||||
|
try {
|
||||||
|
bool result = thisScriptManager->areCellsFree(luaArguments.getVec2i(-3), luaArguments.getInt(-2), luaArguments.getInt(-1));
|
||||||
|
luaArguments.returnInt(result ? 1 : 0);
|
||||||
|
} catch (const game_runtime_error & ex) {
|
||||||
|
error(luaHandle, &ex, __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ScriptManager::getUnitPosition(LuaHandle * luaHandle) {
|
ScriptManager::getUnitPosition(LuaHandle * luaHandle) {
|
||||||
LuaArguments
|
LuaArguments
|
||||||
|
@@ -629,6 +629,8 @@ namespace Game {
|
|||||||
getStartLocation(int factionIndex);
|
getStartLocation(int factionIndex);
|
||||||
Vec2i
|
Vec2i
|
||||||
getUnitPosition(int unitId);
|
getUnitPosition(int unitId);
|
||||||
|
bool
|
||||||
|
areCellsFree(Vec2i pos, int size, int field);
|
||||||
int
|
int
|
||||||
getUnitFaction(int unitId);
|
getUnitFaction(int unitId);
|
||||||
const string
|
const string
|
||||||
@@ -960,6 +962,7 @@ namespace Game {
|
|||||||
static int
|
static int
|
||||||
getLastCreatedUnitId(LuaHandle * luaHandle);
|
getLastCreatedUnitId(LuaHandle * luaHandle);
|
||||||
|
|
||||||
|
static int areCellsFree(LuaHandle * luaHandle);
|
||||||
static int
|
static int
|
||||||
setUnitPosition(LuaHandle * luaHandle);
|
setUnitPosition(LuaHandle * luaHandle);
|
||||||
static int
|
static int
|
||||||
|
@@ -842,6 +842,16 @@ namespace Game {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Map::isAproxFreeCell(const Vec2i &pos, Field field) const {
|
||||||
|
for (int i = 0; i <= MAX_MAP_FACTIONCOUNT; i++) {
|
||||||
|
if (!isAproxFreeCell(pos, field, i))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("[%s] Line: %d returning false\n",__FUNCTION__,__LINE__);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Map::isFreeCells(const Vec2i & pos, int size, Field field, bool buildingsOnly) const {
|
bool Map::isFreeCells(const Vec2i & pos, int size, Field field, bool buildingsOnly) const {
|
||||||
for (int i = pos.x; i < pos.x + size; ++i) {
|
for (int i = pos.x; i < pos.x + size; ++i) {
|
||||||
for (int j = pos.y; j < pos.y + size; ++j) {
|
for (int j = pos.y; j < pos.y + size; ++j) {
|
||||||
@@ -877,6 +887,16 @@ namespace Game {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Map::isAproxFreeCells(const Vec2i &pos, int size, Field field) const {
|
||||||
|
for (int i = 0; i <= MAX_MAP_FACTIONCOUNT; i++) {
|
||||||
|
if (!isAproxFreeCells(pos, size, field, i))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("[%s] Line: %d returning false\n",__FUNCTION__,__LINE__);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Map::canMorph(const Vec2i &pos, const Unit *currentUnit, const UnitType *targetUnitType) const {
|
bool Map::canMorph(const Vec2i &pos, const Unit *currentUnit, const UnitType *targetUnitType) const {
|
||||||
Field field = targetUnitType->getField();
|
Field field = targetUnitType->getField();
|
||||||
const UnitType *ut = targetUnitType;
|
const UnitType *ut = targetUnitType;
|
||||||
@@ -1321,9 +1341,6 @@ namespace Game {
|
|||||||
bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,
|
bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,
|
||||||
const Vec2i &testPos) const {
|
const Vec2i &testPos) const {
|
||||||
assert(ut != NULL);
|
assert(ut != NULL);
|
||||||
if (ut == NULL) {
|
|
||||||
throw game_runtime_error("ut == NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInside(testPos) && isInsideSurface(toSurfCoords(testPos))) {
|
if (isInside(testPos) && isInsideSurface(toSurfCoords(testPos))) {
|
||||||
Cell *testCell = getCell(testPos);
|
Cell *testCell = getCell(testPos);
|
||||||
@@ -1372,9 +1389,7 @@ namespace Game {
|
|||||||
|
|
||||||
if (ut->hasCellMap() == false || ut->getCellMapCell(i, j, unit->getModelFacing())) {
|
if (ut->hasCellMap() == false || ut->getCellMapCell(i, j, unit->getModelFacing())) {
|
||||||
if (getCell(currPos)->getUnit(field) != NULL && getCell(currPos)->getUnit(field) != unit) {
|
if (getCell(currPos)->getUnit(field) != NULL && getCell(currPos)->getUnit(field) != unit) {
|
||||||
// TT: is this ok ?
|
//if unit tries to move into a cell where another unit resides cancel the move command
|
||||||
//If unit tries to move into a cell where another unit resides
|
|
||||||
// cancel the move command
|
|
||||||
if (unit->getCurrSkill() != NULL &&
|
if (unit->getCurrSkill() != NULL &&
|
||||||
unit->getCurrSkill()->getClass() == scMove) {
|
unit->getCurrSkill()->getClass() == scMove) {
|
||||||
canPutInCell = false;
|
canPutInCell = false;
|
||||||
|
@@ -429,9 +429,11 @@ namespace Game {
|
|||||||
//free cells
|
//free cells
|
||||||
bool isFreeCell(const Vec2i &pos, Field field, bool buildingsOnly = false) const;
|
bool isFreeCell(const Vec2i &pos, Field field, bool buildingsOnly = false) const;
|
||||||
bool isFreeCellOrHasUnit(const Vec2i &pos, Field field, const Unit *unit) const;
|
bool isFreeCellOrHasUnit(const Vec2i &pos, Field field, const Unit *unit) const;
|
||||||
|
bool isAproxFreeCell(const Vec2i &pos, Field field) const;
|
||||||
bool isAproxFreeCell(const Vec2i &pos, Field field, int teamIndex) const;
|
bool isAproxFreeCell(const Vec2i &pos, Field field, int teamIndex) const;
|
||||||
bool isFreeCells(const Vec2i &pos, int size, Field field, bool buildingsOnly = false) const;
|
bool isFreeCells(const Vec2i &pos, int size, Field field, bool buildingsOnly = false) const;
|
||||||
bool isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const;
|
bool isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const;
|
||||||
|
bool isAproxFreeCells(const Vec2i &pos, int size, Field field) const;
|
||||||
bool isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const;
|
bool isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const;
|
||||||
bool canMorph(const Vec2i &pos, const Unit *currentUnit, const UnitType *targetUnitType) const;
|
bool canMorph(const Vec2i &pos, const Unit *currentUnit, const UnitType *targetUnitType) const;
|
||||||
//bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing);
|
//bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing);
|
||||||
|
@@ -1804,6 +1804,10 @@ namespace Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool World::areCellsFree(Vec2i pos, int size, Field field) {
|
||||||
|
return map.isFreeCells(pos, size, field);
|
||||||
|
}
|
||||||
|
|
||||||
Vec2i World::getUnitPosition(int unitId) {
|
Vec2i World::getUnitPosition(int unitId) {
|
||||||
Unit* unit = findUnitById(unitId);
|
Unit* unit = findUnitById(unitId);
|
||||||
if (unit == NULL) {
|
if (unit == NULL) {
|
||||||
|
@@ -314,6 +314,7 @@ namespace Game {
|
|||||||
void giveResource(const string &resourceName, int factionIndex, int amount);
|
void giveResource(const string &resourceName, int factionIndex, int amount);
|
||||||
int getResourceAmount(const string &resourceName, int factionIndex);
|
int getResourceAmount(const string &resourceName, int factionIndex);
|
||||||
Vec2i getStartLocation(int factionIndex);
|
Vec2i getStartLocation(int factionIndex);
|
||||||
|
bool areCellsFree(Vec2i pos, int size, Field field);
|
||||||
Vec2i getUnitPosition(int unitId);
|
Vec2i getUnitPosition(int unitId);
|
||||||
void setUnitPosition(int unitId, Vec2i pos, bool forceSet = false);
|
void setUnitPosition(int unitId, Vec2i pos, bool forceSet = false);
|
||||||
|
|
||||||
|
@@ -57,7 +57,6 @@ namespace Shared {
|
|||||||
static const int MAX_MAP_CELL_HEIGHT = 20;
|
static const int MAX_MAP_CELL_HEIGHT = 20;
|
||||||
static const int DEFAULT_MAP_CELL_HEIGHT = 10;
|
static const int DEFAULT_MAP_CELL_HEIGHT = 10;
|
||||||
|
|
||||||
static const int MIN_MAP_FACTIONCOUNT = 1;
|
|
||||||
static const int MAX_MAP_FACTIONCOUNT = 10;
|
static const int MAX_MAP_FACTIONCOUNT = 10;
|
||||||
static const int DEFAULT_MAP_FACTIONCOUNT = 8;
|
static const int DEFAULT_MAP_FACTIONCOUNT = 8;
|
||||||
|
|
||||||
|
@@ -645,9 +645,9 @@ namespace Shared {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MapPreview::resetFactions(int maxPlayers) {
|
void MapPreview::resetFactions(int maxPlayers) {
|
||||||
if (maxPlayers < MIN_MAP_FACTIONCOUNT || maxPlayers > MAX_MAP_FACTIONCOUNT) {
|
if (maxPlayers < 0 || maxPlayers > MAX_MAP_FACTIONCOUNT) {
|
||||||
char szBuf[8096] = "";
|
char szBuf[8096] = "";
|
||||||
snprintf(szBuf, 8096, "Max Players must be in the range %d-%d", MIN_MAP_FACTIONCOUNT, MAX_MAP_FACTIONCOUNT);
|
snprintf(szBuf, 8096, "Max Players must be in the range %d-%d", 0, MAX_MAP_FACTIONCOUNT);
|
||||||
throw game_runtime_error(szBuf);
|
throw game_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user