Skip to content

Commit

Permalink
Move private types from unit/depend.h into unit/depend.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Oct 21, 2023
1 parent b0a5f1b commit b9d4311
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 75 deletions.
77 changes: 2 additions & 75 deletions src/include/depend.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,90 +32,16 @@

//@{

/*----------------------------------------------------------------------------
-- Documentation
----------------------------------------------------------------------------*/

/**
** @struct DependRule depend.h
**
** \#include "depend.h"
**
** This structure is used define the requirements of upgrades or
** unit-types. The structure is used to define the base (the wanted)
** upgrade or unit-type and the requirements upgrades or unit-types.
** The requirements could be combination of and-rules and or-rules.
**
** This structure is very complex because nearly everything has two
** meanings.
**
** The depend-rule structure members:
**
** DependRule::Next
**
** Next rule in hash chain for the base upgrade/unit-type.
** Next and-rule for the requirements.
**
** DependRule::Count
**
** If DependRule::Type is DependRuleUnitType, the counter is
** how many units of the unit-type are required, if zero no unit
** of this unit-type is allowed. if DependRule::Type is
** DependRuleUpgrade, for a non-zero counter the upgrade must be
** researched, for a zero counter the upgrade must be unresearched.
**
** DependRule::Type
**
** Type of the rule, DependRuleUnitType for an unit-type,
** DependRuleUpgrade for an upgrade.
**
** DependRule::Kind
**
** Contains the element of rule. Depending on DependRule::Type.
**
** DependRule::Kind::UnitType
**
** An unit-type pointer.
**
** DependRule::Kind::Upgrade
**
** An upgrade pointer.
**
** DependRule::Rule
**
** For the base upgrade/unit-type the rules which must be meet.
** For the requirements alternative or-rules.
**
*/
#include <string_view>

/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/

class CPlayer;
class CUnitType;
class CUpgrade;
class ButtonAction;

enum {
DependRuleUnitType, /// Kind is an unit-type
DependRuleUpgrade /// Kind is an upgrade
};

/// Dependency rule
class DependRule
{
public:
DependRule *Next; /// next hash chain, or rules
unsigned char Count; /// how many required
char Type; /// an unit-type or upgrade
union {
const CUnitType *UnitType; /// unit-type pointer
const CUpgrade *Upgrade; /// upgrade pointer
} Kind; /// required object
DependRule *Rule; /// requirements, and rule
};

/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
Expand All @@ -133,6 +59,7 @@ extern std::string PrintDependencies(const CPlayer &player, const ButtonAction &
extern bool CheckDependByIdent(const CPlayer &player, std::string_view target);
/// Check a dependency by unit type
extern bool CheckDependByType(const CPlayer &player, const CUnitType &type);

//@}

#endif // !__DEPEND_H__
77 changes: 77 additions & 0 deletions src/unit/depend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,83 @@
#include "upgrade_structs.h"
#include "upgrade.h"

/*----------------------------------------------------------------------------
-- Documentation
----------------------------------------------------------------------------*/

/**
** @struct DependRule depend.h
**
** \#include "depend.h"
**
** This structure is used define the requirements of upgrades or
** unit-types. The structure is used to define the base (the wanted)
** upgrade or unit-type and the requirements upgrades or unit-types.
** The requirements could be combination of and-rules and or-rules.
**
** This structure is very complex because nearly everything has two
** meanings.
**
** The depend-rule structure members:
**
** DependRule::Next
**
** Next rule in hash chain for the base upgrade/unit-type.
** Next and-rule for the requirements.
**
** DependRule::Count
**
** If DependRule::Type is DependRuleUnitType, the counter is
** how many units of the unit-type are required, if zero no unit
** of this unit-type is allowed. if DependRule::Type is
** DependRuleUpgrade, for a non-zero counter the upgrade must be
** researched, for a zero counter the upgrade must be unresearched.
**
** DependRule::Type
**
** Type of the rule, DependRuleUnitType for an unit-type,
** DependRuleUpgrade for an upgrade.
**
** DependRule::Kind
**
** Contains the element of rule. Depending on DependRule::Type.
**
** DependRule::Kind::UnitType
**
** An unit-type pointer.
**
** DependRule::Kind::Upgrade
**
** An upgrade pointer.
**
** DependRule::Rule
**
** For the base upgrade/unit-type the rules which must be meet.
** For the requirements alternative or-rules.
**
*/

enum
{
DependRuleUnitType, /// Kind is an unit-type
DependRuleUpgrade /// Kind is an upgrade
};

/// Dependency rule
class DependRule
{
public:
DependRule *Next; /// next hash chain, or rules
unsigned char Count; /// how many required
char Type; /// an unit-type or upgrade
union
{
const CUnitType *UnitType; /// unit-type pointer
const CUpgrade *Upgrade; /// upgrade pointer
} Kind; /// required object
DependRule *Rule; /// requirements, and rule
};

/*----------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------*/
Expand Down

0 comments on commit b9d4311

Please sign in to comment.