Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic
This commit is contained in:
commit
1eceb6095f
|
@ -9,7 +9,7 @@
|
||||||
#include "NetworkClient.h"
|
#include "NetworkClient.h"
|
||||||
|
|
||||||
#include "L_inputClass.h"
|
#include "L_inputClass.h"
|
||||||
#include "vld.h"
|
//#include "vld.h"
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,9 +18,24 @@ namespace GameLogic
|
||||||
void UseAttatchment(const WEAPON_FIRE &fireInput);
|
void UseAttatchment(const WEAPON_FIRE &fireInput);
|
||||||
|
|
||||||
private:
|
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);
|
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);
|
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:
|
private:
|
||||||
struct PrivateData;
|
struct PrivateData;
|
||||||
PrivateData *myData;
|
PrivateData *myData;
|
||||||
|
|
|
@ -26,6 +26,10 @@ AttatchmentSocket::AttatchmentSocket(void)
|
||||||
|
|
||||||
AttatchmentSocket::~AttatchmentSocket(void)
|
AttatchmentSocket::~AttatchmentSocket(void)
|
||||||
{
|
{
|
||||||
|
if (myData->attatchment)
|
||||||
|
{
|
||||||
|
delete myData->attatchment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IAttatchment* AttatchmentSocket::GetAttatchment()
|
IAttatchment* AttatchmentSocket::GetAttatchment()
|
||||||
|
|
|
@ -180,6 +180,8 @@
|
||||||
<ClInclude Include="Object.h" />
|
<ClInclude Include="Object.h" />
|
||||||
<ClInclude Include="Player.h" />
|
<ClInclude Include="Player.h" />
|
||||||
<ClInclude Include="StaticObject.h" />
|
<ClInclude Include="StaticObject.h" />
|
||||||
|
<ClInclude Include="Team.h" />
|
||||||
|
<ClInclude Include="TeamManager.h" />
|
||||||
<ClInclude Include="Weapon.h" />
|
<ClInclude Include="Weapon.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -193,6 +195,8 @@
|
||||||
<ClCompile Include="Object.cpp" />
|
<ClCompile Include="Object.cpp" />
|
||||||
<ClCompile Include="Player.cpp" />
|
<ClCompile Include="Player.cpp" />
|
||||||
<ClCompile Include="StaticObject.cpp" />
|
<ClCompile Include="StaticObject.cpp" />
|
||||||
|
<ClCompile Include="Team.cpp" />
|
||||||
|
<ClCompile Include="TeamManager.cpp" />
|
||||||
<ClCompile Include="Weapon.cpp" />
|
<ClCompile Include="Weapon.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include "DynamicObject.h"
|
#include "DynamicObject.h"
|
||||||
#include "GameMode.h"
|
#include "GameMode.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
|
#include "PhysicsAPI.h"
|
||||||
|
#include "TeamManager.h"
|
||||||
|
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
|
||||||
|
@ -16,8 +18,7 @@ struct Level::PrivateData
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Player *players;
|
TeamManager *teamManager;
|
||||||
int nrOfPlayers;
|
|
||||||
|
|
||||||
StaticObject** staticObjects;
|
StaticObject** staticObjects;
|
||||||
int nrOfStaticObjects;
|
int nrOfStaticObjects;
|
||||||
|
@ -27,6 +28,8 @@ struct Level::PrivateData
|
||||||
|
|
||||||
GameMode* gameMode;
|
GameMode* gameMode;
|
||||||
|
|
||||||
|
Oyster::Physics::ICustomBody *rigidBodyLevel;
|
||||||
|
|
||||||
}myData;
|
}myData;
|
||||||
|
|
||||||
Level::Level(void)
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#ifndef LEVEL_H
|
#ifndef LEVEL_H
|
||||||
#define LEVEL_H
|
#define LEVEL_H
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
@ -15,8 +16,34 @@ namespace GameLogic
|
||||||
Level(void);
|
Level(void);
|
||||||
~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);
|
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:
|
private:
|
||||||
struct PrivateData;
|
struct PrivateData;
|
||||||
PrivateData *myData;
|
PrivateData *myData;
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct Player::PrivateData
|
||||||
weapon = new Weapon();
|
weapon = new Weapon();
|
||||||
|
|
||||||
life = 100;
|
life = 100;
|
||||||
|
teamID = -1;
|
||||||
playerState = PLAYER_STATE_IDLE;
|
playerState = PLAYER_STATE_IDLE;
|
||||||
|
|
||||||
lookDir = Oyster::Math::Float3(1,0,0);
|
lookDir = Oyster::Math::Float3(1,0,0);
|
||||||
|
@ -27,6 +28,7 @@ struct Player::PrivateData
|
||||||
}
|
}
|
||||||
|
|
||||||
int life;
|
int life;
|
||||||
|
int teamID;
|
||||||
Weapon *weapon;
|
Weapon *weapon;
|
||||||
PLAYER_STATE playerState;
|
PLAYER_STATE playerState;
|
||||||
Oyster::Math::Float3 lookDir;
|
Oyster::Math::Float3 lookDir;
|
||||||
|
@ -44,20 +46,7 @@ Player::~Player(void)
|
||||||
delete myData;
|
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)
|
void Player::Move(const PLAYER_MOVEMENT &movement)
|
||||||
{
|
{
|
||||||
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
|
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
|
||||||
|
@ -83,18 +72,20 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/********************************************************
|
|
||||||
* Uses the players weapon based on user input
|
|
||||||
********************************************************/
|
|
||||||
void Player::UseWeapon(const WEAPON_FIRE &fireInput)
|
void Player::UseWeapon(const WEAPON_FIRE &fireInput)
|
||||||
{
|
{
|
||||||
myData->weapon->Use(fireInput);
|
myData->weapon->Use(fireInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************
|
void Player::Respawn(Oyster::Math::Float3 spawnPoint)
|
||||||
* Jumps if the player is currently not in a state of jumping
|
{
|
||||||
* Applies a force upwards(current upwards)
|
API::Instance().SetCenter(rigidBody,spawnPoint);
|
||||||
********************************************************/
|
myData->life = 100;
|
||||||
|
myData->playerState = PLAYER_STATE_IDLE;
|
||||||
|
myData->lookDir = Oyster::Math::Float3(1,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
void Player::Jump()
|
void Player::Jump()
|
||||||
{
|
{
|
||||||
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
|
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;
|
return myData->lookDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************
|
int Player::GetTeamID()
|
||||||
* Respawns the player on a new chosen position
|
|
||||||
* This resets a set of variables such as life, ammo etcetc
|
|
||||||
********************************************************/
|
|
||||||
void Player::Respawn()
|
|
||||||
{
|
{
|
||||||
|
return myData->teamID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Player::DamageLife(int damage)
|
void Player::DamageLife(int damage)
|
||||||
{
|
{
|
||||||
myData->life -= damage;
|
myData->life -= damage;
|
||||||
|
|
|
@ -17,10 +17,24 @@ namespace GameLogic
|
||||||
Player(void);
|
Player(void);
|
||||||
~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 Move(const PLAYER_MOVEMENT &movement);
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* 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);
|
void UseWeapon(const WEAPON_FIRE &fireInput);
|
||||||
void Jump();
|
|
||||||
|
/********************************************************
|
||||||
|
* 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 IsWalking();
|
||||||
bool IsJumping();
|
bool IsJumping();
|
||||||
|
@ -28,11 +42,13 @@ namespace GameLogic
|
||||||
|
|
||||||
Oyster::Math::Float3 GetPos();
|
Oyster::Math::Float3 GetPos();
|
||||||
Oyster::Math::Float3 GetLookDir();
|
Oyster::Math::Float3 GetLookDir();
|
||||||
|
int GetTeamID();
|
||||||
void Respawn();
|
|
||||||
|
|
||||||
void DamageLife(int damage);
|
void DamageLife(int damage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void Jump();
|
||||||
private:
|
private:
|
||||||
struct PrivateData;
|
struct PrivateData;
|
||||||
PrivateData *myData;
|
PrivateData *myData;
|
||||||
|
|
|
@ -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++;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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
|
|
@ -49,6 +49,12 @@ Weapon::Weapon(int MaxNrOfSockets)
|
||||||
|
|
||||||
Weapon::~Weapon(void)
|
Weapon::~Weapon(void)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < myData->currentNrOfAttatchments; i++)
|
||||||
|
{
|
||||||
|
delete myData->attatchmentSockets[i];
|
||||||
|
}
|
||||||
|
delete[] myData->attatchmentSockets;
|
||||||
|
|
||||||
delete myData;
|
delete myData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +63,11 @@ Weapon::~Weapon(void)
|
||||||
********************************************************/
|
********************************************************/
|
||||||
void Weapon::Use(const WEAPON_FIRE &fireInput)
|
void Weapon::Use(const WEAPON_FIRE &fireInput)
|
||||||
{
|
{
|
||||||
myData->selectedAttatchment->UseAttatchment(fireInput);
|
if (myData->selectedAttatchment)
|
||||||
|
{
|
||||||
|
myData->selectedAttatchment->UseAttatchment(fireInput);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H
|
#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vld.h>
|
//#include <vld.h>
|
||||||
|
|
||||||
#ifdef CUSTOM_NET_PROTOCOL_EXPORT
|
#ifdef CUSTOM_NET_PROTOCOL_EXPORT
|
||||||
#define NET_PROTOCOL_EXPORT __declspec(dllexport)
|
#define NET_PROTOCOL_EXPORT __declspec(dllexport)
|
||||||
|
|
|
@ -217,17 +217,18 @@ void Translator::Pack(OysterByte &bytes, CustomNetProtocol& protocol)
|
||||||
|
|
||||||
privateData->PackHeader(bytes, protocol);
|
privateData->PackHeader(bytes, protocol);
|
||||||
privateData->PackMessage(bytes, protocol);
|
privateData->PackMessage(bytes, protocol);
|
||||||
this->privateData->headerString.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
|
bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
|
||||||
{
|
{
|
||||||
|
this->privateData->headerString.clear();
|
||||||
|
|
||||||
if(!privateData->UnpackHeader(protocol, bytes))
|
if(!privateData->UnpackHeader(protocol, bytes))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
privateData->UnpackMessage(protocol, bytes);
|
privateData->UnpackMessage(protocol, bytes);
|
||||||
this->privateData->headerString.clear();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
|
@ -60,13 +60,14 @@ unsigned char* OysterByte::GetByteArray()
|
||||||
|
|
||||||
void OysterByte::AddSize(unsigned int size)
|
void OysterByte::AddSize(unsigned int size)
|
||||||
{
|
{
|
||||||
int oldSize = this->size;
|
int newCapacity = this->size + size;
|
||||||
this->size += size;
|
|
||||||
|
|
||||||
if(this->size >= capacity)
|
if(newCapacity >= capacity)
|
||||||
{
|
{
|
||||||
IncreaseCapacity(oldSize);
|
IncreaseCapacity(newCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->size += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OysterByte::SetBytes(unsigned char* bytes)
|
void OysterByte::SetBytes(unsigned char* bytes)
|
||||||
|
@ -116,7 +117,7 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
|
||||||
|
|
||||||
if(newSize >= (int)capacity)
|
if(newSize >= (int)capacity)
|
||||||
{
|
{
|
||||||
IncreaseCapacity(this->size);
|
IncreaseCapacity(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = size, j = 0; i < newSize; i++, j++)
|
for(int i = size, j = 0; i < newSize; i++, j++)
|
||||||
|
@ -133,12 +134,12 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
|
||||||
// Private //
|
// 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];
|
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];
|
temp[i] = byteArray[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ namespace Oyster
|
||||||
char* UnpackCStr(unsigned char buffer[])
|
char* UnpackCStr(unsigned char buffer[])
|
||||||
{
|
{
|
||||||
short len = UnpackS(buffer);
|
short len = UnpackS(buffer);
|
||||||
char* str = new char[len];
|
char* str = new char[len+1];
|
||||||
|
|
||||||
buffer += 2;
|
buffer += 2;
|
||||||
for(int i = 0; i < len; i++)
|
for(int i = 0; i < len; i++)
|
||||||
|
@ -290,6 +290,8 @@ namespace Oyster
|
||||||
str[i] = buffer[i];
|
str[i] = buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str[len] = '\0';
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ int main()
|
||||||
Oyster::Network::NetworkServer::INIT_DESC desc;
|
Oyster::Network::NetworkServer::INIT_DESC desc;
|
||||||
desc.port = 15151;
|
desc.port = 15151;
|
||||||
desc.callbackType = NetworkClientCallbackType_Function;
|
desc.callbackType = NetworkClientCallbackType_Function;
|
||||||
desc.recvObj = proc;
|
//desc.recvObj = proc;
|
||||||
|
|
||||||
if(!server.Init(desc))
|
if(!server.Init(desc))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue