Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abramann committed Nov 3, 2023
1 parent 32509fd commit 6a8b8e5
Show file tree
Hide file tree
Showing 31 changed files with 3,322 additions and 3,215 deletions.
14 changes: 8 additions & 6 deletions src/Client/tankswar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "..\common\inlined.inl"
#include "thisplayer.h"

TanksWar::TanksWar() : m_status(clientNS::CLIENT_UNCONNECTED), m_aiLevel(AI_LEVEL_EASY), m_soloGameStarted(false), m_AIPlayersCount(0)
TanksWar::TanksWar() : m_status(clientNS::CLIENT_UNCONNECTED), m_soloGameStarted(false)
{
m_pClient = std::make_shared<Client>();
m_pRData = m_pClient->getReceiveBuffer();
Expand Down Expand Up @@ -237,14 +237,16 @@ bool TanksWar::onStartSoloPlayerGame()
if (!m_pMap->load(m_map))
return false;

m_pMap->removeObject(&m_thisClient);
m_pMap->addObject(&m_thisPlayer);
m_thisPlayer.setPosition(m_pMap->getRandomEmptySpace(&m_thisPlayer).v1);
m_pAIPlayer.resize(m_AIPlayersCount);
uint8 c = 1;
for (auto& pAIPlayer : m_pAIPlayer)
for (uint32 i = 0; i < g_pGameSettings->aiCount; i++)
{
pAIPlayer->initialize(this, c, strFormat("AIPlayer %d", c++).c_str());
pAIPlayer->setPosition(m_pMap->getRandomEmptySpace(pAIPlayer.get()).v1);
m_pAIPlayer.push_back(std::make_shared<AIPlayer>());
m_pAIPlayer.back()->initialize(this, i+1, strFormat("AIPlayer %d", i+1));
m_pAIPlayer.back()->setPosition(m_pMap->getRandomEmptySpace(m_pAIPlayer[i].get()).v1);
}

m_soloGameStarted = true;
return true;
}
Expand Down
6 changes: 0 additions & 6 deletions src/Client/tankswar.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ class TanksWar : public Game
int32 getExistClients() const { return m_pRemoteClient.size() + 1; }
std::string getGameMap() const { return m_map; }
void setGameMap(const std::string& gameMap) { debuggerBreak(isOnline(), "Invalid call!/n"); strcpy(m_map, gameMap.c_str()); }
AILevel getAILevel() const { return m_aiLevel; }
void setAILevel(AILevel aiLevel) { m_aiLevel = aiLevel; }
bool onStartSoloPlayerGame();
bool isSoloGameStarted() const { return m_soloGameStarted; }
uint32 getAIPlayerCount() const { return m_AIPlayersCount; }
void setAIPlayersCount(uint32 newAIPlayersCount) { m_AIPlayersCount = newAIPlayersCount; }
void quitSoloGame();

private:
Expand All @@ -61,7 +57,6 @@ class TanksWar : public Game
void applyClientGameAttribute();

clientNS::ClientStatus m_status;
AILevel m_aiLevel;
PlayerID m_id;
char m_map[gameNS::MAX_NAME_LEN];
const char* m_pSData, *m_pRData;
Expand All @@ -82,6 +77,5 @@ class TanksWar : public Game
ThisClient m_thisClient;
ThisPlayer m_thisPlayer;
std::vector<std::shared_ptr<AIPlayer>> m_pAIPlayer;
uint32 m_AIPlayersCount;
bool m_soloGameStarted;
};
12 changes: 11 additions & 1 deletion src/Client/thisplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ void ThisPlayer::executeAnimateRepeat()
m_handleInput = true;
m_health = 100;
Player::executeAnimateRepeat();
}
}

void ThisPlayer::reset()
{
m_rotate = V3();
m_position = V3();
m_health = logicNS::HEALTH_TANK;
m_velocity = logicNS::VELOCITY_TANK;
m_inflictedDamage = 0;
m_madeKills = 0;
}
1 change: 1 addition & 0 deletions src/Client/thisplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ThisPlayer : public Player
virtual void update();
virtual void executeDie();
virtual void executeAnimateRepeat();
virtual void reset();

protected:

Expand Down
4 changes: 4 additions & 0 deletions src/Server/Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
<ClInclude Include="..\common\image.h" />
<ClInclude Include="..\common\input.h" />
<ClInclude Include="..\common\interface.h" />
<ClInclude Include="..\common\line.h" />
<ClInclude Include="..\common\map.h" />
<ClInclude Include="..\common\net.h" />
<ClInclude Include="..\common\node.h" />
<ClInclude Include="..\common\object.h" />
<ClInclude Include="..\common\player.h" />
<ClInclude Include="..\common\serverplayer.h" />
Expand Down Expand Up @@ -67,8 +69,10 @@
<ClCompile Include="..\common\imgui\imgui_widgets.cpp" />
<ClCompile Include="..\common\input.cpp" />
<ClCompile Include="..\common\interface.cpp" />
<ClCompile Include="..\common\line.cpp" />
<ClCompile Include="..\common\map.cpp" />
<ClCompile Include="..\common\net.cpp" />
<ClCompile Include="..\common\node.cpp" />
<ClCompile Include="..\common\object.cpp" />
<ClCompile Include="..\common\player.cpp" />
<ClCompile Include="..\common\serverplayer.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions src/Server/Server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
<ClInclude Include="..\common\inlined.inl">
<Filter>Common\Headers</Filter>
</ClInclude>
<ClInclude Include="..\common\node.h">
<Filter>Common\Headers</Filter>
</ClInclude>
<ClInclude Include="..\common\line.h">
<Filter>Common\Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\common\texturemanger.cpp">
Expand Down Expand Up @@ -209,6 +215,12 @@
<ClCompile Include="..\common\sprite.cpp">
<Filter>Common\Sources</Filter>
</ClCompile>
<ClCompile Include="..\common\node.cpp">
<Filter>Common\Sources</Filter>
</ClCompile>
<ClCompile Include="..\common\line.cpp">
<Filter>Common\Sources</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="..\common\pixel.hlsl">
Expand Down
2 changes: 1 addition & 1 deletion src/Server/tankswarServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void TanksWarServer::send(Client* pClient, int32 size, bool sbClear)

void TanksWarServer::resetClientGameStatus(Client* pClient)
{
Space space = m_pMap->getRandomEmptySpace();
Space space = m_pMap->getRandomEmptySpace(pClient);
V3 position = V3(space.v1.x, space.v1.y, 0);
pClient->setPosition(position);
pClient->setRotate(V3(0, 0, 0));
Expand Down
22 changes: 19 additions & 3 deletions src/common/aiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
#include "gamemath.h"
#include "object.h"
#include "texturemanger.h"
#include "timer.h"

AIPlayer::AIPlayer() : m_pTargetObject(nullptr)
using namespace logicNS;

AIPlayer::AIPlayer() : m_pTargetObject(nullptr), m_onAttack(false), m_onMoving(false)
{
}

AIPlayer::~AIPlayer()
{
}

void AIPlayer::initialize(Game * pGame, PlayerID id, const char * name)
void AIPlayer::initialize(Game * pGame, PlayerID id, const std::string& name)
{
Player::initialize(id, name, PLAYER_ENEMY, pGame);
}
Expand All @@ -27,6 +30,13 @@ void AIPlayer::update()
if (m_health <= 0)
return;

static std::map<AILevel, AIEnemySearchDelay> enemySearchDelayAI =
{
{ AI_LEVEL_EASY, AI_SEARCH_EASY },
{ AI_LEVEL_MEDUIM, AI_SEARCH_MEDUIM },
{ AI_LEVEL_HARD, AI_SEARCH_HARD }
};

if (m_pMap->isValidObject(m_pTargetObject))
{
moveTowardsObject(m_pTargetObject);
Expand All @@ -35,7 +45,12 @@ void AIPlayer::update()
}
else
{
lookForEnemy();
int64 timeUntilLastSeacrch = m_pTimer->getCurrentTime() - m_lastSeachEnemyTime;
if (timeUntilLastSeacrch >= enemySearchDelayAI[(AILevel)g_pGameSettings->aiLevel])
{
lookForEnemy();
m_lastSeachEnemyTime = m_pTimer->getCurrentTime();
}
}

if (GetAsyncKeyState(VK_F12))
Expand Down Expand Up @@ -109,6 +124,7 @@ void AIPlayer::attackOjbect(Object * pObject)
{
auto bulletWidth = m_pTextureManger->getTexture("bullet")->getWidth();
Vector3D toTargetVector = Vector3D(getSpace().getCenter(), m_pTargetObject->getSpace().getCenter(), bulletWidth);

if (!m_pMap->isVectorUnderFreespace(toTargetVector, { this, m_pTargetObject }))
{
m_onMoving = false, m_onAttack = false;
Expand Down
5 changes: 3 additions & 2 deletions src/common/aiplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class AIPlayer : public Player

AIPlayer();
~AIPlayer();
virtual void initialize(Game* pGame, PlayerID id, const char* name);
virtual void initialize(Game* pGame, PlayerID id, const std::string& name);
virtual void update();
std::vector<V3> getPath() const { return m_path; }
virtual void executeAnimateRepeat();

private:

void lookForEnemy();
Expand All @@ -31,4 +31,5 @@ class AIPlayer : public Player
Object* m_pTargetObject;
std::vector<V3> m_path;
bool m_onMoving, m_onAttack;
int64 m_lastSeachEnemyTime, m_lastShotTime;
};
44 changes: 22 additions & 22 deletions src/common/collisionshader.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,10 @@ ret

const BYTE g_pCollisionShader[] =
{
68, 88, 66, 67, 14, 131,
218, 41, 10, 112, 114, 54,
91, 206, 171, 4, 104, 245,
169, 171, 1, 0, 0, 0,
68, 88, 66, 67, 229, 224,
155, 28, 34, 110, 180, 197,
44, 89, 100, 36, 140, 180,
214, 254, 1, 0, 0, 0,
44, 27, 1, 0, 6, 0,
0, 0, 56, 0, 0, 0,
112, 3, 0, 0, 128, 3,
Expand Down Expand Up @@ -3992,11 +3992,11 @@ const BYTE g_pCollisionShader[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 148, 46,
49, 1, 26, 105, 65, 101,
1, 0, 0, 0, 54, 0,
167, 243, 148, 4, 188, 70,
175, 16, 130, 155, 145, 87,
91, 41, 0, 0, 0, 0,
49, 1, 67, 2, 67, 101,
1, 0, 0, 0, 42, 252,
144, 155, 136, 203, 187, 72,
143, 205, 41, 67, 8, 93,
13, 149, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
Expand Down Expand Up @@ -4166,7 +4166,7 @@ const BYTE g_pCollisionShader[] =
25, 96, 3, 0, 80, 133,
1, 0, 187, 122, 1, 0,
13, 245, 0, 0, 14, 98,
1, 0, 233, 249, 0, 0,
1, 0, 226, 245, 0, 0,
35, 50, 0, 0, 146, 230,
3, 0, 250, 112, 1, 0,
193, 96, 0, 0, 168, 190,
Expand All @@ -4180,7 +4180,7 @@ const BYTE g_pCollisionShader[] =
15, 122, 1, 0, 118, 19,
1, 0, 199, 197, 0, 0,
195, 33, 2, 0, 53, 40,
2, 0, 15, 227, 0, 0,
2, 0, 202, 221, 0, 0,
237, 206, 3, 0, 255, 226,
0, 0, 40, 178, 2, 0,
229, 4, 2, 0, 55, 93,
Expand Down Expand Up @@ -5102,8 +5102,8 @@ const BYTE g_pCollisionShader[] =
65, 76, 95, 67, 79, 76,
76, 73, 68, 69, 68, 32,
27, 226, 48, 1, 128, 0,
0, 0, 208, 252, 130, 49,
60, 12, 218, 1, 1, 0,
0, 0, 176, 233, 43, 18,
48, 13, 218, 1, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
Expand Down Expand Up @@ -11216,7 +11216,7 @@ const BYTE g_pCollisionShader[] =
0, 0, 0, 0, 12, 0,
86, 51, 0, 243, 242, 241,
14, 0, 23, 21, 26, 16,
0, 0, 0, 2, 144, 0,
0, 0, 0, 2, 176, 0,
16, 0, 242, 241, 10, 0,
1, 18, 1, 0, 0, 0,
27, 16, 0, 0, 26, 0,
Expand Down Expand Up @@ -11362,7 +11362,7 @@ const BYTE g_pCollisionShader[] =
12, 0, 86, 51, 96, 80,
65, 67, 75, 69, 68, 0,
14, 0, 23, 21, 5, 16,
0, 0, 0, 2, 144, 0,
0, 0, 0, 2, 176, 0,
16, 0, 242, 241, 10, 0,
1, 18, 1, 0, 0, 0,
6, 16, 0, 0, 10, 0,
Expand Down Expand Up @@ -12630,11 +12630,11 @@ const BYTE g_pCollisionShader[] =
224, 79, 0, 0, 0, 0,
0, 0, 84, 58, 0, 0,
1, 0, 0, 0, 232, 166,
11, 0, 0, 0, 0, 0,
179, 0, 0, 0, 0, 0,
0, 0, 0, 0, 109, 97,
105, 110, 0, 110, 111, 110,
101, 0, 0, 0, 45, 186,
46, 241, 1, 0, 97, 0,
46, 241, 1, 0, 82, 0,
0, 0, 0, 0, 240, 56,
0, 0, 32, 0, 0, 96,
0, 0, 66, 0, 0, 0,
Expand Down Expand Up @@ -12696,11 +12696,11 @@ const BYTE g_pCollisionShader[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 148, 46,
49, 1, 26, 105, 65, 101,
1, 0, 0, 0, 54, 0,
167, 243, 148, 4, 188, 70,
175, 16, 130, 155, 145, 87,
91, 41, 134, 0, 0, 0,
49, 1, 67, 2, 67, 101,
1, 0, 0, 0, 42, 252,
144, 155, 136, 203, 187, 72,
143, 205, 41, 67, 8, 93,
13, 149, 134, 0, 0, 0,
47, 76, 105, 110, 107, 73,
110, 102, 111, 0, 47, 110,
97, 109, 101, 115, 0, 47,
Expand Down
21 changes: 17 additions & 4 deletions src/common/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace gameNS
constexpr auto UPDATE_DELAY_FPS = 800;
constexpr auto AUDIO_DEFAULT = true;
constexpr auto COMPUTESHADER_DEFAULT = false;
constexpr auto AILEVEL_DEFAULT = 1;
constexpr auto DEBUGMODE_DEFAULT = false;
constexpr auto LOGO_SHOW_TIME = 800;
#ifdef _SRVER_BUILD
Expand Down Expand Up @@ -132,6 +133,20 @@ namespace logicNS
constexpr auto VELOCITY_TANK = 3.0f;
constexpr auto DEFAULT_BITMAP_DAMAGEFACTOR = 1.0f;
constexpr auto DEFAULT_BITMAP_VELOCITYFACTOR = 1.0f;

enum AIEnemySearchDelay : uint32
{
AI_SEARCH_EASY = 1000,
AI_SEARCH_MEDUIM = 400,
AI_SEARCH_HARD = 0
};

enum AIShotDelay : uint32
{
AI_SHOT_EASY = 300,
AI_SHOT_MEDUIM = 80,
AI_SHOT_HARD = 0
};
}

namespace networkNS
Expand Down Expand Up @@ -278,7 +293,7 @@ enum MatrixType
MATRIX_TYPE_ROTATE,
};

enum PacketType_
enum PacketType : char
{
PACKET_START_SEASSON = 100,
PACKET_DISCONNECT,
Expand All @@ -294,9 +309,7 @@ enum PacketType_
PACKET_CLIENT_GAME_ATTRIBUTE
};

typedef char PacketType;

enum AILevel : uint8
enum AILevel : uint32
{
AI_LEVEL_EASY,
AI_LEVEL_MEDUIM,
Expand Down
2 changes: 1 addition & 1 deletion src/common/dx11wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void Dx11Wrapper::psSetSRV(ID3D11ShaderResourceView ** ppSRV, uint32 numViews, u
m_pDeviceContext->PSSetShaderResources(startSlot, numViews, ppSRV);
}

bool Dx11Wrapper::createSRVFromFile(const std::string & file, ID3D11ShaderResourceView ** ppSRV, int32& width, int32& height)
bool Dx11Wrapper::createSRVFromFile(const std::string & file, ID3D11ShaderResourceView ** ppSRV, uint32& width, uint32& height)
{
D3DX11_IMAGE_INFO info;
if (FAILED(D3DX11GetImageInfoFromFileA(file.c_str(), 0, &info, 0)))
Expand Down
2 changes: 1 addition & 1 deletion src/common/dx11wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Dx11Wrapper
void d3dDraw(uint32 vertexCount, uint32 startVertex);
void d3dDrawIndexed(uint32 indexCount, uint32 startIndex, uint32 baseVertex);
void psSetSRV(ID3D11ShaderResourceView** ppSRV, uint32 numViews = 1, uint32 startSlot = 0);
bool createSRVFromFile(const std::string& file, ID3D11ShaderResourceView ** ppSRV, int32& width, int32& height);
bool createSRVFromFile(const std::string& file, ID3D11ShaderResourceView ** ppSRV, uint32& width, uint32& height);
Microsoft::WRL::ComPtr<ID3D11Buffer> createBuffer(D3D11_USAGE usage, D3D11_BIND_FLAG bindFlag, uint32 cpuAccess, uint32 byteWidth, uint32 stride = 0,
void* initialData = 0, uint32 miscFlag = 0) const;
Microsoft::WRL::ComPtr<ID3D11Buffer> createVertexBuffer(uint32 vertices, uint32 cpuAccess, Vertex* data = 0);
Expand Down
Loading

0 comments on commit 6a8b8e5

Please sign in to comment.