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

[Fix] Fix default type->NumDirections by ignoring "forward-declaration" #710

Merged
merged 1 commit into from
Aug 11, 2024
Merged
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
16 changes: 9 additions & 7 deletions src/unit/script_unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ static int CclDefineUnitType(lua_State *l)
type->Flip = 1;
}
std::uint32_t redefine = 0;

bool forward_declaration = true;
// Parse the list: (still everything could be changed!)
for (lua_pushnil(l); lua_next(l, 2); lua_pop(l, 1)) {
forward_declaration = false;
std::string_view value = LuaToString(l, -2);
if (value == "Name") {
type->Name = LuaToString(l, -1);
Expand Down Expand Up @@ -1169,12 +1170,13 @@ static int CclDefineUnitType(lua_State *l)
}
}

// If number of directions is not specified, make a guess
// Building have 1 direction and units 8
if (type->Building && type->NumDirections == 0) {
type->NumDirections = 1;
} else if (type->NumDirections == 0) {
type->NumDirections = 8;
// If number of directions is not specified,
// specify it but not for forward-declaration
if (type->NumDirections == 0 && !forward_declaration)
{
// make a guess Building have 1 direction and units 8
type->NumDirections = type->Building ? 1 : 8;
DebugPrint("Defaulting 'NumDirections' of %s to %d\n", str.data(), type->NumDirections);
}

// FIXME: try to simplify/combine the flags instead
Expand Down
Loading