Skip to content

Commit

Permalink
Solar Control commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverpechey committed Aug 18, 2023
1 parent cceb8ac commit 84687a2
Show file tree
Hide file tree
Showing 9 changed files with 800 additions and 99 deletions.
2 changes: 1 addition & 1 deletion FLHookSDK
101 changes: 49 additions & 52 deletions plugins/npc_control/NPCControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace Plugins::Npc
/** @ingroup NPCControl
* @brief Checks if a ship is one of our spawned NPCs and if so, removes it from our data
*/
bool IsFLHookNPC(CShip* ship)
bool IsHookNPC(CShip* ship)
{
// If it's a player do nothing
if (ship->is_player() == true)
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace Plugins::Npc
if (kill)
{
CShip* cShip = Hk::Player::CShipFromShipDestroyed(ecx);
IsFLHookNPC(cShip);
IsHookNPC(cShip);
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ namespace Plugins::Npc
*/
void LoadSettings()
{
global->Log = spdlog::basic_logger_mt<spdlog::async_factory>("flhook_npcs", "logs/npc.log");
global->Log = spdlog::basic_logger_mt<spdlog::async_factory>("npcs", "logs/npc.log");
auto config = Serializer::JsonToObject<Config>();

for (auto& [name, npc] : config.npcInfo)
Expand Down Expand Up @@ -325,23 +325,23 @@ namespace Plugins::Npc
/** @ingroup NPCControl
* @brief Admin command to destroy the AI
*/
void AdminCmdAIKill(CCmds* cmds)
void AdminCmdAIKill(CCmds* commands)
{
if (!(cmds->rights & RIGHT_SUPERADMIN))
if (!(commands->rights & RIGHT_SUPERADMIN))
{
cmds->Print("ERR No permission");
commands->Print("ERR No permission");
return;
}

// Destroy targeted ship
if (cmds->IsPlayer())
if (commands->IsPlayer())
{
if (auto const target = Hk::Player::GetTarget(cmds->GetAdminName()); target.has_value())
if (auto const target = Hk::Player::GetTarget(commands->GetAdminName()); target.has_value())
{
if (const auto it = std::ranges::find(global->spawnedNpcs, target.value()); target.value() && it != global->spawnedNpcs.end())
{
pub::SpaceObj::Destroy(target.value(), DestroyType::FUSE);
cmds->Print("OK");
commands->Print("OK");
return;
}
}
Expand All @@ -351,21 +351,21 @@ namespace Plugins::Npc
for (std::vector<uint> tempSpawnedNpcs = global->spawnedNpcs; const auto& npc : tempSpawnedNpcs)
pub::SpaceObj::Destroy(npc, DestroyType::FUSE);

cmds->Print("OK");
commands->Print("OK");
}

/** @ingroup NPCControl
* @brief Admin command to make AI come to your position
*/
void AdminCmdAICome(CCmds* cmds)
void AdminCmdAICome(CCmds* commands)
{
if (!(cmds->rights & RIGHT_SUPERADMIN))
if (!(commands->rights & RIGHT_SUPERADMIN))
{
cmds->Print("ERR No permission");
commands->Print("ERR No permission");
return;
}

if (auto ship = Hk::Player::GetShip(Hk::Client::GetClientIdFromCharName(cmds->GetAdminName()).value()); ship.has_value())
if (auto ship = Hk::Player::GetShip(Hk::Client::GetClientIdFromCharName(commands->GetAdminName()).value()); ship.has_value())
{
auto [pos, rot] = Hk::Solar::GetLocation(ship.value(), IdType::Ship).value();

Expand All @@ -384,7 +384,7 @@ namespace Plugins::Npc
pub::AI::SubmitDirective(npc, &go);
}
}
cmds->Print("OK");
commands->Print("OK");
return;
}

Expand All @@ -401,27 +401,27 @@ namespace Plugins::Npc
/** @ingroup NPCControl
* @brief Admin command to make AI follow target (or admin) until death
*/
void AdminCmdAIFollow(CCmds* cmds, std::wstring charname)
void AdminCmdAIFollow(CCmds* commands, std::wstring characterName)
{
if (!(cmds->rights & RIGHT_SUPERADMIN))
if (!(commands->rights & RIGHT_SUPERADMIN))
{
cmds->Print("ERR No permission");
commands->Print("ERR No permission");
return;
}

// If no player specified follow the admin
uint client;
if (charname == L"")
if (characterName == L"")
{
client = Hk::Client::GetClientIdFromCharName(cmds->GetAdminName()).value();
charname = cmds->GetAdminName();
client = Hk::Client::GetClientIdFromCharName(commands->GetAdminName()).value();
characterName = commands->GetAdminName();
}
// Follow the player specified
else
client = Hk::Client::GetClientIdFromCharName(charname).value();
client = Hk::Client::GetClientIdFromCharName(characterName).value();

if (client == UINT_MAX)
cmds->Print(std::format("{} is not online", wstos(charname)));
commands->Print(std::format("{} is not online", wstos(characterName)));

else
{
Expand All @@ -439,29 +439,29 @@ namespace Plugins::Npc
for (const auto& npc : global->spawnedNpcs)
AiFollow(ship.value(), npc);
}
cmds->Print(std::format("Following {}", wstos(charname)));
commands->Print(std::format("Following {}", wstos(characterName)));
}
}
else
{
cmds->Print(std::format("{} is not in space", wstos(charname)));
commands->Print(std::format("{} is not in space", wstos(characterName)));
}
}
}

/** @ingroup NPCControl
* @brief Admin command to cancel the current operation
*/
void AdminCmdAICancel(CCmds* cmds)
void AdminCmdAICancel(CCmds* commands)
{
if (!(cmds->rights & RIGHT_SUPERADMIN))
if (!(commands->rights & RIGHT_SUPERADMIN))
{
cmds->Print("ERR No permission");
commands->Print("ERR No permission");
return;
}

// Is the admin targeting an NPC?
if (const auto target = Hk::Player::GetTarget(cmds->GetAdminName()); target.has_value())
if (const auto target = Hk::Player::GetTarget(commands->GetAdminName()); target.has_value())
{
if (const auto it = std::ranges::find(global->spawnedNpcs, target.value()); target.value() && it != global->spawnedNpcs.end())
{
Expand All @@ -478,24 +478,24 @@ namespace Plugins::Npc
pub::AI::SubmitDirective(npc, &cancelOp);
}
}
cmds->Print("OK");
commands->Print("OK");
}

/** @ingroup NPCControl
* @brief Admin command to list NPCs
*/
void AdminCmdListNPCs(CCmds* cmds)
void AdminCmdListNPCs(CCmds* commands)
{
if (!(cmds->rights & RIGHT_SUPERADMIN))
if (!(commands->rights & RIGHT_SUPERADMIN))
{
cmds->Print("ERR No permission");
commands->Print("ERR No permission");
return;
}

cmds->Print(std::format("Available NPCs: {}", global->config->npcInfo.size()));
commands->Print(std::format("Available NPCs: {}", global->config->npcInfo.size()));

for (auto const& [name, npc] : global->config->npcInfo)
cmds->Print(std::format("|{}", wstos(name)));
commands->Print(std::format("|{}", wstos(name)));
}

/** @ingroup NPCControl
Expand All @@ -518,47 +518,47 @@ namespace Plugins::Npc
/** @ingroup NPCControl
* @brief Admin command to spawn a Fleet
*/
void AdminCmdAIFleet(CCmds* cmds, const std::wstring& FleetName)
void AdminCmdAIFleet(CCmds* commands, const std::wstring& FleetName)
{
if (!(cmds->rights & RIGHT_SUPERADMIN))
if (!(commands->rights & RIGHT_SUPERADMIN))
{
cmds->Print("ERR No permission");
commands->Print("ERR No permission");
return;
}

if (const auto& iter = global->config->fleetInfo.find(FleetName); iter != global->config->fleetInfo.end())
for (auto const& [name, amount] : iter->second.member)
AdminCmdAIMake(cmds, amount, name);
AdminCmdAIMake(commands, amount, name);
else
{
cmds->Print("ERR Wrong Fleet name");
commands->Print("ERR Wrong Fleet name");
return;
}
}

/** @ingroup NPCControl
* @brief Admin command processing
*/
bool ExecuteCommandString(CCmds* cmds, const std::wstring& cmd)
bool ExecuteCommandString(CCmds* commands, const std::wstring& cmd)
{
global->returnCode = ReturnCode::SkipAll;

if (cmd == L"aicreate")
AdminCmdAIMake(cmds, cmds->ArgInt(1), cmds->ArgStr(2));
AdminCmdAIMake(commands, commands->ArgInt(1), commands->ArgStr(2));
else if (cmd == L"aidestroy")
AdminCmdAIKill(cmds);
AdminCmdAIKill(commands);
else if (cmd == L"aicancel")
AdminCmdAICancel(cmds);
AdminCmdAICancel(commands);
else if (cmd == L"aifollow")
AdminCmdAIFollow(cmds, cmds->ArgCharname(1));
AdminCmdAIFollow(commands, commands->ArgCharname(1));
else if (cmd == L"aicome")
AdminCmdAICome(cmds);
AdminCmdAICome(commands);
else if (cmd == L"aifleet")
AdminCmdAIFleet(cmds, cmds->ArgStr(1));
AdminCmdAIFleet(commands, commands->ArgStr(1));
else if (cmd == L"fleetlist")
AdminCmdListNPCFleets(cmds);
AdminCmdListNPCFleets(commands);
else if (cmd == L"npclist")
AdminCmdListNPCs(cmds);
AdminCmdListNPCs(commands);
else
{
global->returnCode = ReturnCode::Default;
Expand All @@ -571,9 +571,6 @@ namespace Plugins::Npc
NpcCommunicator::NpcCommunicator(const std::string& plug) : PluginCommunicator(plug) { this->CreateNpc = CreateNPC; }
} // namespace Plugins::Npc

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FLHOOK STUFF
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace Plugins::Npc;

DefaultDllMainSettings(AfterStartup);
Expand Down
14 changes: 7 additions & 7 deletions plugins/npc_control/NPCControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@
namespace Plugins::Npc
{
//! A struct that represents an npc that can be spawned
struct Npc : Reflectable
struct Npc final : Reflectable
{
std::string shipArch = "ge_fighter";
std::string loadout = "MP_ge_fighter";
std::string iff = "fc_fl_grp";
uint iffId;
uint iffId = 0;
uint infocardId = 197808;
uint infocard2Id = 197809;
std::string pilot = "pilot_pirate_ace";
std::string graph = "FIGHTER"; // NOTHING, FIGHTER, TRANSPORT, GUNBOAT, CRUISER. Possibly (unconfirmed) MINER, CAPITAL, FREIGHTER

uint shipArchId;
uint loadoutId;
uint shipArchId = 0;
uint loadoutId = 0;
};

// A struct that represents a fleet that can be spawned
struct Fleet : Reflectable
struct Fleet final : Reflectable
{
std::wstring name = L"example";
std::map<std::wstring, int> member = {{L"example", 5}};
};

// A struct that represents an NPC that is spawned on startup
struct StartupNpc : Reflectable
struct StartupNpc final : Reflectable
{
std::wstring name = L"example";
std::string system = "li01";
Expand All @@ -46,7 +46,7 @@ namespace Plugins::Npc
};

//! Config data for this plugin
struct Config : Reflectable
struct Config final : Reflectable
{
//! Map of npcs that can be spawned
std::map<std::wstring, Npc> npcInfo = {{L"example", Npc()}};
Expand Down
Loading

0 comments on commit 84687a2

Please sign in to comment.