1
0
Fork 0

Codechange: strongly type GoalID

pull/13511/head
Rubidium 2025-01-28 22:55:11 +01:00 committed by rubidium42
parent 7cc194e745
commit 6aada55e96
4 changed files with 8 additions and 5 deletions

View File

@ -14,7 +14,7 @@
#include "goal_type.h"
#include "core/pool_type.hpp"
typedef Pool<Goal, GoalID, 64, 64000> GoalPool;
using GoalPool = Pool<Goal, GoalID, 64, GoalID::End().base()>;
extern GoalPool _goal_pool;
/** Struct about goals, current and completed */

View File

@ -11,6 +11,7 @@
#define GOAL_TYPE_H
#include "core/enum_type.hpp"
#include "core/pool_type.hpp"
static const uint32_t GOAL_QUESTION_BUTTON_COUNT = 18; ///< Amount of buttons available.
@ -34,8 +35,10 @@ enum GoalType : uint8_t {
typedef uint32_t GoalTypeID; ///< Contains either tile, industry ID, town ID, company ID, or story page ID
typedef uint16_t GoalID; ///< ID of a goal
/** ID of a goal */
using GoalID = PoolID<uint16_t, struct GoalIDTag, 64000, 0xFFFF>;
struct Goal;
static const GoalID INVALID_GOAL = 0xFFFF; ///< Constant representing a non-existing goal.
static constexpr GoalID INVALID_GOAL = GoalID::Invalid(); ///< Constant representing a non-existing goal.
#endif /* GOAL_TYPE_H */

View File

@ -55,7 +55,7 @@
if (!ScriptObject::Command<CMD_CREATE_GOAL>::Do(&ScriptInstance::DoCommandReturnGoalID, ScriptCompany::FromScriptCompanyID(company), (::GoalType)type, destination, text)) return GOAL_INVALID;
/* In case of test-mode, we return GoalID 0 */
return static_cast<GoalID>(0);
return GoalID::Begin();
}
/* static */ bool ScriptGoal::Remove(GoalID goal_id)

View File

@ -105,7 +105,7 @@ static void UpdateElement(StoryPageElement &pe, TileIndex tile, uint32_t referen
pe.referenced_id = tile.base();
break;
case SPET_GOAL:
pe.referenced_id = (GoalID)reference;
pe.referenced_id = reference;
break;
case SPET_BUTTON_PUSH:
case SPET_BUTTON_TILE: