Skip to content

Commit e2c0ddc

Browse files
authored
Implement some stuff needed for AIGroup (#909)
1 parent 516471c commit e2c0ddc

25 files changed

+974
-109
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ set(GAMEENGINE_SRC
265265
game/common/thing/thingfactory.cpp
266266
game/common/thing/thingtemplate.cpp
267267
game/logic/ai/ai.cpp
268+
game/logic/ai/aigroup.cpp
268269
game/logic/ai/aipathfind.cpp
269270
game/logic/ai/aiplayer.cpp
270271
game/logic/ai/aistates.cpp
@@ -332,6 +333,7 @@ set(GAMEENGINE_SRC
332333
game/logic/system/cavesystem.cpp
333334
game/logic/system/cratesystem.cpp
334335
game/logic/system/partitionmanager.cpp
336+
game/logic/system/simpleobjectiterator.cpp
335337
game/network/framemetrics.cpp
336338
game/network/gameinfo.cpp
337339
game/network/gameresultsthread.cpp

src/game/client/line2d.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,19 @@ bool Clip_Line_2D(ICoord2D *p1, ICoord2D *p2, ICoord2D *c1, ICoord2D *c2, IRegio
151151
return x0 >= x_min && x0 <= x_max && y0 >= y_min && y0 <= y_max && x1 >= x_min && x1 <= x_max && y1 >= y_min
152152
&& y1 <= y_max;
153153
}
154+
155+
bool Coord_3D_Inside_Rect_2D(const Coord3D *input_point, const Coord2D *tl, const Coord2D *br)
156+
{
157+
return input_point->x >= tl->x && input_point->x <= br->x && input_point->y >= tl->y && input_point->y <= br->y;
158+
}
159+
160+
void Scale_Rect_2D(Coord2D *tl, Coord2D *br, float scale_factor)
161+
{
162+
float delta = scale_factor - 1.0f;
163+
float x = (br->x - tl->x) * delta * 0.5f;
164+
float y = (br->y - tl->y) * delta * 0.5f;
165+
tl->x = tl->x - x;
166+
tl->y = tl->y - y;
167+
br->x = x + br->x;
168+
br->y = y + br->y;
169+
}

src/game/client/line2d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
#include "coord.h"
1818

1919
bool Clip_Line_2D(ICoord2D *p1, ICoord2D *p2, ICoord2D *c1, ICoord2D *c2, IRegion2D *clip_region);
20+
bool Coord_3D_Inside_Rect_2D(const Coord3D *input_point, const Coord2D *tl, const Coord2D *br);
21+
void Scale_Rect_2D(Coord2D *tl, Coord2D *br, float scale_factor);

src/game/common/rts/actionmanager.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
* LICENSE
1414
*/
1515
#include "actionmanager.h"
16+
#include "behaviormodule.h"
17+
#include "object.h"
18+
#include "player.h"
19+
#include "specialpower.h"
20+
#include "terrainlogic.h"
1621
#ifdef GAME_DLL
1722
#include "hooker.h"
1823
#endif
@@ -31,3 +36,63 @@ bool ActionManager::Can_Enter_Object(
3136
return false;
3237
#endif
3338
}
39+
40+
bool ActionManager::Can_Do_Special_Power(
41+
const Object *obj, const SpecialPowerTemplate *sp_template, CommandSourceType source, unsigned int i, bool b)
42+
{
43+
#ifdef GAME_DLL
44+
return Call_Method<bool,
45+
ActionManager,
46+
const Object *,
47+
const SpecialPowerTemplate *,
48+
CommandSourceType,
49+
unsigned int,
50+
bool>(PICK_ADDRESS(0x00497A70, 0x008E202D), this, obj, sp_template, source, i, b);
51+
#else
52+
return false;
53+
#endif
54+
}
55+
56+
bool ActionManager::Can_Do_Special_Power_At_Location(const Object *obj,
57+
const Coord3D *loc,
58+
CommandSourceType source,
59+
const SpecialPowerTemplate *sp_template,
60+
const Object *object_in_way,
61+
unsigned int i,
62+
bool b)
63+
{
64+
#ifdef GAME_DLL
65+
return Call_Method<bool,
66+
ActionManager,
67+
const Object *,
68+
const Coord3D *,
69+
CommandSourceType,
70+
const SpecialPowerTemplate *,
71+
const Object *,
72+
unsigned int,
73+
bool>(PICK_ADDRESS(0x004972F0, 0x008E1907), this, obj, loc, source, sp_template, object_in_way, i, b);
74+
#else
75+
return false;
76+
#endif
77+
}
78+
79+
bool ActionManager::Can_Do_Special_Power_At_Object(const Object *obj,
80+
const Object *target,
81+
CommandSourceType source,
82+
const SpecialPowerTemplate *sp_template,
83+
unsigned int i,
84+
bool b)
85+
{
86+
#ifdef GAME_DLL
87+
return Call_Method<bool,
88+
ActionManager,
89+
const Object *,
90+
const Object *,
91+
CommandSourceType,
92+
const SpecialPowerTemplate *,
93+
unsigned int,
94+
bool>(PICK_ADDRESS(0x00497530, 0x008E1AEB), this, obj, target, source, sp_template, i, b);
95+
#else
96+
return false;
97+
#endif
98+
}

src/game/common/rts/actionmanager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "subsysteminterface.h"
1919

2020
class Object;
21+
class SpecialPowerTemplate;
22+
class Coord3D;
2123

2224
enum CanEnterType
2325
{
@@ -34,6 +36,21 @@ class ActionManager : public SubsystemInterface
3436
virtual void Update() override {}
3537

3638
bool Can_Enter_Object(const Object *obj, const Object *object_to_enter, CommandSourceType source, CanEnterType type);
39+
bool Can_Do_Special_Power(
40+
const Object *obj, const SpecialPowerTemplate *sp_template, CommandSourceType source, unsigned int i, bool b);
41+
bool Can_Do_Special_Power_At_Location(const Object *obj,
42+
const Coord3D *loc,
43+
CommandSourceType source,
44+
const SpecialPowerTemplate *sp_template,
45+
const Object *object_in_way,
46+
unsigned int i,
47+
bool b);
48+
bool Can_Do_Special_Power_At_Object(const Object *obj,
49+
const Object *target,
50+
CommandSourceType source,
51+
const SpecialPowerTemplate *sp_template,
52+
unsigned int i,
53+
bool b);
3754
};
3855

3956
#ifdef GAME_DLL

src/game/common/rts/specialpower.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,14 @@ const SpecialPowerTemplate *SpecialPowerTemplate::Get_FO() const
6666
{
6767
return static_cast<const SpecialPowerTemplate *>(Friend_Get_Final_Override());
6868
}
69+
70+
const SpecialPowerTemplate *SpecialPowerStore::Find_Special_Power_Template_By_ID(unsigned int id)
71+
{
72+
for (size_t i = 0; i < m_specialPowerTemplates.size(); i++) {
73+
if (m_specialPowerTemplates[i]->Get_ID() == id) {
74+
return m_specialPowerTemplates[i];
75+
}
76+
}
77+
78+
return nullptr;
79+
}

src/game/common/rts/specialpower.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SpecialPowerStore : public SubsystemInterface
6464
virtual void Update() override {}
6565

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

6869
private:
6970
std::vector<SpecialPowerTemplate *> m_specialPowerTemplates;

src/game/common/system/upgrade.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* LICENSE
1414
*/
1515
#include "upgrade.h"
16+
#include "ingameui.h"
17+
#include "player.h"
1618

1719
#ifndef GAME_DLL
1820
UpgradeCenter *g_theUpgradeCenter;
@@ -83,3 +85,20 @@ void Upgrade::Xfer_Snapshot(Xfer *xfer)
8385
xfer->xferVersion(&version, 1);
8486
xfer->xferUser(&m_status, sizeof(m_status));
8587
}
88+
89+
bool UpgradeCenter::Can_Afford_Upgrade(Player *player, const UpgradeTemplate *upgrade, bool show_message)
90+
{
91+
if (player == nullptr || upgrade == nullptr) {
92+
return false;
93+
}
94+
95+
if (player->Get_Money()->Count_Money() >= upgrade->Calc_Cost_To_Build(player)) {
96+
return true;
97+
}
98+
99+
if (show_message) {
100+
g_theInGameUI->Message("GUI:NotEnoughMoneyToUpgrade");
101+
}
102+
103+
return false;
104+
}

src/game/common/system/upgrade.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class UpgradeTemplate : public MemoryPoolObject
5050
UpgradeType Get_Type() const { return m_type; }
5151
AcademyClassificationType Get_Academy_Classify() const { return m_academyClassify; }
5252

53+
int Calc_Cost_To_Build(Player *player) const { return m_cost; }
54+
5355
private:
5456
UpgradeType m_type;
5557
Utf8String m_name;
@@ -81,6 +83,7 @@ class UpgradeCenter : public SubsystemInterface
8183
UpgradeTemplate *Get_Upgrade_List() { return m_upgradeList; }
8284
UpgradeTemplate *Find_Upgrade(const Utf8String &name);
8385
UpgradeTemplate *Find_Upgrade_By_Key(NameKeyType key);
86+
bool Can_Afford_Upgrade(Player *player, const UpgradeTemplate *upgrade, bool show_message);
8487

8588
private:
8689
UpgradeTemplate *m_upgradeList;

src/game/logic/ai/ai.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @author Jonathan Wilson
55
*
6-
* @brief
6+
* @brief AI
77
*
88
* @copyright Thyme is free software: you can redistribute it and/or
99
* modify it under the terms of the GNU General Public License
@@ -110,29 +110,6 @@ void TAiData::Xfer_Snapshot(Xfer *xfer)
110110
xfer->xferVersion(&version, 1);
111111
}
112112

113-
void AIGroup::Add(Object *obj)
114-
{
115-
#ifdef GAME_DLL
116-
Call_Method<void, AIGroup, Object *>(PICK_ADDRESS(0x0054FB60, 0x008D27B0), this, obj);
117-
#endif
118-
}
119-
120-
void AIGroup::Remove(Object *obj)
121-
{
122-
#ifdef GAME_DLL
123-
Call_Method<void, AIGroup, Object *>(PICK_ADDRESS(0x0054FBF0, 0x008D287E), this, obj);
124-
#endif
125-
}
126-
127-
const std::vector<ObjectID> &AIGroup::Get_All_IDs() const
128-
{
129-
#ifdef GAME_DLL
130-
return Call_Method<const std::vector<ObjectID> &, const AIGroup>(PICK_ADDRESS(0x0054FAC0, 0x008D26A1), this);
131-
#else
132-
return std::vector<ObjectID>();
133-
#endif
134-
}
135-
136113
AI::AI() : m_formationID(0), m_groupID(0)
137114
{
138115
m_aiData = new TAiData();

0 commit comments

Comments
 (0)