Remove a direct src include from lib/gamelib.
parent
3ff588daab
commit
e32c1f0e89
|
@ -27,7 +27,6 @@
|
|||
#include "lib/framework/frame.h"
|
||||
#include "lib/framework/wzapp_c.h"
|
||||
#include "gtime.h"
|
||||
#include "src/multiplay.h"
|
||||
#include "lib/netplay/netplay.h"
|
||||
|
||||
#include <time.h>
|
||||
|
@ -48,9 +47,9 @@ static UDWORD baseTime;
|
|||
/** When the game paused, so that gameTime can be adjusted when the game restarts. */
|
||||
static SDWORD pauseStart;
|
||||
|
||||
/**
|
||||
* Count how many times gameTimeStop has been called without a game time start.
|
||||
* We use this to ensure that we can properly nest stop commands.
|
||||
/**
|
||||
* Count how many times gameTimeStop has been called without a game time start.
|
||||
* We use this to ensure that we can properly nest stop commands.
|
||||
**/
|
||||
static UDWORD stopCount;
|
||||
|
||||
|
@ -193,10 +192,10 @@ void gameTimeUpdate()
|
|||
baseTime = currTime;
|
||||
timeOffset = graphicsTime;
|
||||
|
||||
debug(LOG_SYNC, "Waiting for other players. gameTime = %u, player times are {%s}", gameTime, listToString("%u", ", ", gameQueueTime, gameQueueTime + game.maxPlayers).c_str());
|
||||
debug(LOG_SYNC, "Waiting for other players. gameTime = %u, player times are {%s}", gameTime, listToString("%u", ", ", gameQueueTime, gameQueueTime + NetPlay.maxPlayers).c_str());
|
||||
mayUpdate = false;
|
||||
|
||||
for (player = 0; player < game.maxPlayers; ++player)
|
||||
for (player = 0; player < NetPlay.maxPlayers; ++player)
|
||||
{
|
||||
if (!checkPlayerGameTime(player))
|
||||
{
|
||||
|
@ -225,8 +224,8 @@ void gameTimeUpdate()
|
|||
updateLatency();
|
||||
if (crcError)
|
||||
{
|
||||
debug(LOG_ERROR, "Synch error, gameTimes were: {%s}", listToString("%10u", ", ", gameQueueCheckTime, gameQueueCheckTime + game.maxPlayers).c_str());
|
||||
debug(LOG_ERROR, "Synch error, CRCs were: {%s}", listToString("0x%08X", ", ", gameQueueCheckCrc, gameQueueCheckCrc + game.maxPlayers).c_str());
|
||||
debug(LOG_ERROR, "Synch error, gameTimes were: {%s}", listToString("%10u", ", ", gameQueueCheckTime, gameQueueCheckTime + NetPlay.maxPlayers).c_str());
|
||||
debug(LOG_ERROR, "Synch error, CRCs were: {%s}", listToString("0x%08X", ", ", gameQueueCheckCrc, gameQueueCheckCrc + NetPlay.maxPlayers).c_str());
|
||||
crcError = false;
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +362,7 @@ static void updateLatency()
|
|||
uint16_t prevDiscreteChosenLatency = discreteChosenLatency;
|
||||
|
||||
// Find out what latency has been agreed on, next.
|
||||
for (player = 0; player < game.maxPlayers; ++player)
|
||||
for (player = 0; player < NetPlay.maxPlayers; ++player)
|
||||
{
|
||||
if (!NetPlay.players[player].kick) // .kick: Don't wait for dropped players.
|
||||
{
|
||||
|
@ -396,7 +395,7 @@ void sendPlayerGameTime()
|
|||
uint32_t checkTime = gameTime;
|
||||
uint32_t checkCrc = nextDebugSync();
|
||||
|
||||
for (player = 0; player < game.maxPlayers; ++player)
|
||||
for (player = 0; player < NetPlay.maxPlayers; ++player)
|
||||
{
|
||||
if (!myResponsibility(player) && whosResponsible(player) != realSelectedPlayer)
|
||||
{
|
||||
|
@ -450,7 +449,7 @@ bool checkPlayerGameTime(unsigned player)
|
|||
if (player == NET_ALL_PLAYERS)
|
||||
{
|
||||
begin = 0;
|
||||
end = game.maxPlayers;
|
||||
end = NetPlay.maxPlayers;
|
||||
}
|
||||
|
||||
for (player = begin; player < end; ++player)
|
||||
|
@ -468,7 +467,7 @@ void setPlayerGameTime(unsigned player, uint32_t time)
|
|||
{
|
||||
if (player == NET_ALL_PLAYERS)
|
||||
{
|
||||
for (player = 0; player < game.maxPlayers; ++player)
|
||||
for (player = 0; player < NetPlay.maxPlayers; ++player)
|
||||
{
|
||||
gameQueueTime[player] = time;
|
||||
}
|
||||
|
|
|
@ -786,7 +786,7 @@ int NETclose(void)
|
|||
{
|
||||
unsigned int i;
|
||||
|
||||
// reset flag
|
||||
// reset flag
|
||||
NEThaltJoining();
|
||||
|
||||
debug(LOG_NET, "Terminating sockets.");
|
||||
|
@ -1332,7 +1332,7 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type)
|
|||
/*
|
||||
* Checks to see if a human player is still with us.
|
||||
* @note: resuscitation isn't possible with current code, so once we lose
|
||||
* the socket, then we have no way to connect with them again. Future
|
||||
* the socket, then we have no way to connect with them again. Future
|
||||
* item to enhance.
|
||||
*/
|
||||
static void NETcheckPlayers(void)
|
||||
|
@ -1415,7 +1415,7 @@ bool NETrecvNet(NETQUEUE *queue, uint8_t *type)
|
|||
else if (*pSocket == NULL)
|
||||
{
|
||||
// If there is a error in NET_fillBuffer() then socket is already invalid.
|
||||
// This means that the player dropped / disconnected for whatever reason.
|
||||
// This means that the player dropped / disconnected for whatever reason.
|
||||
debug(LOG_INFO, "Player, (player %u) seems to have dropped/disconnected.", (unsigned)current);
|
||||
|
||||
if (NetPlay.isHost)
|
||||
|
@ -1484,10 +1484,10 @@ bool NETrecvGame(NETQUEUE *queue, uint8_t *type)
|
|||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
// File Transfer programs.
|
||||
/** Send file. It returns % of file sent when 100 it's complete. Call until it returns 100.
|
||||
/** Send file. It returns % of file sent when 100 it's complete. Call until it returns 100.
|
||||
* @TODO: more error checking (?) different file types (?)
|
||||
* Maybe should close file handle, and seek each time?
|
||||
*
|
||||
*
|
||||
* @NOTE: MAX_FILE_TRANSFER_PACKET is set to 2k per packet since 7*2 = 14K which is pretty
|
||||
* much our limit. Don't screw with that without having a bigger buffer!
|
||||
* NET_BUFFER_SIZE is at 16k. (also remember text chat, plus all the other cruff)
|
||||
|
@ -1600,7 +1600,7 @@ UBYTE NETrecvFile(NETQUEUE queue)
|
|||
else
|
||||
{
|
||||
uint32_t reason = STUCK_IN_FILE_LOOP;
|
||||
|
||||
|
||||
NETend();
|
||||
// we should never get here, it means, that the game can't detect the level, but we have the file.
|
||||
// so we kick this player out.
|
||||
|
@ -2024,7 +2024,7 @@ bool NEThostGame(const char* SessionName, const char* PlayerName,
|
|||
NetPlay.maxPlayers = plyrs;
|
||||
NETlogEntry("Hosting game, resetting ban list.", SYNC_FLAG, 0);
|
||||
if (IPlist)
|
||||
{
|
||||
{
|
||||
free(IPlist);
|
||||
IPlist = NULL;
|
||||
}
|
||||
|
@ -2709,3 +2709,45 @@ static void addToBanList(const char *ip, const char *name)
|
|||
numBans = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// to determine human/computer players and responsibilities of each..
|
||||
bool isHumanPlayer(int player)
|
||||
{
|
||||
if (player >= MAX_PLAYERS || player < 0)
|
||||
{
|
||||
return false; // obvious, really
|
||||
}
|
||||
return NetPlay.players[player].allocated;
|
||||
}
|
||||
|
||||
// returns player responsible for 'player'
|
||||
int whosResponsible(int player)
|
||||
{
|
||||
if (isHumanPlayer(player))
|
||||
{
|
||||
return player; // Responsible for him or her self
|
||||
}
|
||||
else if (player == selectedPlayer)
|
||||
{
|
||||
return player; // We are responsibly for ourselves
|
||||
}
|
||||
else
|
||||
{
|
||||
return NET_HOST_ONLY; // host responsible for all AIs
|
||||
}
|
||||
}
|
||||
|
||||
//returns true if selected player is responsible for 'player'
|
||||
bool myResponsibility(int player)
|
||||
{
|
||||
return whosResponsible(player) == selectedPlayer;
|
||||
}
|
||||
|
||||
//returns true if 'player' is responsible for 'playerinquestion'
|
||||
bool responsibleFor(int player, int playerinquestion)
|
||||
{
|
||||
return whosResponsible(playerinquestion) == player;
|
||||
}
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ enum
|
|||
};
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
// Player information. Filled when players join, never re-ordered. selectedPlayer global points to
|
||||
// Player information. Filled when players join, never re-ordered. selectedPlayer global points to
|
||||
// currently controlled player.
|
||||
struct PLAYER
|
||||
{
|
||||
|
@ -324,4 +324,10 @@ void resetSyncDebug(void); ///< Resets the
|
|||
uint32_t nextDebugSync(void); ///< Returns a CRC corresponding to all syncDebug() calls since the last nextDebugSync() or resetSyncDebug() call.
|
||||
bool checkDebugSync(uint32_t checkGameTime, uint32_t checkCrc); ///< Dumps all syncDebug() calls from that gameTime, if the CRC doesn't match.
|
||||
|
||||
extern bool isHumanPlayer(int player); //to tell if the player is a computer or not.
|
||||
extern int whosResponsible(int player);
|
||||
extern bool myResponsibility(int player);
|
||||
extern bool responsibleFor(int player, int playerinquestion);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
11
src/ai.cpp
11
src/ai.cpp
|
@ -26,6 +26,9 @@
|
|||
|
||||
#include "lib/framework/frame.h"
|
||||
|
||||
// For isHumanPlayer
|
||||
#include "lib/netplay/netplay.h"
|
||||
|
||||
#include "action.h"
|
||||
#include "cmddroid.h"
|
||||
#include "combat.h"
|
||||
|
@ -219,7 +222,7 @@ static BASE_OBJECT *aiSearchSensorTargets(BASE_OBJECT *psObj, int weapon_slot, W
|
|||
{
|
||||
*targetOrigin = ORIGIN_SENSOR;
|
||||
}
|
||||
|
||||
|
||||
if (isCB)
|
||||
{
|
||||
if (targetOrigin)
|
||||
|
@ -295,7 +298,7 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
|
|||
//go through all enemy weapons
|
||||
for(weaponSlot = 0; !bTargetingCmd && weaponSlot < ((STRUCTURE *)psTarget)->numWeaps; weaponSlot++)
|
||||
{
|
||||
if (((STRUCTURE *)psTarget)->psTarget[weaponSlot] ==
|
||||
if (((STRUCTURE *)psTarget)->psTarget[weaponSlot] ==
|
||||
(BASE_OBJECT *)psAttackerDroid->psGroup->psCommander)
|
||||
{
|
||||
bTargetingCmd = true;
|
||||
|
@ -743,7 +746,7 @@ bool aiChooseTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget, int weapon_slot
|
|||
{
|
||||
*targetOrigin = ORIGIN_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
/* Get the sensor range */
|
||||
switch (psObj->type)
|
||||
{
|
||||
|
@ -1063,7 +1066,7 @@ void aiUpdateDroid(DROID *psDroid)
|
|||
|
||||
lookForTarget = false;
|
||||
updateTarget = false;
|
||||
|
||||
|
||||
// look for a target if doing nothing
|
||||
if (orderState(psDroid, DORDER_NONE) ||
|
||||
orderState(psDroid, DORDER_GUARD) ||
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include "lib/framework/fixedpoint.h"
|
||||
#include "lib/framework/wzapp_c.h"
|
||||
|
||||
// isHumanPlayer
|
||||
#include "lib/netplay/netplay.h"
|
||||
|
||||
#include "action.h"
|
||||
#include "display.h"
|
||||
#include "map.h"
|
||||
|
|
|
@ -452,46 +452,6 @@ bool setPlayerName(int player, const char *sName)
|
|||
return true;
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
// to determine human/computer players and responsibilities of each..
|
||||
bool isHumanPlayer(int player)
|
||||
{
|
||||
if (player >= MAX_PLAYERS || player < 0)
|
||||
{
|
||||
return false; // obvious, really
|
||||
}
|
||||
return NetPlay.players[player].allocated;
|
||||
}
|
||||
|
||||
// returns player responsible for 'player'
|
||||
int whosResponsible(int player)
|
||||
{
|
||||
if (isHumanPlayer(player))
|
||||
{
|
||||
return player; // Responsible for him or her self
|
||||
}
|
||||
else if (player == selectedPlayer)
|
||||
{
|
||||
return player; // We are responsibly for ourselves
|
||||
}
|
||||
else
|
||||
{
|
||||
return NET_HOST_ONLY; // host responsible for all AIs
|
||||
}
|
||||
}
|
||||
|
||||
//returns true if selected player is responsible for 'player'
|
||||
bool myResponsibility(int player)
|
||||
{
|
||||
return whosResponsible(player) == selectedPlayer;
|
||||
}
|
||||
|
||||
//returns true if 'player' is responsible for 'playerinquestion'
|
||||
bool responsibleFor(int player, int playerinquestion)
|
||||
{
|
||||
return whosResponsible(playerinquestion) == player;
|
||||
}
|
||||
|
||||
int scavengerSlot()
|
||||
{
|
||||
// Scavengers used to always be in position 7, when scavengers were only supported in less than 8 player maps.
|
||||
|
|
|
@ -160,10 +160,6 @@ extern WZ_DECL_WARN_UNUSED_RESULT DROID_TEMPLATE *IdToTemplate(UDWORD tempId,UDW
|
|||
extern const char* getPlayerName(int player);
|
||||
extern bool setPlayerName(int player, const char *sName);
|
||||
extern const char* getPlayerColourName(int player);
|
||||
extern bool isHumanPlayer(int player); //to tell if the player is a computer or not.
|
||||
extern bool myResponsibility(int player);
|
||||
extern bool responsibleFor(int player, int playerinquestion);
|
||||
extern int whosResponsible(int player);
|
||||
int scavengerSlot(); // Returns the player number that scavengers would have if they were enabled.
|
||||
int scavengerPlayer(); // Returns the player number that the scavengers have, or -1 if disabled.
|
||||
extern Vector3i cameraToHome (UDWORD player,bool scroll);
|
||||
|
|
Loading…
Reference in New Issue