Skip to content

Commit

Permalink
Implement some stuff needed for AIGroup (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwil authored May 5, 2023
1 parent 516471c commit e2c0ddc
Show file tree
Hide file tree
Showing 25 changed files with 974 additions and 109 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ set(GAMEENGINE_SRC
game/common/thing/thingfactory.cpp
game/common/thing/thingtemplate.cpp
game/logic/ai/ai.cpp
game/logic/ai/aigroup.cpp
game/logic/ai/aipathfind.cpp
game/logic/ai/aiplayer.cpp
game/logic/ai/aistates.cpp
Expand Down Expand Up @@ -332,6 +333,7 @@ set(GAMEENGINE_SRC
game/logic/system/cavesystem.cpp
game/logic/system/cratesystem.cpp
game/logic/system/partitionmanager.cpp
game/logic/system/simpleobjectiterator.cpp
game/network/framemetrics.cpp
game/network/gameinfo.cpp
game/network/gameresultsthread.cpp
Expand Down
16 changes: 16 additions & 0 deletions src/game/client/line2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,19 @@ bool Clip_Line_2D(ICoord2D *p1, ICoord2D *p2, ICoord2D *c1, ICoord2D *c2, IRegio
return x0 >= x_min && x0 <= x_max && y0 >= y_min && y0 <= y_max && x1 >= x_min && x1 <= x_max && y1 >= y_min
&& y1 <= y_max;
}

bool Coord_3D_Inside_Rect_2D(const Coord3D *input_point, const Coord2D *tl, const Coord2D *br)
{
return input_point->x >= tl->x && input_point->x <= br->x && input_point->y >= tl->y && input_point->y <= br->y;
}

void Scale_Rect_2D(Coord2D *tl, Coord2D *br, float scale_factor)
{
float delta = scale_factor - 1.0f;
float x = (br->x - tl->x) * delta * 0.5f;
float y = (br->y - tl->y) * delta * 0.5f;
tl->x = tl->x - x;
tl->y = tl->y - y;
br->x = x + br->x;
br->y = y + br->y;
}
2 changes: 2 additions & 0 deletions src/game/client/line2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
#include "coord.h"

bool Clip_Line_2D(ICoord2D *p1, ICoord2D *p2, ICoord2D *c1, ICoord2D *c2, IRegion2D *clip_region);
bool Coord_3D_Inside_Rect_2D(const Coord3D *input_point, const Coord2D *tl, const Coord2D *br);
void Scale_Rect_2D(Coord2D *tl, Coord2D *br, float scale_factor);
65 changes: 65 additions & 0 deletions src/game/common/rts/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
* LICENSE
*/
#include "actionmanager.h"
#include "behaviormodule.h"
#include "object.h"
#include "player.h"
#include "specialpower.h"
#include "terrainlogic.h"
#ifdef GAME_DLL
#include "hooker.h"
#endif
Expand All @@ -31,3 +36,63 @@ bool ActionManager::Can_Enter_Object(
return false;
#endif
}

bool ActionManager::Can_Do_Special_Power(
const Object *obj, const SpecialPowerTemplate *sp_template, CommandSourceType source, unsigned int i, bool b)
{
#ifdef GAME_DLL
return Call_Method<bool,
ActionManager,
const Object *,
const SpecialPowerTemplate *,
CommandSourceType,
unsigned int,
bool>(PICK_ADDRESS(0x00497A70, 0x008E202D), this, obj, sp_template, source, i, b);
#else
return false;
#endif
}

bool ActionManager::Can_Do_Special_Power_At_Location(const Object *obj,
const Coord3D *loc,
CommandSourceType source,
const SpecialPowerTemplate *sp_template,
const Object *object_in_way,
unsigned int i,
bool b)
{
#ifdef GAME_DLL
return Call_Method<bool,
ActionManager,
const Object *,
const Coord3D *,
CommandSourceType,
const SpecialPowerTemplate *,
const Object *,
unsigned int,
bool>(PICK_ADDRESS(0x004972F0, 0x008E1907), this, obj, loc, source, sp_template, object_in_way, i, b);
#else
return false;
#endif
}

bool ActionManager::Can_Do_Special_Power_At_Object(const Object *obj,
const Object *target,
CommandSourceType source,
const SpecialPowerTemplate *sp_template,
unsigned int i,
bool b)
{
#ifdef GAME_DLL
return Call_Method<bool,
ActionManager,
const Object *,
const Object *,
CommandSourceType,
const SpecialPowerTemplate *,
unsigned int,
bool>(PICK_ADDRESS(0x00497530, 0x008E1AEB), this, obj, target, source, sp_template, i, b);
#else
return false;
#endif
}
17 changes: 17 additions & 0 deletions src/game/common/rts/actionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "subsysteminterface.h"

class Object;
class SpecialPowerTemplate;
class Coord3D;

enum CanEnterType
{
Expand All @@ -34,6 +36,21 @@ class ActionManager : public SubsystemInterface
virtual void Update() override {}

bool Can_Enter_Object(const Object *obj, const Object *object_to_enter, CommandSourceType source, CanEnterType type);
bool Can_Do_Special_Power(
const Object *obj, const SpecialPowerTemplate *sp_template, CommandSourceType source, unsigned int i, bool b);
bool Can_Do_Special_Power_At_Location(const Object *obj,
const Coord3D *loc,
CommandSourceType source,
const SpecialPowerTemplate *sp_template,
const Object *object_in_way,
unsigned int i,
bool b);
bool Can_Do_Special_Power_At_Object(const Object *obj,
const Object *target,
CommandSourceType source,
const SpecialPowerTemplate *sp_template,
unsigned int i,
bool b);
};

#ifdef GAME_DLL
Expand Down
11 changes: 11 additions & 0 deletions src/game/common/rts/specialpower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ const SpecialPowerTemplate *SpecialPowerTemplate::Get_FO() const
{
return static_cast<const SpecialPowerTemplate *>(Friend_Get_Final_Override());
}

const SpecialPowerTemplate *SpecialPowerStore::Find_Special_Power_Template_By_ID(unsigned int id)
{
for (size_t i = 0; i < m_specialPowerTemplates.size(); i++) {
if (m_specialPowerTemplates[i]->Get_ID() == id) {
return m_specialPowerTemplates[i];
}
}

return nullptr;
}
1 change: 1 addition & 0 deletions src/game/common/rts/specialpower.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SpecialPowerStore : public SubsystemInterface
virtual void Update() override {}

bool Can_Use_Special_Power(Object *obj, const SpecialPowerTemplate *special_power_template);
const SpecialPowerTemplate *Find_Special_Power_Template_By_ID(unsigned int id);

private:
std::vector<SpecialPowerTemplate *> m_specialPowerTemplates;
Expand Down
19 changes: 19 additions & 0 deletions src/game/common/system/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* LICENSE
*/
#include "upgrade.h"
#include "ingameui.h"
#include "player.h"

#ifndef GAME_DLL
UpgradeCenter *g_theUpgradeCenter;
Expand Down Expand Up @@ -83,3 +85,20 @@ void Upgrade::Xfer_Snapshot(Xfer *xfer)
xfer->xferVersion(&version, 1);
xfer->xferUser(&m_status, sizeof(m_status));
}

bool UpgradeCenter::Can_Afford_Upgrade(Player *player, const UpgradeTemplate *upgrade, bool show_message)
{
if (player == nullptr || upgrade == nullptr) {
return false;
}

if (player->Get_Money()->Count_Money() >= upgrade->Calc_Cost_To_Build(player)) {
return true;
}

if (show_message) {
g_theInGameUI->Message("GUI:NotEnoughMoneyToUpgrade");
}

return false;
}
3 changes: 3 additions & 0 deletions src/game/common/system/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class UpgradeTemplate : public MemoryPoolObject
UpgradeType Get_Type() const { return m_type; }
AcademyClassificationType Get_Academy_Classify() const { return m_academyClassify; }

int Calc_Cost_To_Build(Player *player) const { return m_cost; }

private:
UpgradeType m_type;
Utf8String m_name;
Expand Down Expand Up @@ -81,6 +83,7 @@ class UpgradeCenter : public SubsystemInterface
UpgradeTemplate *Get_Upgrade_List() { return m_upgradeList; }
UpgradeTemplate *Find_Upgrade(const Utf8String &name);
UpgradeTemplate *Find_Upgrade_By_Key(NameKeyType key);
bool Can_Afford_Upgrade(Player *player, const UpgradeTemplate *upgrade, bool show_message);

private:
UpgradeTemplate *m_upgradeList;
Expand Down
25 changes: 1 addition & 24 deletions src/game/logic/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author Jonathan Wilson
*
* @brief
* @brief AI
*
* @copyright Thyme is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -110,29 +110,6 @@ void TAiData::Xfer_Snapshot(Xfer *xfer)
xfer->xferVersion(&version, 1);
}

void AIGroup::Add(Object *obj)
{
#ifdef GAME_DLL
Call_Method<void, AIGroup, Object *>(PICK_ADDRESS(0x0054FB60, 0x008D27B0), this, obj);
#endif
}

void AIGroup::Remove(Object *obj)
{
#ifdef GAME_DLL
Call_Method<void, AIGroup, Object *>(PICK_ADDRESS(0x0054FBF0, 0x008D287E), this, obj);
#endif
}

const std::vector<ObjectID> &AIGroup::Get_All_IDs() const
{
#ifdef GAME_DLL
return Call_Method<const std::vector<ObjectID> &, const AIGroup>(PICK_ADDRESS(0x0054FAC0, 0x008D26A1), this);
#else
return std::vector<ObjectID>();
#endif
}

AI::AI() : m_formationID(0), m_groupID(0)
{
m_aiData = new TAiData();
Expand Down
24 changes: 5 additions & 19 deletions src/game/logic/ai/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author Jonathan Wilson
*
* @brief
* @brief AI
*
* @copyright Thyme is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -13,8 +13,12 @@
* LICENSE
*/
#pragma once
#include "always.h"
#include "aigroup.h"
#include "aiupdate.h"
#include "gametype.h"
#include "mempoolobj.h"
#include "object.h"
#include "snapshot.h"
#include "subsysteminterface.h"
#include <list>
Expand All @@ -26,24 +30,6 @@ class Object;
class PartitionFilter;
class Pathfinder;

class AIGroup
{
public:
void Add(Object *obj);
void Remove(Object *obj);
const std::vector<ObjectID> &Get_All_IDs() const;
};

enum FormationID : int32_t
{
FORMATION_UNK,
};

enum GroupID : int32_t
{
GROUP_UNK,
};

class SkillSet
{
private:
Expand Down
38 changes: 38 additions & 0 deletions src/game/logic/ai/aigroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file
*
* @author Jonathan Wilson
*
* @brief AI Group
*
* @copyright Thyme is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 2 of the License, or (at your option) any later version.
* A full copy of the GNU General Public License can be found in
* LICENSE
*/
#include "aigroup.h"

void AIGroup::Add(Object *obj)
{
#ifdef GAME_DLL
Call_Method<void, AIGroup, Object *>(PICK_ADDRESS(0x0054FB60, 0x008D27B0), this, obj);
#endif
}

void AIGroup::Remove(Object *obj)
{
#ifdef GAME_DLL
Call_Method<void, AIGroup, Object *>(PICK_ADDRESS(0x0054FBF0, 0x008D287E), this, obj);
#endif
}

const std::vector<ObjectID> &AIGroup::Get_All_IDs() const
{
#ifdef GAME_DLL
return Call_Method<const std::vector<ObjectID> &, const AIGroup>(PICK_ADDRESS(0x0054FAC0, 0x008D26A1), this);
#else
return std::vector<ObjectID>();
#endif
}
Loading

0 comments on commit e2c0ddc

Please sign in to comment.