Skip to content

Commit

Permalink
Merge pull request #516 from Wargus/clean_up_cclgetpos
Browse files Browse the repository at this point in the history
Use `CclGetPos` overload with `vec2T` when possible.
  • Loading branch information
Jarod42 authored Sep 27, 2023
2 parents 15b9a69 + 9e79246 commit 251e0f1
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ bool COrder_Attack::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x, &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);

} else if (value == "amove-tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->attackMovePos.x, &this->attackMovePos.y);
CclGetPos(l, &this->attackMovePos);
lua_pop(l, 1);

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool COrder_Board::ParseSpecificData(lua_State *l, int &j, std::string_view valu
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool COrder_Build::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else if (value == "type") {
++j;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_defend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool COrder_Defend::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_explore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool COrder_Explore::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_follow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool COrder_Follow::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool COrder_Move::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_patrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool COrder_Patrol::ParseSpecificData(lua_State *l,
if (value == "patrol") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->WayPoint.x , &this->WayPoint.y);
CclGetPos(l, &this->WayPoint);
lua_pop(l, 1);
} else if (value == "waiting-cycle") {
++j;
Expand All @@ -100,7 +100,7 @@ bool COrder_Patrol::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_repair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool COrder_Repair::ParseSpecificData(lua_State *l, int &j, std::string_view val
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ bool COrder_Resource::ParseSpecificData(lua_State *l,
} else if (value == "res-pos") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->Resource.Pos.x , &this->Resource.Pos.y);
CclGetPos(l, &this->Resource.Pos);
lua_pop(l, 1);
} else if (value == "state") {
++j;
Expand All @@ -313,7 +313,7 @@ bool COrder_Resource::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_spellcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool COrder_SpellCast::ParseSpecificData(lua_State *l,
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_unload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool COrder_Unload::ParseSpecificData(lua_State *l, int &j, std::string_view val
} else if (value == "tile") {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/game/trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ static int CclGetNumUnitsAt(lua_State *l)

Vec2i minPos;
Vec2i maxPos;
CclGetPos(l, &minPos.x, &minPos.y, 3);
CclGetPos(l, &maxPos.x, &maxPos.y, 4);
CclGetPos(l, &minPos, 3);
CclGetPos(l, &maxPos, 4);

if (minPos.x > maxPos.x) {
std::swap(minPos.x, maxPos.x);
Expand Down
2 changes: 1 addition & 1 deletion src/map/script_tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void CTileset::parse(lua_State *l)
} else if (value == "image") {
this->ImageFile = LuaToString(l, j);
} else if (value == "size") {
CclGetPos(l, &this->pixelTileSize.x, &this->pixelTileSize.y, j);
CclGetPos(l, &this->pixelTileSize, j);
} else if (value == "slots") {
// must be deferred to later, after the size is parsed
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/missile/script_missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void MissileType::Load(lua_State *l)
if (value == "File") {
file = LuaToString(l, -1);
} else if (value == "Size") {
CclGetPos(l, &this->size.x, &this->size.y);
CclGetPos(l, &this->size);
} else if (value == "Frames") {
this->SpriteFrames = LuaToNumber(l, -1);
} else if (value == "Flip") {
Expand Down Expand Up @@ -254,11 +254,11 @@ static int CclMissile(lua_State *l)
if (value == "type") {
type = &MissileTypeByIdent(LuaToString(l, j + 1));
} else if (value == "pos") {
CclGetPos(l, &position.x, &position.y, j + 1);
CclGetPos(l, &position, j + 1);
} else if (value == "origin-pos") {
CclGetPos(l, &source.x, &source.y, j + 1);
CclGetPos(l, &source, j + 1);
} else if (value == "goal") {
CclGetPos(l, &destination.x, &destination.y, j + 1);
CclGetPos(l, &destination, j + 1);
} else if (value == "local") {
Assert(type);
missile = MakeLocalMissile(*type, position, destination);
Expand Down Expand Up @@ -380,8 +380,8 @@ static int CclCreateMissile(lua_State *l)
const std::string_view name = LuaToString(l, 1);
const MissileType &mtype = MissileTypeByIdent(name);
PixelPos startpos, endpos;
CclGetPos(l, &startpos.x, &startpos.y, 2);
CclGetPos(l, &endpos.x, &endpos.y, 3);
CclGetPos(l, &startpos, 2);
CclGetPos(l, &endpos, 3);

const int sourceUnitId = LuaToNumber(l, 4);
const int destUnitId = LuaToNumber(l, 5);
Expand Down
6 changes: 3 additions & 3 deletions src/stratagus/script_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CPlayer::Load(lua_State *l)
}
}
} else if (value == "start") {
CclGetPos(l, &this->StartPos.x, &this->StartPos.y, j + 1);
CclGetPos(l, &this->StartPos, j + 1);
} else if (value == "resources") {
if (!lua_istable(l, j + 1)) {
LuaError(l, "incorrect argument");
Expand Down Expand Up @@ -359,8 +359,8 @@ static int CclChangeUnitsOwner(lua_State *l)

Vec2i pos1;
Vec2i pos2;
CclGetPos(l, &pos1.x, &pos1.y, 1);
CclGetPos(l, &pos2.x, &pos2.y, 2);
CclGetPos(l, &pos1, 1);
CclGetPos(l, &pos2, 2);
if (pos1.x > pos2.x) {
std::swap(pos1.x, pos2.x);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/script_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ static CContentType *CclParseContent(lua_State *l)
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
std::string_view key = LuaToString(l, -2);
if (key == "Pos") {
CclGetPos(l, &pos.x, &pos.y);
CclGetPos(l, &pos);
} else if (key == "More") {
Assert(lua_istable(l, -1));
lua_rawgeti(l, -1, 1); // Method name
Expand Down Expand Up @@ -807,7 +807,7 @@ static void ParseButtonStyleProperties(lua_State *l, ButtonStyleProperties *p)
lua_pop(l, 1);
}
} else if (value == "TextPos") {
CclGetPos(l, &p->TextPos.x, &p->TextPos.y);
CclGetPos(l, &p->TextPos);
} else if (value == "TextAlign") {
value = LuaToString(l, -1);
if (value == "Center") {
Expand Down
22 changes: 11 additions & 11 deletions src/unit/script_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ void PathFinderInput::Load(lua_State *l)
++i;
if (tag == "unit-size") {
lua_rawgeti(l, -1, i);
CclGetPos(l, &this->unitSize.x, &this->unitSize.y);
CclGetPos(l, &this->unitSize);
lua_pop(l, 1);
} else if (tag == "goalpos") {
lua_rawgeti(l, -1, i);
CclGetPos(l, &this->goalPos.x, &this->goalPos.y);
CclGetPos(l, &this->goalPos);
lua_pop(l, 1);
} else if (tag == "goal-size") {
lua_rawgeti(l, -1, i);
CclGetPos(l, &this->goalSize.x, &this->goalSize.y);
CclGetPos(l, &this->goalSize);
lua_pop(l, 1);
} else if (tag == "minrange") {
this->minRange = LuaToNumber(l, -1, i);
Expand Down Expand Up @@ -390,12 +390,12 @@ static int CclUnit(lua_State *l)
lua_pop(l, 1);
} else if (value == "tile") {
lua_rawgeti(l, 2, j + 1);
CclGetPos(l, &unit->tilePos.x , &unit->tilePos.y, -1);
CclGetPos(l, &unit->tilePos, -1);
lua_pop(l, 1);
unit->Offset = Map.getIndex(unit->tilePos);
} else if (value == "seen-tile") {
lua_rawgeti(l, 2, j + 1);
CclGetPos(l, &unit->Seen.tilePos.x , &unit->Seen.tilePos.y, -1);
CclGetPos(l, &unit->Seen.tilePos, -1);
lua_pop(l, 1);
} else if (value == "stats") {
unit->Stats = &type->Stats[LuaToNumber(l, 2, j + 1)];
Expand Down Expand Up @@ -691,7 +691,7 @@ static int CclMoveUnit(lua_State *l)
lua_pop(l, 1);

Vec2i ipos;
CclGetPos(l, &ipos.x, &ipos.y, 2);
CclGetPos(l, &ipos, 2);

if (!unit->Removed) {
unit->Remove(unit->Container);
Expand All @@ -707,7 +707,7 @@ static int CclMoveUnit(lua_State *l)
}

if (nargs == 3) {
CclGetPos(l, &ipos.x, &ipos.y, 3);
CclGetPos(l, &ipos, 3);
unit->IX = ipos.x;
unit->IY = ipos.y;
}
Expand Down Expand Up @@ -774,7 +774,7 @@ static int CclCreateUnit(lua_State *l)
}
lua_pop(l, 1);
Vec2i ipos;
CclGetPos(l, &ipos.x, &ipos.y, 3);
CclGetPos(l, &ipos, 3);

lua_pushvalue(l, 2);
const int playerno = TriggerGetPlayer(l);
Expand Down Expand Up @@ -1087,8 +1087,8 @@ static int CclKillUnitAt(lua_State *l)
}
Vec2i pos1;
Vec2i pos2;
CclGetPos(l, &pos1.x, &pos1.y, 4);
CclGetPos(l, &pos2.x, &pos2.y, 5);
CclGetPos(l, &pos1, 4);
CclGetPos(l, &pos2, 5);
if (pos1.x > pos2.x) {
std::swap(pos1.x, pos2.x);
}
Expand Down Expand Up @@ -1608,7 +1608,7 @@ static int CclTurnTowardsLocation(lua_State *l)

Vec2i dir;
if (lua_istable(l, 2)) {
CclGetPos(l, &dir.x, &dir.y, 2);
CclGetPos(l, &dir, 2);
dir = dir - unit->tilePos;
} else {
lua_pushvalue(l, 2);
Expand Down
2 changes: 1 addition & 1 deletion src/unit/script_unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static int CclDefineUnitType(lua_State *l)
}
for (int m = 0; m < UnitSides; ++m) {
lua_rawgeti(l, -1, m + 1);
CclGetPos(l, &type->MissileOffsets[m][k].x, &type->MissileOffsets[m][k].y);
CclGetPos(l, &type->MissileOffsets[m][k]);
lua_pop(l, 1);
}
lua_pop(l, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/unit/unit_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static int CclDefineSprites(lua_State *l)
} else if (key == "File") {
deco.File = LuaToString(l, -1);
} else if (key == "Offset") {
CclGetPos(l, &deco.HotPos.x, &deco.HotPos.y);
CclGetPos(l, &deco.HotPos);
} else if (key == "Size") {
CclGetPos(l, &deco.Width, &deco.Height);
} else { // Error.
Expand Down
2 changes: 1 addition & 1 deletion src/video/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static int CclDefineCursor(lua_State *l)
} else if (value == "File") {
file = LuaToString(l, -1);
} else if (value == "HotSpot") {
CclGetPos(l, &hotpos.x, &hotpos.y);
CclGetPos(l, &hotpos);
} else if (value == "Size") {
CclGetPos(l, &w, &h);
} else if (value == "Rate") {
Expand Down

0 comments on commit 251e0f1

Please sign in to comment.