Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Implements and hooks remaining functions for AircraftTypeClass, TechnoTypeClass, VesselTypeClass and InfantryTypeClass. #256

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/game/engine/aircrafttype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,14 @@ void AircraftTypeClass::Dimensions(int &w, int &h) const
*/
BOOL AircraftTypeClass::Create_And_Place(cell_t cellnum, HousesType house) const
{
#if 0
// TODO: This function returns false, this could be why you can't pre place aircraft on a map correctly...
/*
AircraftClass *aptr = new AircraftClass(m_Type, house);
captainslog_assert(aptr != nullptr);
if (aptr != nullptr) {
return aptr->Unlimbo(Cell_To_Coord(cellnum));
}
*/

return false;
#endif
// TODO: This function returns false, this could be why you can't pre place aircraft on a map correctly...
return false;
}

Expand All @@ -142,17 +140,9 @@ BOOL AircraftTypeClass::Create_And_Place(cell_t cellnum, HousesType house) const
*/
ObjectClass *AircraftTypeClass::Create_One_Of(HouseClass *house) const
{
//TODO: Requires AircaftClass to be implemented
#ifdef GAME_DLL
ObjectClass *(*func)(const AircraftTypeClass *, HouseClass *) =
reinterpret_cast<ObjectClass *(*)(const AircraftTypeClass *, HouseClass *)>(0x00404024);
return func(this, house);
#else
/*captainslog_assert(house != nullptr);
return new AircraftClass(Type, house->What_Type());*/
captainslog_assert(house != nullptr);

return nullptr;
#endif
return new AircraftClass(m_Type, house->What_Type());
}

/**
Expand Down Expand Up @@ -274,4 +264,3 @@ void AircraftTypeClass::Prep_For_Add()
}
}
}

2 changes: 1 addition & 1 deletion src/game/engine/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CellClass
BOOL Reduce_Wall(int damage);
BOOL Is_Clear_To_Move(SpeedType speed, BOOL ignore_crushable = false, BOOL ignore_destructable = false, int zone = ZONE_NONE, MZoneType mzone = MZONE_NORMAL) const;
int Ore_Adjust(BOOL randomize);
coord_t Closest_Free_Spot(coord_t coord, BOOL skip_occupied) const;
coord_t Closest_Free_Spot(coord_t coord, BOOL skip_occupied = false) const;
BOOL Is_Spot_Free(int spotindex) const { return ((1 << spotindex) & m_OccupantBit) == 0; }
BOOL Goodie_Check(FootClass *foot);
BOOL Should_Save() const;
Expand Down
14 changes: 14 additions & 0 deletions src/game/engine/coord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ void Move_Point(int16_t &x, int16_t &y, DirType dir, uint16_t distance)
y -= (_sintable[dir] * distance) / 128;
}

/**
*
*
* 0x004AC870
*/
void Normal_Move_Point(int16_t &x, int16_t &y, DirType dir, uint16_t distance)
{
#ifdef GAME_DLL
void (*func)(int16_t, int16_t, DirType, uint16_t) =
reinterpret_cast<void (*)(int16_t, int16_t, DirType, uint16_t)>(0x004AC870);
return func(x, y, dir, distance);
#endif
}

/**
* Calculates a moved Coord relative to the source coord.
*
Expand Down
1 change: 1 addition & 0 deletions src/game/engine/coord.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ inline int Target_Distance(target_t target1, target_t target2)
int Cell_Distance(cell_t cell1, cell_t cell2);

void Move_Point(int16_t &x, int16_t &y, DirType dir, uint16_t distance);
void Normal_Move_Point(int16_t &x, int16_t &y, DirType dir, uint16_t distance);
coord_t Coord_Move(coord_t coord, DirType dir, uint16_t distance);
coord_t Coord_Scatter(coord_t coord, uint16_t distance, BOOL center = false);
BOOL __cdecl Confine_Rect(int &x_pos, int &y_pos, int x, int y, int w, int h);
Expand Down
2 changes: 1 addition & 1 deletion src/game/engine/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DisplayClass : public MapClass
cell_t Calculated_Cell(
SourceType source, int waypoint, cell_t cellnum, SpeedType speed, BOOL use_zone, MZoneType mzone) const;
BOOL Good_Reinforcement_Cell(cell_t cell1, cell_t cell2, SpeedType speed, int zone, MZoneType mzone) const;
coord_t Closest_Free_Spot(coord_t coord, BOOL skip_occupied) const;
coord_t Closest_Free_Spot(coord_t coord, BOOL skip_occupied = false) const;
void All_To_Look(BOOL skip_buildings);
void Constrained_Look(coord_t coord, int constraint);
void Encroach_Shadow();
Expand Down
73 changes: 30 additions & 43 deletions src/game/engine/infantrytype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* LICENSE
*/
#include "infantrytype.h"
#include "infantrydata.h"
#include "gameini.h"
#include "gamefile.h"
#include "facing.h"
#include "gamefile.h"
#include "gameini.h"
#include "globals.h"
#include "infantry.h"
#include "infantrydata.h"
#include "iomap.h"
#include "lists.h"
#include "rules.h"
#include "iomap.h"

#ifndef GAME_DLL
TFixedIHeapClass<InfantryTypeClass> g_InfantryTypes;
Expand Down Expand Up @@ -60,7 +61,7 @@ InfantryTypeClass::InfantryTypeClass(InfantryType type, int uiname, const char *
/**
* 0x004EB2F0
*/
InfantryTypeClass::InfantryTypeClass(InfantryTypeClass const &that) :
InfantryTypeClass::InfantryTypeClass(const InfantryTypeClass &that) :
TechnoTypeClass(that),
m_FemaleVoice(that.m_FemaleVoice),
m_IsCrawler(that.m_IsCrawler),
Expand Down Expand Up @@ -130,23 +131,16 @@ void InfantryTypeClass::Dimensions(int &w, int &h) const
*/
BOOL InfantryTypeClass::Create_And_Place(cell_t cellnum, HousesType house) const
{
#ifdef GAME_DLL
BOOL (*func)
(const InfantryTypeClass *, cell_t, HousesType) =
reinterpret_cast<BOOL (*)(const InfantryTypeClass *, cell_t, HousesType)>(0x004EAF74);
return func(this, cellnum, house);
#else
/*InfantryClass *iptr = new InfantryClass(Type, house);
InfantryClass *iptr = new InfantryClass(m_Type, house);

if (iptr != nullptr) {
coord_t spot = Map[cellnum].Closest_Free_Spot(Cell_To_Coord(cellnum));
if (spot != 0) {
return iptr->Unlimbo(spot, DIR_EAST);
coord_t coord = g_Map[cellnum].Closest_Free_Spot(Cell_To_Coord(cellnum));
if (coord != 0) {
return iptr->Unlimbo(coord, DIR_EAST);
}
}*/
}

return false;
#endif
}

/**
Expand All @@ -156,16 +150,9 @@ BOOL InfantryTypeClass::Create_And_Place(cell_t cellnum, HousesType house) const
*/
ObjectClass *InfantryTypeClass::Create_One_Of(HouseClass *house) const
{
#ifdef GAME_DLL
ObjectClass *(*func)(const InfantryTypeClass *, HouseClass *) =
reinterpret_cast<ObjectClass *(*)(const InfantryTypeClass *, HouseClass *)>(0x004EAF20);
return func(this, house);
#else
/*captainslog_assert(house != nullptr);
return new InfantryClass(Type, house->What_Type());*/

return nullptr;
#endif
captainslog_assert(house != nullptr);

return new InfantryClass(m_Type, house->What_Type());
}

/**
Expand All @@ -188,26 +175,26 @@ const int16_t *InfantryTypeClass::Occupy_List(BOOL a1) const
*/
BOOL InfantryTypeClass::Read_INI(GameINIClass &ini)
{
if (TechnoTypeClass::Read_INI(ini)) {
m_IsFraidycat = ini.Get_Bool(m_Name, "Fraidycat", m_IsFraidycat);
m_IsInfiltrator = ini.Get_Bool(m_Name, "Infiltrate", m_IsInfiltrator);
m_HasC4 = ini.Get_Bool(m_Name, "C4", m_HasC4);
m_IsCanine = ini.Get_Bool(m_Name, "IsCanine", m_IsCanine);

// C4 presumes infiltrate.
if (m_HasC4) {
m_IsInfiltrator = true;
}
if (!TechnoTypeClass::Read_INI(ini)) {
return false;
}

// Dogs can't be leaders.
if (m_IsCanine) {
m_IsLeader = false;
}
m_IsFraidycat = ini.Get_Bool(m_Name, "Fraidycat", m_IsFraidycat);
m_IsInfiltrator = ini.Get_Bool(m_Name, "Infiltrate", m_IsInfiltrator);
m_HasC4 = ini.Get_Bool(m_Name, "C4", m_HasC4);
m_IsCanine = ini.Get_Bool(m_Name, "IsCanine", m_IsCanine);

return true;
// C4 presumes infiltrate.
if (m_HasC4) {
m_IsInfiltrator = true;
}

return false;
// Dogs can't be leaders.
if (m_IsCanine) {
m_IsLeader = false;
}

return true;
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/game/engine/infantrytype.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,39 @@ class InfantryTypeClass : public TechnoTypeClass
static void One_Time();
static void Prep_For_Add();

#ifdef GAME_DLL
public:
friend void Setup_Hooks();

InfantryTypeClass *Hooked_Ctor(InfantryType type, int uiname, const char *name, int def_fire_coord, int rot_count, BOOL female,
BOOL crawls, BOOL civilian, BOOL has_alt_remap, BOOL nominal, BOOL theater, PipEnum pip, const DoInfoStruct *do_info,
int fire_up, int fire_prone, const uint8_t *alt_remap)
{
return new (this) InfantryTypeClass(type,
uiname,
name,
def_fire_coord,
rot_count,
female,
crawls,
civilian,
has_alt_remap,
nominal,
theater,
pip,
do_info,
fire_up,
fire_prone,
alt_remap);
}
int InfantryTypeClass::Hooked_Full_Name() const { return InfantryTypeClass::Full_Name(); }
void InfantryTypeClass::Hooked_Dimensions(int &w, int &h) const { InfantryTypeClass::Dimensions(w, h); }
BOOL InfantryTypeClass::Hooked_Create_And_Place(cell_t cellnum, HousesType house) { return InfantryTypeClass::Create_And_Place(cellnum, house); }
ObjectClass *InfantryTypeClass::Hooked_Create_One_Of(HouseClass *house) { return InfantryTypeClass::Create_One_Of(house); }
const int16_t *InfantryTypeClass::Hooked_Occupy_List(BOOL a1) { return InfantryTypeClass::Occupy_List(a1); }
BOOL Hooked_Read_INI(GameINIClass &ini) { return InfantryTypeClass::Read_INI(ini); }
#endif

private:
#ifndef CHRONOSHIFT_NO_BITFIELDS
BOOL m_FemaleVoice : 1; // & 1 Uses the civilian female voice (def = false)?
Expand Down
Loading