diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp
index a6249dc9..803c97c0 100644
--- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp
+++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp
@@ -9,7 +9,7 @@
#include "NetworkClient.h"
#include "L_inputClass.h"
-#include "vld.h"
+//#include "vld.h"
namespace DanBias
{
diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h
index 2fac7be4..4c4fc124 100644
--- a/Code/Game/GameLogic/AttatchmentMassDriver.h
+++ b/Code/Game/GameLogic/AttatchmentMassDriver.h
@@ -18,9 +18,24 @@ namespace GameLogic
void UseAttatchment(const WEAPON_FIRE &fireInput);
private:
+ /********************************************************
+ * Pushes objects and players in a cone in front of the player
+ * @param fireInput: allows switching on different functionality in this specific function
+ ********************************************************/
void ForcePush(const WEAPON_FIRE &fireInput);
+
+ /********************************************************
+ * Pulls the player forward, this is a movement tool
+ * @param fireInput: allows switching on different functionality in this specific function
+ ********************************************************/
void ForcePull(const WEAPON_FIRE &fireInput);
+ /********************************************************
+ * Sucks objects towards the player, the player can then pick up an object and throw it as a projectile
+ * @param fireInput: allows switching on different functionality in this specific function
+ ********************************************************/
+ void ForceSuck(const WEAPON_FIRE &fireInput);
+
private:
struct PrivateData;
PrivateData *myData;
diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp
index 288a1a4e..5d997a45 100644
--- a/Code/Game/GameLogic/AttatchmentSocket.cpp
+++ b/Code/Game/GameLogic/AttatchmentSocket.cpp
@@ -26,6 +26,10 @@ AttatchmentSocket::AttatchmentSocket(void)
AttatchmentSocket::~AttatchmentSocket(void)
{
+ if (myData->attatchment)
+ {
+ delete myData->attatchment;
+ }
}
IAttatchment* AttatchmentSocket::GetAttatchment()
diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj
index e0614e29..11ba6e82 100644
--- a/Code/Game/GameLogic/GameLogic.vcxproj
+++ b/Code/Game/GameLogic/GameLogic.vcxproj
@@ -180,6 +180,8 @@
+
+
@@ -193,6 +195,8 @@
+
+
diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp
index 835062c1..f0d1b935 100644
--- a/Code/Game/GameLogic/Level.cpp
+++ b/Code/Game/GameLogic/Level.cpp
@@ -3,6 +3,8 @@
#include "DynamicObject.h"
#include "GameMode.h"
#include "Player.h"
+#include "PhysicsAPI.h"
+#include "TeamManager.h"
using namespace GameLogic;
@@ -16,8 +18,7 @@ struct Level::PrivateData
{
}
- Player *players;
- int nrOfPlayers;
+ TeamManager *teamManager;
StaticObject** staticObjects;
int nrOfStaticObjects;
@@ -27,6 +28,8 @@ struct Level::PrivateData
GameMode* gameMode;
+ Oyster::Physics::ICustomBody *rigidBodyLevel;
+
}myData;
Level::Level(void)
@@ -45,4 +48,19 @@ void Level::InitiateLevel(std::string levelPath)
}
+void Level::AddPlayerToTeam(Player *player, int teamID)
+{
+ myData->teamManager->AddPlayerToTeam(player,teamID);
+}
+
+void Level::CreateTeam(int teamSize)
+{
+ myData->teamManager->CreateTeam(teamSize);
+}
+
+void Level::RespawnPlayer(Player *player)
+{
+ myData->teamManager->RespawnPlayerRandom(player);
+}
+
diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h
index 7177531b..fa450dc4 100644
--- a/Code/Game/GameLogic/Level.h
+++ b/Code/Game/GameLogic/Level.h
@@ -4,6 +4,7 @@
#ifndef LEVEL_H
#define LEVEL_H
#include
+#include "Player.h"
namespace GameLogic
{
@@ -15,8 +16,34 @@ namespace GameLogic
Level(void);
~Level(void);
+ /********************************************************
+ * Initiates a level for players to play on
+ * @param levelPath: Path to a file that contains all information on the level
+ ********************************************************/
void InitiateLevel(std::string levelPath);
+ /********************************************************
+ * Creates a team in the level
+ * @param teamSize: The size of the team you want to create
+ ********************************************************/
+ void CreateTeam(int teamSize);
+
+ /********************************************************
+ * Adds a player to a team
+ * @param player: The player you want to add to the team
+ * @param teamID: ArrayPos of the team you want to add the player to
+ ********************************************************/
+ void AddPlayerToTeam(Player *player, int teamID);
+
+
+ /********************************************************
+ * Respawns a player on a random teammate
+ * @param player: The player you want to respawn
+ ********************************************************/
+ void RespawnPlayer(Player *player);
+
+ private:
+
private:
struct PrivateData;
PrivateData *myData;
diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp
index bae54e9a..b17a1b5b 100644
--- a/Code/Game/GameLogic/Player.cpp
+++ b/Code/Game/GameLogic/Player.cpp
@@ -13,6 +13,7 @@ struct Player::PrivateData
weapon = new Weapon();
life = 100;
+ teamID = -1;
playerState = PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float3(1,0,0);
@@ -27,6 +28,7 @@ struct Player::PrivateData
}
int life;
+ int teamID;
Weapon *weapon;
PLAYER_STATE playerState;
Oyster::Math::Float3 lookDir;
@@ -44,20 +46,7 @@ Player::~Player(void)
delete myData;
}
-/********************************************************
-* Updates the player(is this function needed?)
-********************************************************/
-void Player::Update()
-{
-
-}
-
-/********************************************************
-* Moves the player based on client input
-* Uses the physics to move the player by adding a force in the chosen direction
-* Uses the Jump() function if the player is to jump, this is becuase jumping requires additional logic compared to normal movement
-********************************************************/
void Player::Move(const PLAYER_MOVEMENT &movement)
{
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
@@ -83,18 +72,20 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
break;
}
}
-/********************************************************
-* Uses the players weapon based on user input
-********************************************************/
+
void Player::UseWeapon(const WEAPON_FIRE &fireInput)
{
myData->weapon->Use(fireInput);
}
-/********************************************************
-* Jumps if the player is currently not in a state of jumping
-* Applies a force upwards(current upwards)
-********************************************************/
+void Player::Respawn(Oyster::Math::Float3 spawnPoint)
+{
+ API::Instance().SetCenter(rigidBody,spawnPoint);
+ myData->life = 100;
+ myData->playerState = PLAYER_STATE_IDLE;
+ myData->lookDir = Oyster::Math::Float3(1,0,0);
+}
+
void Player::Jump()
{
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
@@ -123,16 +114,11 @@ Oyster::Math::Float3 Player::GetLookDir()
return myData->lookDir;
}
-/********************************************************
-* Respawns the player on a new chosen position
-* This resets a set of variables such as life, ammo etcetc
-********************************************************/
-void Player::Respawn()
+int Player::GetTeamID()
{
-
+ return myData->teamID;
}
-
void Player::DamageLife(int damage)
{
myData->life -= damage;
diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h
index af0bff50..f6e61fa5 100644
--- a/Code/Game/GameLogic/Player.h
+++ b/Code/Game/GameLogic/Player.h
@@ -16,23 +16,39 @@ namespace GameLogic
public:
Player(void);
~Player(void);
-
- void Update();
+
+ /********************************************************
+ * Moves the player based on input
+ * @param movement: enum value on what kind of action is to be taken
+ ********************************************************/
void Move(const PLAYER_MOVEMENT &movement);
- void UseWeapon(const WEAPON_FIRE &fireInput);
- void Jump();
+ /********************************************************
+ * Uses the weapon based on input
+ * @param fireInput: enum value on what kind of action is to be taken
+ ********************************************************/
+ void UseWeapon(const WEAPON_FIRE &fireInput);
+
+ /********************************************************
+ * Respawns the player, this resets several stats and settings on the player
+ * @param spawnPoint: the coordinate in the world where the player is to spawn
+ ********************************************************/
+ void Respawn(Oyster::Math::Float3 spawnPoint);
+
+
bool IsWalking();
bool IsJumping();
bool IsIdle();
Oyster::Math::Float3 GetPos();
Oyster::Math::Float3 GetLookDir();
-
- void Respawn();
+ int GetTeamID();
void DamageLife(int damage);
+ private:
+
+ void Jump();
private:
struct PrivateData;
PrivateData *myData;
diff --git a/Code/Game/GameLogic/Team.cpp b/Code/Game/GameLogic/Team.cpp
new file mode 100644
index 00000000..b0c28785
--- /dev/null
+++ b/Code/Game/GameLogic/Team.cpp
@@ -0,0 +1,59 @@
+#include "Team.h"
+#include "Player.h"
+
+using namespace GameLogic;
+
+struct Team::PrivateData
+{
+ PrivateData()
+ {
+ players = 0;
+ nrOfPlayers = 0;
+ teamSize = 0;
+ }
+ ~PrivateData()
+ {
+
+ }
+
+ Player **players;
+ int nrOfPlayers;
+
+ int teamSize;
+
+}myData;
+
+Team::Team(void)
+{
+ myData = new PrivateData();
+}
+
+Team::Team(int teamSize)
+{
+ myData = new PrivateData();
+ myData->teamSize = teamSize;
+}
+
+
+Team::~Team(void)
+{
+ delete myData;
+}
+
+Player* Team::GetPlayer(int playerID)
+{
+ return myData->players[playerID];
+}
+
+bool Team::AddPlayer(Player *player)
+{
+ if (myData->nrOfPlayers >= myData->teamSize)
+ {
+ return false;
+ }
+ else
+ {
+ myData->players[myData->nrOfPlayers] = player;
+ myData->nrOfPlayers++;
+ }
+}
diff --git a/Code/Game/GameLogic/Team.h b/Code/Game/GameLogic/Team.h
new file mode 100644
index 00000000..ff0d5941
--- /dev/null
+++ b/Code/Game/GameLogic/Team.h
@@ -0,0 +1,35 @@
+//////////////////////////////////////////////////
+//Created by Erik of the GameLogic team
+//////////////////////////////////////////////////
+
+#ifndef TEAM_H
+#define TEAM_H
+namespace GameLogic
+{
+
+ class Team
+ {
+ public:
+ Team(void);
+ Team(int teamSize);
+ ~Team(void);
+
+ /********************************************************
+ * Gets a player in the team
+ * @param playerID: Arrayposition of the player you want to get
+ ********************************************************/
+ Player* GetPlayer(int playerID);
+
+ /********************************************************
+ * Adds a player to the team
+ * @param player: Player that are to be added
+ ********************************************************/
+ bool AddPlayer(Player *player);
+
+ private:
+ struct PrivateData;
+ PrivateData *myData;
+ };
+}
+#endif
+
diff --git a/Code/Game/GameLogic/TeamManager.cpp b/Code/Game/GameLogic/TeamManager.cpp
new file mode 100644
index 00000000..21a68394
--- /dev/null
+++ b/Code/Game/GameLogic/TeamManager.cpp
@@ -0,0 +1,96 @@
+#include "TeamManager.h"
+#include "Team.h"
+
+
+using namespace GameLogic;
+
+struct TeamManager::PrivateData
+{
+ PrivateData()
+ {
+ teams = 0;
+ nrOfTeams = 0;
+ }
+ ~PrivateData()
+ {
+ }
+
+ Team **teams;
+ int nrOfTeams;
+ int maxNrOfTeams;
+
+}myData;
+
+TeamManager::TeamManager(void)
+{
+ myData = new PrivateData();
+ myData->maxNrOfTeams = 10;
+ myData->teams = new Team*[myData->maxNrOfTeams];
+}
+
+TeamManager::TeamManager(int maxNrOfTeams)
+{
+ myData = new PrivateData();
+ myData->maxNrOfTeams = maxNrOfTeams;
+
+ myData->teams = new Team*[myData->maxNrOfTeams];
+ for (int i = 0; i < myData->maxNrOfTeams; i++)
+ {
+ myData->teams[i] = 0;
+ }
+
+}
+
+
+TeamManager::~TeamManager(void)
+{
+ delete myData;
+}
+
+void TeamManager::RespawnPlayerRandom(Player *player)
+{
+
+ int teamID = player->GetTeamID();
+
+ Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0);
+
+ player->Respawn(respawnOnThis->GetPos());
+}
+
+void TeamManager::CreateTeam(int teamSize)
+{
+ if (myData->nrOfTeams < myData->maxNrOfTeams)
+ {
+ myData->teams[myData->nrOfTeams] = new Team(teamSize);
+ myData->nrOfTeams++;
+ }
+}
+
+void TeamManager::RemoveTeam(int teamID)
+{
+
+}
+
+bool TeamManager::AddPlayerToTeam(Player *player,int teamID)
+{
+ if (IsValidTeam(teamID))
+ {
+ return myData->teams[teamID]->AddPlayer(player);
+ }
+ return false;
+}
+
+bool TeamManager::AddPlayerToTeam(Player *player)
+{
+
+}
+
+bool TeamManager::IsValidTeam(int teamID)
+{
+ if (teamID < myData->nrOfTeams && teamID > 0 && myData->teams[teamID] != NULL)
+ {
+ return true;
+ }
+
+ return false;
+}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/TeamManager.h b/Code/Game/GameLogic/TeamManager.h
new file mode 100644
index 00000000..80715210
--- /dev/null
+++ b/Code/Game/GameLogic/TeamManager.h
@@ -0,0 +1,63 @@
+//////////////////////////////////////////////////
+//Created by Erik of the GameLogic team
+//////////////////////////////////////////////////
+
+#ifndef TEAMMANAGER_H
+#define TEAMMANAGER_H
+#include "Player.h"
+
+namespace GameLogic
+{
+
+ class TeamManager
+ {
+ public:
+ TeamManager(void);
+ TeamManager(int maxNrOfTeams);
+ ~TeamManager(void);
+
+ /********************************************************
+ * Respawns the chosen player on a random teammember
+ * @param player: Pointer to the player you want to respawn
+ ********************************************************/
+ void RespawnPlayerRandom(Player *player);
+
+ /********************************************************
+ * Creates a team that can hold players
+ * @param teamSize: The number of players that can fit in this team
+ ********************************************************/
+ void CreateTeam(int teamSize);
+
+
+ /********************************************************
+ * Removes the chosen team
+ * @param teamID: This is the array ID of the team you want to remove
+ ********************************************************/
+ void RemoveTeam(int teamID);
+
+
+ /********************************************************
+ * Adds a player to the teamID given
+ * @param player: Player that you want to add to a team
+ * @param teamID: The team you want to place the player in
+ ********************************************************/
+ bool AddPlayerToTeam(Player *player ,int teamID);
+
+ /********************************************************
+ * Adds a player to the team with the least amount players
+ * @param player: Player that you want to add to a team
+ ********************************************************/
+ bool AddPlayerToTeam(Player *player);
+
+ /********************************************************
+ * Checks if the team exists or not, returns true if yes
+ * @param teamID: ID of the team that are to exist or not
+ ********************************************************/
+ bool IsValidTeam(int teamID);
+
+ private:
+ struct PrivateData;
+ PrivateData *myData;
+ };
+}
+#endif
\ No newline at end of file
diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp
index e620e0d6..b2359ec7 100644
--- a/Code/Game/GameLogic/Weapon.cpp
+++ b/Code/Game/GameLogic/Weapon.cpp
@@ -49,6 +49,12 @@ Weapon::Weapon(int MaxNrOfSockets)
Weapon::~Weapon(void)
{
+ for (int i = 0; i < myData->currentNrOfAttatchments; i++)
+ {
+ delete myData->attatchmentSockets[i];
+ }
+ delete[] myData->attatchmentSockets;
+
delete myData;
}
@@ -57,7 +63,11 @@ Weapon::~Weapon(void)
********************************************************/
void Weapon::Use(const WEAPON_FIRE &fireInput)
{
- myData->selectedAttatchment->UseAttatchment(fireInput);
+ if (myData->selectedAttatchment)
+ {
+ myData->selectedAttatchment->UseAttatchment(fireInput);
+ }
+
}
/********************************************************
diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h
index d25c23e5..82d92c99 100644
--- a/Code/Network/NetworkAPI/CustomNetProtocol.h
+++ b/Code/Network/NetworkAPI/CustomNetProtocol.h
@@ -5,7 +5,7 @@
#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H
#include
-#include
+//#include
#ifdef CUSTOM_NET_PROTOCOL_EXPORT
#define NET_PROTOCOL_EXPORT __declspec(dllexport)
diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp
index 59ecdfd2..0829913e 100644
--- a/Code/Network/NetworkAPI/Translator.cpp
+++ b/Code/Network/NetworkAPI/Translator.cpp
@@ -217,17 +217,18 @@ void Translator::Pack(OysterByte &bytes, CustomNetProtocol& protocol)
privateData->PackHeader(bytes, protocol);
privateData->PackMessage(bytes, protocol);
- this->privateData->headerString.clear();
}
bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
{
+ this->privateData->headerString.clear();
+
if(!privateData->UnpackHeader(protocol, bytes))
{
return false;
}
privateData->UnpackMessage(protocol, bytes);
- this->privateData->headerString.clear();
+
return true;
}
\ No newline at end of file
diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp
index 7cbbde58..ac6923a2 100644
--- a/Code/Network/NetworkDependencies/OysterByte.cpp
+++ b/Code/Network/NetworkDependencies/OysterByte.cpp
@@ -60,13 +60,14 @@ unsigned char* OysterByte::GetByteArray()
void OysterByte::AddSize(unsigned int size)
{
- int oldSize = this->size;
- this->size += size;
+ int newCapacity = this->size + size;
- if(this->size >= capacity)
+ if(newCapacity >= capacity)
{
- IncreaseCapacity(oldSize);
+ IncreaseCapacity(newCapacity);
}
+
+ this->size += size;
}
void OysterByte::SetBytes(unsigned char* bytes)
@@ -113,17 +114,17 @@ OysterByte::operator unsigned char*()
OysterByte& OysterByte::operator +=(const OysterByte& obj)
{
int newSize = this->size + obj.size;
-
+
if(newSize >= (int)capacity)
{
- IncreaseCapacity(this->size);
+ IncreaseCapacity(newSize);
}
for(int i = size, j = 0; i < newSize; i++, j++)
{
this->byteArray[i] = obj.byteArray[j];
}
-
+
this->size = newSize;
return *this;
@@ -133,12 +134,12 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
// Private //
/////////////
-void OysterByte::IncreaseCapacity(unsigned int oldSize)
+void OysterByte::IncreaseCapacity(unsigned int newCapacity)
{
- capacity = size * 2;
+ capacity = newCapacity * 2;
unsigned char* temp = new unsigned char[capacity];
- for(int i = 0; i < (int)oldSize; i++)
+ for(int i = 0; i < (int)this->size; i++)
{
temp[i] = byteArray[i];
}
diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp
index 5728cabe..41d059a3 100644
--- a/Code/Network/NetworkDependencies/Packing.cpp
+++ b/Code/Network/NetworkDependencies/Packing.cpp
@@ -282,7 +282,7 @@ namespace Oyster
char* UnpackCStr(unsigned char buffer[])
{
short len = UnpackS(buffer);
- char* str = new char[len];
+ char* str = new char[len+1];
buffer += 2;
for(int i = 0; i < len; i++)
@@ -290,6 +290,8 @@ namespace Oyster
str[i] = buffer[i];
}
+ str[len] = '\0';
+
return str;
}
diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp
index eb66154a..a2a65d13 100644
--- a/Code/Network/OysterNetworkServer/ServerMain.cpp
+++ b/Code/Network/OysterNetworkServer/ServerMain.cpp
@@ -29,7 +29,7 @@ int main()
Oyster::Network::NetworkServer::INIT_DESC desc;
desc.port = 15151;
desc.callbackType = NetworkClientCallbackType_Function;
- desc.recvObj = proc;
+ //desc.recvObj = proc;
if(!server.Init(desc))
{