forked from teamnwah/openmw-tes3coop
[General] Make WorldTime script functions more consistent with others
This commit is contained in:
parent
8d36d0d945
commit
46744ee90f
4 changed files with 41 additions and 55 deletions
|
@ -12,66 +12,35 @@ using namespace mwmp;
|
|||
|
||||
BaseWorldstate writeWorldstate;
|
||||
|
||||
void WorldstateFunctions::SetHour(unsigned short pid, double hour) noexcept
|
||||
void WorldstateFunctions::SetHour(double hour) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
writeWorldstate.guid = player->guid;
|
||||
|
||||
writeWorldstate.hour = hour;
|
||||
writeWorldstate.day = -1;
|
||||
writeWorldstate.month = -1;
|
||||
writeWorldstate.timeScale = -1;
|
||||
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate);
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false);
|
||||
}
|
||||
|
||||
void WorldstateFunctions::SetDay(unsigned short pid, int day) noexcept
|
||||
void WorldstateFunctions::SetDay(int day) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
writeWorldstate.guid = player->guid;
|
||||
|
||||
writeWorldstate.hour = -1;
|
||||
writeWorldstate.day = day;
|
||||
writeWorldstate.month = -1;
|
||||
writeWorldstate.timeScale = -1;
|
||||
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate);
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false);
|
||||
}
|
||||
|
||||
void WorldstateFunctions::SetMonth(unsigned short pid, int month) noexcept
|
||||
void WorldstateFunctions::SetMonth(int month) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
writeWorldstate.guid = player->guid;
|
||||
|
||||
writeWorldstate.hour = -1;
|
||||
writeWorldstate.day = -1;
|
||||
writeWorldstate.month = month;
|
||||
writeWorldstate.timeScale = -1;
|
||||
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate);
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false);
|
||||
}
|
||||
|
||||
void WorldstateFunctions::SetTimeScale(unsigned short pid, double timeScale) noexcept
|
||||
void WorldstateFunctions::SetTimeScale(double timeScale) noexcept
|
||||
{
|
||||
writeWorldstate.timeScale = timeScale;
|
||||
}
|
||||
void WorldstateFunctions::SendWorldTime(unsigned short pid, bool toOthers) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
writeWorldstate.guid = player->guid;
|
||||
|
||||
writeWorldstate.hour = -1;
|
||||
writeWorldstate.day = -1;
|
||||
writeWorldstate.month = -1;
|
||||
writeWorldstate.timeScale = timeScale;
|
||||
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate);
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false);
|
||||
|
||||
if (toOthers)
|
||||
mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(true);
|
||||
}
|
||||
|
|
|
@ -7,47 +7,58 @@
|
|||
{"SetHour", WorldstateFunctions::SetHour},\
|
||||
{"SetDay", WorldstateFunctions::SetDay},\
|
||||
{"SetMonth", WorldstateFunctions::SetMonth},\
|
||||
{"SetTimeScale", WorldstateFunctions::SetTimeScale}
|
||||
{"SetTimeScale", WorldstateFunctions::SetTimeScale},\
|
||||
\
|
||||
{"SendWorldTime", WorldstateFunctions::SendWorldTime}
|
||||
|
||||
class WorldstateFunctions
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Set the world's hour for a player and send a WorldTime packet to that player.
|
||||
* \brief Set the world's hour in the worldstate stored on the server.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \param hour The hour.
|
||||
* \return void
|
||||
*/
|
||||
static void SetHour(unsigned short pid, double hour) noexcept;
|
||||
static void SetHour(double hour) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the world's day of the month for a player and send a WorldTime packet to that player.
|
||||
* \brief Set the world's day in the worldstate stored on the server.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \param day The day.
|
||||
* \return void
|
||||
*/
|
||||
static void SetDay(unsigned short pid, int day) noexcept;
|
||||
static void SetDay(int day) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the world's month for a player and send a WorldTime packet to that player.
|
||||
* \brief Set the world's month in the worldstate stored on the server.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \param month The month.
|
||||
* \return void
|
||||
*/
|
||||
static void SetMonth(unsigned short pid, int month) noexcept;
|
||||
static void SetMonth(int month) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the world's time scale for a player and send a WorldTime packet to that player.
|
||||
* \brief Set the world's time scale in the worldstate stored on the server.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \param timeScale The time scale.
|
||||
* \return void
|
||||
*/
|
||||
static void SetTimeScale(unsigned short pid, double timeScale) noexcept;
|
||||
static void SetTimeScale(double timeScale) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Send a WorldTime packet with the current time and time scale
|
||||
* to a specific player or to all players.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \return void
|
||||
*/
|
||||
static void SendWorldTime(unsigned short pid, bool toOthers = false) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -23,11 +23,14 @@ namespace mwmp
|
|||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
if (worldstate.hour != -1)
|
||||
world->setHour(worldstate.hour);
|
||||
else if (worldstate.day != -1)
|
||||
|
||||
if (worldstate.day != -1)
|
||||
world->setDay(worldstate.day);
|
||||
else if (worldstate.month != -1)
|
||||
|
||||
if (worldstate.month != -1)
|
||||
world->setMonth(worldstate.month);
|
||||
else if (worldstate.timeScale != -1)
|
||||
|
||||
if (worldstate.timeScale != -1)
|
||||
world->setTimeScale(worldstate.timeScale);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,10 @@ namespace mwmp
|
|||
|
||||
BaseWorldstate()
|
||||
{
|
||||
|
||||
month = -1;
|
||||
day = -1;
|
||||
hour = -1;
|
||||
timeScale = -1;
|
||||
}
|
||||
|
||||
RakNet::RakNetGUID guid;
|
||||
|
|
Loading…
Reference in a new issue