167 lines
4.2 KiB
C
Raw Normal View History

2013-08-29 11:45:22 +09:00
/*
Copyright (c) 2013 yvt
2013-09-05 00:52:03 +09:00
based on code of pysnip (c) Mathias Kaerlev 2011-2012.
2013-08-29 11:45:22 +09:00
This file is part of OpenSpades.
2013-08-29 11:45:22 +09:00
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2013-08-29 11:45:22 +09:00
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2013-08-29 11:45:22 +09:00
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
2013-08-29 11:45:22 +09:00
*/
2013-08-18 16:18:06 +09:00
#pragma once
#include <list>
2014-03-09 01:03:38 +09:00
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <map>
#include "GameMapWrapper.h"
#include "PhysicsConstants.h"
#include <Core/Debug.h>
#include <Core/Math.h>
2013-08-18 16:18:06 +09:00
namespace spades {
namespace client {
class GameMap;
class GameMapWrapper;
class Player;
class IWorldListener;
class Grenade;
class IGameMode;
class Client; // FIXME: for debug
2014-03-09 01:03:38 +09:00
class HitTestDebugger;
2017-11-18 21:15:07 +00:00
struct GameProperties;
2013-08-18 16:18:06 +09:00
class World {
friend class Client; // FIXME: for debug
public:
struct Team {
IntVector3 color;
std::string name;
};
struct PlayerPersistent {
std::string name;
int kills;
PlayerPersistent() : kills(0) { ; }
2013-08-18 16:18:06 +09:00
};
2013-08-18 16:18:06 +09:00
private:
IWorldListener *listener;
2013-08-18 16:18:06 +09:00
IGameMode *mode;
2013-08-18 16:18:06 +09:00
GameMap *map;
GameMapWrapper *mapWrapper;
float time;
IntVector3 fogColor;
Team teams[3];
std::shared_ptr<GameProperties> gameProperties;
2013-08-18 16:18:06 +09:00
std::vector<Player *> players;
std::vector<PlayerPersistent> playerPersistents;
int localPlayerIndex;
2013-08-18 16:18:06 +09:00
std::list<Grenade *> grenades;
2014-03-09 01:03:38 +09:00
std::unique_ptr<HitTestDebugger> hitTestDebugger;
std::unordered_map<CellPos, spades::IntVector3, CellPosHash> createdBlocks;
std::unordered_set<CellPos, CellPosHash> destroyedBlocks;
2017-02-20 04:09:10 +09:00
std::multimap<float, IntVector3> blockRegenerationQueue;
std::unordered_map<IntVector3, std::multimap<float, IntVector3>::iterator>
blockRegenerationQueueMap;
void ApplyBlockActions();
2013-08-18 16:18:06 +09:00
public:
World(const std::shared_ptr<GameProperties>&);
2013-08-18 16:18:06 +09:00
~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; }
2013-08-18 16:18:06 +09:00
void SetMap(GameMap *);
2013-08-18 16:18:06 +09:00
IntVector3 GetFogColor() { return fogColor; }
void SetFogColor(IntVector3 v) { fogColor = v; }
2013-08-18 16:18:06 +09:00
void Advance(float dt);
2013-08-18 16:18:06 +09:00
void AddGrenade(Grenade *);
std::vector<Grenade *> GetAllGrenades();
void MarkBlockForRegeneration(const IntVector3 &blockLocation);
void UnmarkBlockForRegeneration(const IntVector3 &blockLocation);
std::vector<IntVector3> CubeLine(IntVector3 v1, IntVector3 v2, int maxLength);
Player *GetPlayer(unsigned int i) {
// SPAssert(i >= 0); lm: unsigned cannot be smaller than 0 :)
2013-08-18 16:18:06 +09:00
SPAssert(i < players.size());
return players[i];
}
2013-08-18 16:18:06 +09:00
void SetPlayer(int i, Player *p);
2013-08-18 16:18:06 +09:00
IGameMode *GetMode() { return mode; }
void SetMode(IGameMode *);
Team &GetTeam(int t) {
2017-02-22 08:19:14 +09:00
if (t >= 2 || t < 0) // spectator
2013-08-18 16:18:06 +09:00
return teams[2];
return teams[t];
}
PlayerPersistent &GetPlayerPersistent(int index);
2013-08-18 16:18:06 +09:00
void CreateBlock(IntVector3 pos, IntVector3 color);
void DestroyBlock(std::vector<IntVector3> &pos);
2013-08-18 16:18:06 +09:00
struct WeaponRayCastResult {
bool hit, startSolid;
Player *player;
IntVector3 blockPos;
Vector3 hitPos;
2013-10-19 02:00:42 +02:00
hitTag_t hitFlag;
2013-08-18 16:18:06 +09:00
};
2013-08-18 16:18:06 +09:00
WeaponRayCastResult WeaponRayCast(Vector3 startPos, Vector3 dir, Player *exclude);
size_t GetNumPlayerSlots() { return players.size(); }
size_t GetNumPlayers();
int GetLocalPlayerIndex() { return localPlayerIndex; }
void SetLocalPlayerIndex(int p) { localPlayerIndex = p; }
2013-08-18 16:18:06 +09:00
Player *GetLocalPlayer() {
if (GetLocalPlayerIndex() == -1)
2013-08-18 16:18:06 +09:00
return NULL;
return GetPlayer(GetLocalPlayerIndex());
}
2014-03-09 01:03:38 +09:00
HitTestDebugger *GetHitTestDebugger();
void SetListener(IWorldListener *l) { listener = l; }
IWorldListener *GetListener() { return listener; }
2013-08-18 16:18:06 +09:00
};
}
}