Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #675

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,6 @@ static bool CheckLimit(const CUnit &unit, const CUnitType &type)
return isOk;
}


class AlreadyBuildingFinder
{
public:
AlreadyBuildingFinder(const CUnit &unit, const CUnitType &t) :
worker(&unit), type(&t) {}
bool operator()(const CUnit *const unit) const
{
return (!unit->Destroyed && unit->Type == type
&& (worker->Player == unit->Player || worker->IsAllied(*unit)));
}
CUnit *Find(const CMapField *const mf) const
{
auto it = ranges::find_if(mf->UnitCache, *this);
return it != mf->UnitCache.end() ? *it : nullptr;
}
private:
const CUnit *worker;
const CUnitType *type;
};

/**
** Check if the unit can build
**
Expand All @@ -285,25 +264,6 @@ CUnit *COrder_Build::CheckCanBuild(CUnit &unit)
if (ontop != nullptr) {
return ontop;
}
#if 0
/*
* FIXME: rb - CheckAlreadyBuilding should be somehow
* enabled/disable via game lua scripting
*/
CUnit *building = AlreadyBuildingFinder(unit, type).Find(Map.Field(pos));
if (building != nullptr) {
if (unit.CurrentOrder() == this) {
DebugPrint("%d: Worker [%d] is helping build: %s [%d]\n",
unit.Player->Index, unit.Slot,
building->Type->Name.c_str(),
building->Slot);

delete this; // Bad
unit.Orders[0] = COrder::NewActionRepair(unit, *building);
return nullptr;
}
}
#endif
// Some tries to build the building.
this->State++;
// To keep the load low, retry each 10 cycles
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static bool MoveRandomly(CUnit &unit)
if (!unit.JustMoved) {
return false;
}
int shift = Map.Tileset->getLogicalToGraphicalTileSizeShift();
int shift = Map.Tileset.getLogicalToGraphicalTileSizeShift();
if (!shift) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static void AiRemoveFromBuilt(PlayerAi &pai, const CUnitType &type)
// This could happen if an upgrade is ready, look for equivalent units.
const auto equivalents = AiFindUnitTypeEquiv(type);
for (int typeIndex : equivalents) {
if (AiRemoveFromBuilt2(pai, *UnitTypes[typeIndex])) {
if (AiRemoveFromBuilt2(pai, *getUnitTypes()[typeIndex])) {
return;
}
}
Expand Down Expand Up @@ -598,7 +598,7 @@ void AiReduceMadeInBuilt(PlayerAi &pai, const CUnitType &type)
const auto equivs = AiFindUnitTypeEquiv(type);

for (int typeIndex : equivs) {
if (AiReduceMadeInBuilt2(pai, *UnitTypes[typeIndex])) {
if (AiReduceMadeInBuilt2(pai, *getUnitTypes()[typeIndex])) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ai/ai_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ std::vector<int> AiFindAvailableUnitTypeEquiv(const CUnitType &unittype)
auto usableTypes = AiFindUnitTypeEquiv(unittype);
// 2 - Remove unavailable unittypes
ranges::erase_if(usableTypes, [&](int typeIndex) {
return !CheckDependByIdent(*AiPlayer->Player, UnitTypes[typeIndex]->Ident);
return !CheckDependByIdent(*AiPlayer->Player, getUnitTypes()[typeIndex]->Ident);
});
// 3 - Sort by level
ranges::sort(usableTypes, std::greater<>(), [](int index) {
return UnitTypes[index]->MapDefaultStat.Variables[PRIORITY_INDEX].Value;
return getUnitTypes()[index]->MapDefaultStat.Variables[PRIORITY_INDEX].Value;
});
return usableTypes;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ai/ai_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ static bool AiMakeUnit(CUnitType &typeToMake, const Vec2i &nearPos)

// Iterate them
for (int typeIndex : usableTypes) {
CUnitType &type = *UnitTypes[typeIndex];
CUnitType &type = *getUnitTypes()[typeIndex];
//
// Check if we have a place for building or a unit to build.
//
Expand Down Expand Up @@ -932,7 +932,7 @@ static bool AiAssignHarvesterFromUnit(CUnit &unit, int resource)

int exploremask = 0;

for (const CUnitType *type : UnitTypes) {
for (const CUnitType *type : getUnitTypes()) {
if (type && type->GivesResource == resource) {
switch (type->MoveType) {
case EMovement::Land: exploremask |= MapFieldLandUnit; break;
Expand Down
12 changes: 6 additions & 6 deletions src/ai/script_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static std::vector<CUnitType *> getUnitTypeFromString(std::string_view list)
std::vector<CUnitType *> res;

if (list == "*") {
return UnitTypes;
return getUnitTypes();
}
size_t begin = 1;
size_t end = list.find(",", begin);
Expand All @@ -101,7 +101,7 @@ static std::vector<CUnitType *> getReparableUnits()
{
std::vector<CUnitType *> res;

for (CUnitType *type : UnitTypes) {
for (CUnitType *type : getUnitTypes()) {
if (type->RepairHP > 0) {
res.push_back(type);
}
Expand All @@ -119,7 +119,7 @@ static std::vector<CUnitType *> getSupplyUnits()
std::vector<CUnitType *> res;
std::vector<CUnitType *> sorted_res;

for (CUnitType *type : UnitTypes) {
for (CUnitType *type : getUnitTypes()) {
if (type->DefaultStat.Variables[SUPPLY_INDEX].Value > 0) { //supply units are identified as being those with a default stat supply of 1 or more; so if a unit has a supply default stat of 0, but through an upgrade ends up having 1 or more supply, it won't be included here
res.push_back(type);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ static std::vector<CUnitType *> getRefineryUnits()
{
std::vector<CUnitType *> res;

for (CUnitType *type : UnitTypes) {
for (CUnitType *type : getUnitTypes()) {
if (type->GivesResource > 0 && type->BoolFlag[CANHARVEST_INDEX].value) {
res.push_back(type);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ static void InitAiHelper(AiHelper &aiHelper)
AiHelperInsert(aiHelper.Refinery(), i - 1, *type);
}
}
for (CUnitType *type : UnitTypes) {
for (CUnitType *type : getUnitTypes()) {
if (type->CanStore[i] > 0) {
/* HACK : we can't store TIME then use 0 as 1 */
AiHelperInsert(aiHelper.Depots(), i - 1, *type);
Expand Down Expand Up @@ -872,7 +872,7 @@ static int CclAiForce(lua_State *l)
}

// Use the equivalent unittype.
type = UnitTypes[UnitTypeEquivs[type->Slot]];
type = getUnitTypes()[UnitTypeEquivs[type->Slot]];

if (resetForce) {
// Append it.
Expand Down
50 changes: 25 additions & 25 deletions src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void EditTile(const Vec2i &pos, int tile)
{
Assert(Map.Info.IsPointOnMap(pos));

const CTileset &tileset = *Map.Tileset;
const CTileset &tileset = Map.Tileset;

CMapField &mf = *Map.Field(pos);

Expand Down Expand Up @@ -751,8 +751,8 @@ static bool forEachTileIconArea(std::function<bool(int,int,int,int,int)> forEach
int x2 = getButtonArea()[2];
int y2 = getButtonArea()[3];

int tileW = Map.Tileset->getPixelTileSize().x + 1;
int tileH = Map.Tileset->getPixelTileSize().y + 1;
int tileW = Map.Tileset.getPixelTileSize().x + 1;
int tileH = Map.Tileset.getPixelTileSize().y + 1;
int maxX = x2 - tileW;
int maxY = y2 - tileH;

Expand Down Expand Up @@ -797,15 +797,15 @@ static void DrawTileIcons()
const unsigned int tile = Editor.ShownTileTypes[i];

Map.TileGraphic->DrawFrameClip(tile, x, y);
Video.DrawRectangleClip(ColorGray, x, y, Map.Tileset->getPixelTileSize().x, Map.Tileset->getPixelTileSize().y);
Video.DrawRectangleClip(ColorGray, x, y, Map.Tileset.getPixelTileSize().x, Map.Tileset.getPixelTileSize().y);

if (i == Editor.SelectedTileIndex) {
Video.DrawRectangleClip(ColorGreen, x + 1, y + 1,
Map.Tileset->getPixelTileSize().x - 2, Map.Tileset->getPixelTileSize().y - 2);
Map.Tileset.getPixelTileSize().x - 2, Map.Tileset.getPixelTileSize().y - 2);
}
if (i == Editor.CursorTileIndex) {
Video.DrawRectangleClip(ColorWhite, x - 1, y - 1,
Map.Tileset->getPixelTileSize().x + 2, Map.Tileset->getPixelTileSize().y + 2);
Map.Tileset.getPixelTileSize().x + 2, Map.Tileset.getPixelTileSize().y + 2);
}

return true;
Expand Down Expand Up @@ -900,24 +900,24 @@ static void DrawMapCursor()

PixelPos screenPosIt;
for (int j = 0; j < TileCursorSize; ++j) {
screenPosIt.y = screenPos.y + j * Map.Tileset->getPixelTileSize().y;
screenPosIt.y = screenPos.y + j * Map.Tileset.getPixelTileSize().y;
if (screenPosIt.y >= UI.MouseViewport->GetBottomRightPos().y) {
break;
}
for (int i = 0; i < TileCursorSize; ++i) {
screenPosIt.x = screenPos.x + i * Map.Tileset->getPixelTileSize().x;
screenPosIt.x = screenPos.x + i * Map.Tileset.getPixelTileSize().x;
if (screenPosIt.x >= UI.MouseViewport->GetBottomRightPos().x) {
break;
}
Map.TileGraphic->DrawFrameClip(tile, screenPosIt.x, screenPosIt.y);
}
}
Video.DrawRectangleClip(ColorWhite, screenPos.x, screenPos.y, Map.Tileset->getPixelTileSize().x * TileCursorSize, Map.Tileset->getPixelTileSize().y * TileCursorSize);
Video.DrawRectangleClip(ColorWhite, screenPos.x, screenPos.y, Map.Tileset.getPixelTileSize().x * TileCursorSize, Map.Tileset.getPixelTileSize().y * TileCursorSize);
PopClipping();
} else {
PushClipping();
UI.MouseViewport->SetClipping();
Video.DrawRectangleClip(ColorWhite, screenPos.x, screenPos.y, Map.Tileset->getPixelTileSize().x, Map.Tileset->getPixelTileSize().y);
Video.DrawRectangleClip(ColorWhite, screenPos.x, screenPos.y, Map.Tileset.getPixelTileSize().x, Map.Tileset.getPixelTileSize().y);
if (Editor.State == EditorStateType::ElevationLevel) {
CLabel(GetGameFont()).DrawClip(screenPos.x + 2, screenPos.y + 1, Editor.SelectedElevationLevel);
}
Expand Down Expand Up @@ -959,7 +959,7 @@ static void DrawStartLocations()
#endif
DrawUnitType(*type, type->Sprite.get(), i, 0, startScreenPos);
} else { // Draw a cross
DrawCross(startScreenPos, Map.Tileset->getPixelTileSize(), Players[i].Color);
DrawCross(startScreenPos, Map.Tileset.getPixelTileSize(), Players[i].Color);
}
}
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ static void DrawEditorInfo()
CLabel(GetGameFont()).Draw(UI.StatusLine.TextX, UI.StatusLine.TextY - GetGameFont().getHeight() * 2, buf);

// Tile info
const CTileset &tileset = *Map.Tileset;
const CTileset &tileset = Map.Tileset;
const int index = tileset.findTileIndexByTile(mf.getGraphicTile());
Assert(index != -1);
const terrain_typeIdx baseTerrainIdx = tileset.tiles[index].tileinfo.BaseTerrain;
Expand Down Expand Up @@ -1227,7 +1227,7 @@ static void EditorCallbackButtonDown(unsigned button)
Editor.SelectedTileIndex = -1;

tile_index index = 0;
for (auto &currTile : Map.Tileset->tiles) {
for (auto &currTile : Map.Tileset.tiles) {
if (currTile.tile) {
Editor.ShownTileTypes.push_back(currTile.tile);
}
Expand All @@ -1236,7 +1236,7 @@ static void EditorCallbackButtonDown(unsigned button)
} else {
Editor.ShownTileTypes.clear();
Editor.SelectedTileIndex = -1;
Map.Tileset->fillSolidTiles(&Editor.ShownTileTypes);
Map.Tileset.fillSolidTiles(&Editor.ShownTileTypes);
}
return;
}
Expand Down Expand Up @@ -1665,10 +1665,10 @@ static bool EditorCallbackMouse_EditTileArea(const PixelPos &screenPos)
noHit = forEachTileIconArea([screenPos](int i, int x, int y, int w, int h) {
if (x < screenPos.x && screenPos.x < x + w && y < screenPos.y && screenPos.y < y + w) {
const int tile = Editor.ShownTileTypes[i];
const int32_t tileindex = Map.Tileset->findTileIndexByTile(tile);
const int32_t tileindex = Map.Tileset.findTileIndexByTile(tile);
Assert(tileindex != -1);
const terrain_typeIdx base = Map.Tileset->tiles[tileindex].tileinfo.BaseTerrain;
UI.StatusLine.Set(Map.Tileset->getTerrainName(base));
const terrain_typeIdx base = Map.Tileset.tiles[tileindex].tileinfo.BaseTerrain;
UI.StatusLine.Set(Map.Tileset.getTerrainName(base));
Editor.CursorTileIndex = i;
return false;
}
Expand Down Expand Up @@ -1722,7 +1722,7 @@ static void EditorCallbackMouse(const PixelPos &pos)
}
}
UI.MouseWarpPos = CursorStartScreenPos;
UI.MouseViewport->Set(tilePos, Map.Tileset->getPixelTileSize() / 2);
UI.MouseViewport->Set(tilePos, Map.Tileset.getPixelTileSize() / 2);
return;
}

Expand All @@ -1741,18 +1741,18 @@ static void EditorCallbackMouse(const PixelPos &pos)
// Scroll the map
if (CursorScreenPos.x <= UI.SelectedViewport->GetTopLeftPos().x) {
vpTilePos.x--;
UI.SelectedViewport->Set(vpTilePos, Map.Tileset->getPixelTileSize() / 2);
UI.SelectedViewport->Set(vpTilePos, Map.Tileset.getPixelTileSize() / 2);
} else if (CursorScreenPos.x >= UI.SelectedViewport->GetBottomRightPos().x) {
vpTilePos.x++;
UI.SelectedViewport->Set(vpTilePos, Map.Tileset->getPixelTileSize() / 2);
UI.SelectedViewport->Set(vpTilePos, Map.Tileset.getPixelTileSize() / 2);
}

if (CursorScreenPos.y <= UI.SelectedViewport->GetTopLeftPos().y) {
vpTilePos.y--;
UI.SelectedViewport->Set(vpTilePos, Map.Tileset->getPixelTileSize() / 2);
UI.SelectedViewport->Set(vpTilePos, Map.Tileset.getPixelTileSize() / 2);
} else if (CursorScreenPos.y >= UI.SelectedViewport->GetBottomRightPos().y) {
vpTilePos.y++;
UI.SelectedViewport->Set(vpTilePos, Map.Tileset->getPixelTileSize() / 2);
UI.SelectedViewport->Set(vpTilePos, Map.Tileset.getPixelTileSize() / 2);
}

// Scroll the map, if cursor moves outside the viewport.
Expand Down Expand Up @@ -1904,10 +1904,10 @@ void CEditor::Init()

Map.Fields.resize(Map.Info.MapWidth * Map.Info.MapHeight);

const int defaultTile = Map.Tileset->getDefaultTileIndex();
const int defaultTile = Map.Tileset.getDefaultTileIndex();

for (int i = 0; i < Map.Info.MapWidth * Map.Info.MapHeight; ++i) {
Map.Fields[i].setTileIndex(*Map.Tileset, defaultTile, 0, 0);
Map.Fields[i].setTileIndex(Map.Tileset, defaultTile, 0, 0);
}
GameSettings.Resources = SettingsPresetMapDefault;
CreateGame("", &Map);
Expand Down Expand Up @@ -1948,7 +1948,7 @@ void CEditor::Init()
Units.Icon = nullptr;
Units.Load();

Map.Tileset->fillSolidTiles(&Editor.ShownTileTypes);
Map.Tileset.fillSolidTiles(&Editor.ShownTileTypes);

RecalculateShownUnits();

Expand Down
Loading
Loading