Browse Source

vcmi: PlayerState is now an Entity

This will reduce code duplication a little bit.
Konstantin 2 years ago
parent
commit
ee489f18d2
3 changed files with 37 additions and 5 deletions
  1. 2 3
      include/vcmi/Player.h
  2. 27 1
      lib/CPlayerState.cpp
  3. 8 1
      lib/CPlayerState.h

+ 2 - 3
include/vcmi/Player.h

@@ -10,19 +10,18 @@
 
 #pragma once
 
+#include "Entity.h"
 VCMI_LIB_NAMESPACE_BEGIN
 
 class PlayerColor;
 class TeamID;
 class IBonusBearer;
 
-class DLL_LINKAGE Player
+class DLL_LINKAGE Player : public EntityWithBonuses<PlayerColor>
 {
 public:
-	virtual PlayerColor getColor() const = 0;
 	virtual TeamID getTeam() const = 0;
 	virtual bool isHuman() const = 0;
-	virtual const IBonusBearer * accessBonuses() const = 0;
 	virtual int getResourceAmount(int type) const = 0;
 };
 

+ 27 - 1
lib/CPlayerState.cpp

@@ -45,11 +45,37 @@ std::string PlayerState::nodeName() const
 	return "Player " + color.getStrCap(false);
 }
 
-PlayerColor PlayerState::getColor() const
+PlayerColor PlayerState::getId() const
 {
 	return color;
 }
 
+int32_t PlayerState::getIndex() const
+{
+	return color.getNum();
+}
+
+int32_t PlayerState::getIconIndex() const 
+{
+	return color.getNum();
+}
+std::string PlayerState::getJsonKey() const
+{
+	return color.getStr(false);
+}
+std::string PlayerState::getNameTranslated() const
+{
+	return color.getStr(true);
+}
+std::string PlayerState::getNameTextID() const
+{
+	return color.getStr(false);
+}
+void PlayerState::registerIcons(const IconRegistar & cb) const
+{
+	//We cannot register new icons for players
+}
+
 TeamID PlayerState::getTeam() const
 {
 	return team;

+ 8 - 1
lib/CPlayerState.h

@@ -45,12 +45,19 @@ public:
 
 	std::string nodeName() const override;
 
-	PlayerColor getColor() const override;
+	PlayerColor getId() const override;
 	TeamID getTeam() const override;
 	bool isHuman() const override;
 	const IBonusBearer * accessBonuses() const override;
 	int getResourceAmount(int type) const override;
 
+	int32_t getIndex() const override;
+	int32_t getIconIndex() const override;
+	std::string getJsonKey() const override;
+	std::string getNameTranslated() const override;
+	std::string getNameTextID() const override;
+	void registerIcons(const IconRegistar & cb) const override;
+
 	bool checkVanquished() const
 	{
 		return heroes.empty() && towns.empty();