Create Weapon instances based on the current GameProperties, not a cvar

This commit is contained in:
yvt 2017-09-11 20:59:39 +09:00
parent 821c392ade
commit 7d0d8e3704
7 changed files with 37 additions and 28 deletions

View File

@ -1772,7 +1772,7 @@ namespace spades {
SPLog("Map decoding succeeded.");
// now initialize world
World *w = new World();
World *w = new World(properties);
w->SetMap(map);
map->Release();
SPLog("World initialized.");

View File

@ -57,7 +57,7 @@ namespace spades {
moveSteps = 0;
this->playerId = playerId;
this->weapon = Weapon::CreateWeapon(wType, this);
this->weapon = Weapon::CreateWeapon(wType, this, *w->GetGameProperties());
this->weaponType = wType;
this->teamId = teamId;
this->weapon->Reset();
@ -927,7 +927,7 @@ namespace spades {
color = (color & 0xffffff) | ((uint32_t)health << 24);
if (map->IsSolid(x, y, z))
map->Set(x, y, z, true, color);
world->MarkBlockForRegeneration(outBlockCoord);
if (world->GetListener())
@ -1388,7 +1388,7 @@ namespace spades {
if (this->weapon->GetWeaponType() == weap)
return;
delete this->weapon;
this->weapon = Weapon::CreateWeapon(weap, this);
this->weapon = Weapon::CreateWeapon(weap, this, *world->GetGameProperties());
this->weaponType = weap;
}

View File

@ -20,13 +20,11 @@
*/
#include "Weapon.h"
#include "GameProperties.h"
#include "IWorldListener.h"
#include "World.h"
#include <Core/Debug.h>
#include <Core/Exception.h>
#include <Core/Settings.h>
SPADES_SETTING(cg_protocolVersion);
namespace spades {
namespace client {
@ -361,23 +359,26 @@ namespace spades {
virtual int GetPelletSize() { return 8; }
};
Weapon *Weapon::CreateWeapon(WeaponType type, Player *p) {
Weapon *Weapon::CreateWeapon(WeaponType type, Player *p, const GameProperties &gp) {
SPADES_MARK_FUNCTION();
if ((int)cg_protocolVersion == 4) {
switch (type) {
case RIFLE_WEAPON: return new RifleWeapon4(p->GetWorld(), p);
case SMG_WEAPON: return new SMGWeapon4(p->GetWorld(), p);
case SHOTGUN_WEAPON: return new ShotgunWeapon4(p->GetWorld(), p);
default: SPInvalidEnum("type", type);
}
} else {
switch (type) {
case RIFLE_WEAPON: return new RifleWeapon3(p->GetWorld(), p);
case SMG_WEAPON: return new SMGWeapon3(p->GetWorld(), p);
case SHOTGUN_WEAPON: return new ShotgunWeapon3(p->GetWorld(), p);
default: SPInvalidEnum("type", type);
}
switch (gp.protocolVersion) {
case ProtocolVersion::v075:
switch (type) {
case RIFLE_WEAPON: return new RifleWeapon3(p->GetWorld(), p);
case SMG_WEAPON: return new SMGWeapon3(p->GetWorld(), p);
case SHOTGUN_WEAPON: return new ShotgunWeapon3(p->GetWorld(), p);
default: SPInvalidEnum("type", type);
}
case ProtocolVersion::v076:
switch (type) {
case RIFLE_WEAPON: return new RifleWeapon4(p->GetWorld(), p);
case SMG_WEAPON: return new SMGWeapon4(p->GetWorld(), p);
case SHOTGUN_WEAPON: return new ShotgunWeapon4(p->GetWorld(), p);
default: SPInvalidEnum("type", type);
}
default:
SPInvalidEnum("protocolVersion", gp.protocolVersion);
}
}
}

View File

@ -28,6 +28,7 @@ namespace spades {
namespace client {
class World;
class Player;
class GameProperties;
class Weapon {
World *world;
@ -64,7 +65,7 @@ namespace spades {
virtual int GetPelletSize() = 0;
static Weapon *CreateWeapon(WeaponType index, Player *);
static Weapon *CreateWeapon(WeaponType index, Player *, const GameProperties &);
void Restock();
void Reset();

View File

@ -29,6 +29,7 @@
#include <Core/IStream.h>
#include "GameMap.h"
#include "GameMapWrapper.h"
#include "GameProperties.h"
#include "Grenade.h"
#include "HitTestDebugger.h"
#include "IGameMode.h"
@ -43,7 +44,8 @@ DEFINE_SPADES_SETTING(cg_debugHitTest, "0");
namespace spades {
namespace client {
World::World() {
World::World(const std::shared_ptr<GameProperties> &gameProperties)
: gameProperties{gameProperties} {
SPADES_MARK_FUNCTION();
listener = NULL;
@ -184,7 +186,7 @@ namespace spades {
delete mode;
mode = m;
}
void World::MarkBlockForRegeneration(const IntVector3 &blockLocation) {
UnmarkBlockForRegeneration(blockLocation);
@ -192,7 +194,7 @@ namespace spades {
auto result = blockRegenerationQueue.emplace(time + 10.0f, blockLocation);
blockRegenerationQueueMap.emplace(blockLocation, result);
}
void World::UnmarkBlockForRegeneration(const IntVector3 &blockLocation) {
auto it = blockRegenerationQueueMap.find(blockLocation);
if (it == blockRegenerationQueueMap.end()) {

View File

@ -43,6 +43,7 @@ namespace spades {
class IGameMode;
class Client; // FIXME: for debug
class HitTestDebugger;
class GameProperties;
class World {
friend class Client; // FIXME: for debug
public:
@ -67,6 +68,8 @@ namespace spades {
IntVector3 fogColor;
Team teams[3];
std::shared_ptr<GameProperties> gameProperties;
std::vector<Player *> players;
std::vector<PlayerPersistent> playerPersistents;
int localPlayerIndex;
@ -84,12 +87,15 @@ namespace spades {
void ApplyBlockActions();
public:
World();
World(const std::shared_ptr<GameProperties>&);
~World();
GameMap *GetMap() { return map; }
GameMapWrapper *GetMapWrapper() { return mapWrapper; }
float GetTime() { return time; }
/** Returns a non-null reference to `GameProperties`. */
const std::shared_ptr<GameProperties> &GetGameProperties() { return gameProperties; }
void SetMap(GameMap *);
IntVector3 GetFogColor() { return fogColor; }

View File

@ -29,7 +29,6 @@
#include <ScriptBindings/ScriptFunction.h>
DEFINE_SPADES_SETTING(cg_lastQuickConnectHost, "127.0.0.1");
SPADES_SETTING(cg_protocolVersion);
DEFINE_SPADES_SETTING(cg_playerName, "Deuce");
namespace spades {