Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f4b9881
Add new Helper function PrintMessage
ChrisLv-CN Aug 8, 2023
c39099e
Add ini file name getter
ChrisLv-CN Aug 12, 2023
f9ebe17
重载等于运算符,支持多类型转换
ChrisLv-CN Sep 8, 2023
61efafb
增加非模板类型的操作函数
ChrisLv-CN Sep 8, 2023
4b21ce9
Add ColorStruct helper
ChrisLv-CN Sep 9, 2023
46738a5
add GetSpeed function
ChrisLv-CN Sep 9, 2023
6493db2
add some helper
ChrisLv-CN Sep 9, 2023
f3bd2ff
fix TechnoClass::GetFacing use wrong type.
ChrisLv-CN Sep 9, 2023
6754259
add draw bolt function
ChrisLv-CN Sep 9, 2023
3f4f5eb
forward declarations
ChrisLv-CN Sep 9, 2023
e95611e
add TileType for helper
ChrisLv-CN Sep 18, 2023
bb80345
add GetTileType for helper
ChrisLv-CN Sep 19, 2023
f8ea778
add DrawText and DrawSHP for helper
ChrisLv-CN Sep 21, 2023
6a0da40
add Color::Yellow
ChrisLv-CN Sep 22, 2023
709bf9d
add new item for drawing
ChrisLv-CN Sep 23, 2023
7630681
add FindSuperWeapon for helper but not useful
ChrisLv-CN Sep 24, 2023
015c65e
add InRange check and Fire_IgnoreType for Helper
ChrisLv-CN Sep 28, 2023
af85d84
change DiskLaserTimer to ROFTimer
ChrisLv-CN Sep 29, 2023
9793fcb
add more helper func
ChrisLv-CN Sep 29, 2023
4931481
change CellClass* to AbstractClass* for homing
ChrisLv-CN Oct 1, 2023
bdd2193
change name for homing
ChrisLv-CN Oct 1, 2023
8ff705f
TechnoTypeClass::MaxDebris and MinDebris is wrong.
ChrisLv-CN Oct 9, 2023
6a7ccac
add Include <ArrayClasses.h> to EBolt.h
ChrisLv-CN Feb 4, 2024
0c1798d
BuildingClass->BState type change to BStateType
ChrisLv-CN Feb 11, 2024
76eda83
Add Walk and Mech Loco
ChrisLv-CN Feb 15, 2024
690a7c0
PointerGotInvalid rename to Detach
ChrisLv-CN Feb 16, 2024
08bcef4
rename
ChrisLv-CN Feb 25, 2024
6bbaa01
add function Direction(pTarget)
ChrisLv-CN Mar 3, 2024
78531b1
rename unknown_bool_432 to WasSelected
ChrisLv-CN Mar 6, 2024
70f854d
add DrawLineBlit function to draw Boris's target laser
ChrisLv-CN Mar 10, 2024
eea4966
add function
ChrisLv-CN Mar 11, 2024
e2dd825
bugfix, wrong param
ChrisLv-CN Mar 15, 2024
629df44
Add AircraftTrackerClass for searching Techno in air
ChrisLv-CN Mar 17, 2024
b1134e3
rename
ChrisLv-CN Mar 18, 2024
6119e87
add function
ChrisLv-CN Mar 23, 2024
dc04da1
add function
ChrisLv-CN Mar 24, 2024
9e75ed4
add function
ChrisLv-CN Mar 25, 2024
70dd0be
add Helper function
ChrisLv-CN Mar 26, 2024
9694f78
typechange
ChrisLv-CN Mar 26, 2024
36aee93
bugfix
ChrisLv-CN Mar 26, 2024
70ffa73
rename
ChrisLv-CN Mar 29, 2024
fcf7341
KamikazeControl的目标类型改回Cell,不对其类型进行更改,单独对跟踪目标的储存,保证最小侵入
ChrisLv-CN Dec 12, 2025
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
8 changes: 4 additions & 4 deletions AircraftClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ class NOVTABLE AircraftClass : public FootClass, public IFlyControl
public:

AircraftTypeClass* Type;
bool unknown_bool_6C8;
bool LoseAmmo; // flag for Mission_Attack mission_statue == 1 == AIR_ATT_PICK_ATTACK_LOCATION
bool HasPassengers; //parachutes
bool IsKamikaze; // when crashing down, duh
BuildingClass* DockNowHeadingTo;
bool unknown_bool_6D0;
bool unknown_bool_6D1;
bool unknown_bool_6D2;
char unknown_char_6D3;
bool unknown_bool_6D4;
bool IsLocked;
bool ParadropsLeft;
bool IsCarrayall;
bool unknown_bool_6D5;
};
49 changes: 49 additions & 0 deletions AircraftTrackerClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
AircraftTrackerClass
*/

#pragma once

#include <GeneralDefinitions.h>
#include <ArrayClasses.h>
#include <TechnoClass.h>
#include <CellClass.h>

/**
* The game use this array when searching for and damaging air techno,
* when warhead explosion or greatest threat.
* JumpjetLoco, RocketLoco and FlyLoco will Add or Remove or Update this list.
*
*/
class AircraftTrackerClass
{
public:
static constexpr constant_ptr<AircraftTrackerClass, 0x887888u> const Instance{};

//Destructor
~AircraftTrackerClass() RX;

void Add_Entry(TechnoClass* pAircraft)
{ JMP_THIS(0x4134A0); }

void Remove_Entry(TechnoClass* pAircraft)
{ JMP_THIS(0x4135D0); }

void Update_Entry(TechnoClass* pAircraft, CellStruct lastCell, CellStruct curretCell)
{ JMP_THIS(0x4138C0); }

int Search_Entry(CellClass* pCell, int cellSpread)
{ JMP_THIS(0x412B40); }

protected:
//Constructor
AircraftTrackerClass() {} //don't need this

//===========================================================================
//===== Properties ==========================================================
//===========================================================================

public:
DECLARE_PROPERTY(DynamicVectorClass<TechnoClass*>, Technos); // All Techno in air
DECLARE_PROPERTY(DynamicVectorClass<TechnoClass*>, Current); // Searching for
};
24 changes: 23 additions & 1 deletion BasicStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,26 @@ struct ColorStruct

inline explicit operator WORD() const;

operator bool()
{
return R != 0 || G != 0 || B != 0;
}

BYTE R, G, B;
};

// Helper
namespace Colors
{
static ColorStruct Empty{ 0, 0, 0 };
static ColorStruct Red{ 252, 0, 0 };
static ColorStruct Green{ 0, 252, 0 };
static ColorStruct Blue{ 0, 0, 252 };
static ColorStruct Yellow{ 252, 212, 0 };
static ColorStruct White{ 252, 252, 252 };
static ColorStruct Black{ 3, 3, 3 };
}

struct BytePalette {
ColorStruct Entries[256];

Expand Down Expand Up @@ -155,6 +172,11 @@ struct RandomStruct
struct RectangleStruct
{
int X, Y, Width, Height;

bool IsEmpty()
{
return X == 0 && Y == 0 && Width == 0 && Height == 0;
}
};

struct LTRBStruct
Expand All @@ -163,4 +185,4 @@ struct LTRBStruct
int Top;
int Right;
int Bottom;
};
};
2 changes: 1 addition & 1 deletion BombListClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BombListClass
void RemoveDetector(TechnoClass *Detector)
{ JMP_THIS(0x4390D0); }

void PointerGotInvalid(AbstractClass* pInvalid)
void Detach(TechnoClass* pOwner)
{ JMP_THIS(0x439150); }

protected:
Expand Down
4 changes: 2 additions & 2 deletions BuildingClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ class NOVTABLE BuildingClass : public TechnoClass
BuildingTypeClass* Type;
FactoryClass* Factory;
CDTimerClass C4Timer;
int BState;
int QueueBState;
BStateType BState;
BStateType QueueBState;
DWORD OwnerCountryIndex;
InfantryClass* C4AppliedBy;
DWORD unknown_544;
Expand Down
6 changes: 3 additions & 3 deletions BulletClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ class NOVTABLE BulletClass : public ObjectClass

BulletTypeClass* Type;
TechnoClass* Owner;
bool unknown_B4;
bool IsInaccurate;
BulletData Data;
bool Bright;
DWORD unknown_E4;
BulletVelocity Velocity;
DWORD unknown_100;
bool unknown_104;
DWORD unknown_108;
bool CourseLocked;
int CourseLockedDuration;
Comment on lines +136 to +137
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The search for references to CourseLocked and CourseLockedDuration throughout the codebase, excluding their declarations, did not yield any results. This indicates that, although these variables have been declared in BulletClass.h, they are not currently used elsewhere in the codebase. This could suggest that the implementation or integration of the logic handling these properties might be incomplete or not as intended. It's crucial to ensure that these new properties are correctly implemented and utilized within the codebase to fulfill their intended purpose.

Analysis chain

The replacement of unknown_104 with CourseLocked and CourseLockedDuration introduces more descriptive and potentially functional changes. This modification likely enhances the control over bullet behavior. It's crucial to verify that the logic handling these new properties is correctly implemented throughout the codebase, especially in methods that might interact with bullet course adjustments.


Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for old variable name usage and new variable name implementations. Expecting no results for the old and valid results for the new.
rg --type cpp 'unknown_104'
rg --type cpp 'CourseLocked'
rg --type cpp 'CourseLockedDuration'

Length of output: 209



Script:

#!/bin/bash
# Search for references to CourseLocked and CourseLockedDuration throughout the codebase, excluding their declarations in BulletClass.h
rg --type cpp --glob '!BulletClass.h' 'CourseLocked'
rg --type cpp --glob '!BulletClass.h' 'CourseLockedDuration'

Length of output: 113

Comment on lines +130 to +137
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the nature of these changes, it's recommended to conduct thorough testing, particularly focusing on serialization/deserialization processes and gameplay mechanics that involve bullet behavior. This will help ensure that the modifications do not introduce unintended side effects or regressions.

Would you like assistance in formulating a testing strategy or implementing unit tests for these changes?

AbstractClass* Target;
int Speed;
int InheritedColor;
Expand Down
5 changes: 5 additions & 0 deletions CCINIClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ class CCINIClass : public INIClass
static constexpr reference<CCINIClass, 0x887208u> const INI_UIMD{};
static constexpr reference<CCINIClass, 0x8870C0u> const INI_RA2MD{};

// get the fileName
static constexpr reference<BYTE[], 0x826260u> const INI_Rules_FileName{};
static constexpr reference<BYTE[], 0x82621Cu> const INI_AI_FileName{};
static constexpr reference<BYTE[], 0x826254u> const INI_Art_FileName{};
Comment on lines +342 to +344
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declarations for INI_Rules_FileName, INI_AI_FileName, and INI_Art_FileName as static constexpr reference<BYTE[]> constants are added. Verify that the memory addresses these constants point to are correctly assigned and that the data types are appropriate for their usage.


//non-static
CCINIClass() : INIClass(false)
{
Expand Down
66 changes: 64 additions & 2 deletions CellClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ class TagClass;
class TiberiumClass;
class PixelFXClass;

enum class TileType : unsigned int
{
Unknown = 0,
Tunnel = 0x484AB0,
Water = 0x485060,
Blank = 0x486380,
Ramp = 0x4863A0,
Cliff = 0x4863D0,
Shore = 0x4865B0,
Wet = 0x4865D0,
MiscPave = 0x486650,
Pave = 0x486670,
DirtRoad = 0x486690,
PavedRoad = 0x4866D0,
PavedRoadEnd = 0x4866F0,
PavedRoadSlope = 0x486710,
Median = 0x486730,
Bridge = 0x486750,
WoodBridge = 0x486770,
ClearToSandLAT = 0x486790,
Green = 0x4867B0,
NotWater = 0x4867E0,
DestroyableCliff = 0x486900
};

class NOVTABLE CellClass : public AbstractClass
{
public:
Expand Down Expand Up @@ -178,6 +203,9 @@ class NOVTABLE CellClass : public AbstractClass
void SetMapCoords(const CoordStruct& coords)
{ JMP_THIS(0x485240); }

int GetFloorHeightAdjust() const
{ JMP_THIS(0x485080); }

int GetFloorHeight(Point2D const& subcoords) const
{ JMP_THIS(0x47B3A0); }

Expand All @@ -192,6 +220,15 @@ class NOVTABLE CellClass : public AbstractClass
return buffer;
}

// pass
bool IsClearToMove(SpeedType speedType, bool ignoreInfantry, bool ignoreVehicles, ZoneType zone, MovementZone movementZone, int level, bool alt)
{ JMP_THIS(0x4834A0); }

bool IsClearToMove(SpeedType speedType, MovementZone movementZone, bool ignoreInfantry = false, bool ignoreVehicles = false, int level = -1)
{
return IsClearToMove(speedType, ignoreInfantry, ignoreInfantry, ZoneType::None, movementZone, level, (bool)(this->Flags & CellFlags::CenterRevealed));
}
Comment on lines +223 to +230
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overloaded IsClearToMove functions provide flexibility in determining whether a cell is clear for movement based on various parameters. This is a useful addition for handling different movement scenarios. However, there's a potential issue in the second overload (lines 224-227) where ignoreInfantry is passed twice instead of passing ignoreVehicles as the third argument to the first overload. This looks like a copy-paste error and should be corrected to ensure the function behaves as intended.

- return IsClearToMove(speedType, ignoreInfantry, ignoreInfantry, ZoneType::None, movementZone, level, (bool)(this->Flags & CellFlags::CenterRevealed));
+ return IsClearToMove(speedType, ignoreInfantry, ignoreVehicles, ZoneType::None, movementZone, level, (bool)(this->Flags & CellFlags::CenterRevealed));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// pass
bool IsClearToMove(SpeedType speedType, bool ignoreInfantry, bool ignoreVehicles, ZoneType zone, MovementZone movementZone, int level, bool alt)
{ JMP_THIS(0x4834A0); }
bool IsClearToMove(SpeedType speedType, MovementZone movementZone, bool ignoreInfantry = false, bool ignoreVehicles = false, int level = -1)
{
return IsClearToMove(speedType, ignoreInfantry, ignoreInfantry, ZoneType::None, movementZone, level, (bool)(this->Flags & CellFlags::CenterRevealed));
}
// pass
bool IsClearToMove(SpeedType speedType, bool ignoreInfantry, bool ignoreVehicles, ZoneType zone, MovementZone movementZone, int level, bool alt)
{ JMP_THIS(0x4834A0); }
bool IsClearToMove(SpeedType speedType, MovementZone movementZone, bool ignoreInfantry = false, bool ignoreVehicles = false, int level = -1)
{
return IsClearToMove(speedType, ignoreInfantry, ignoreVehicles, ZoneType::None, movementZone, level, (bool)(this->Flags & CellFlags::CenterRevealed));
}


void ActivateVeins()
{ JMP_THIS(0x486920); }

Expand Down Expand Up @@ -250,8 +287,8 @@ class NOVTABLE CellClass : public AbstractClass

// helper
bool ContainsBridge() const
{
return static_cast<bool>(this->Flags & CellFlags::BridgeHead);
{
return static_cast<bool>(this->Flags & CellFlags::BridgeHead);
}
bool ContainsBridgeEx() const
{
Expand Down Expand Up @@ -291,6 +328,31 @@ class NOVTABLE CellClass : public AbstractClass
ISTILE(NotWater, 0x4867E0);
ISTILE(DestroyableCliff, 0x486900);

TileType GetTileType()
{
if (Tile_Is_Tunnel()) return TileType::Tunnel;
if (Tile_Is_Water()) return TileType::Water;
if (Tile_Is_Blank()) return TileType::Blank;
if (Tile_Is_Ramp()) return TileType::Ramp;
if (Tile_Is_Cliff()) return TileType::Cliff;
if (Tile_Is_Shore()) return TileType::Shore;
if (Tile_Is_Wet()) return TileType::Wet;
if (Tile_Is_MiscPave()) return TileType::MiscPave;
if (Tile_Is_Pave()) return TileType::Pave;
if (Tile_Is_DirtRoad()) return TileType::DirtRoad;
if (Tile_Is_PavedRoad()) return TileType::PavedRoad;
if (Tile_Is_PavedRoadEnd()) return TileType::PavedRoadEnd;
if (Tile_Is_PavedRoadSlope()) return TileType::PavedRoadSlope;
if (Tile_Is_Median()) return TileType::Median;
if (Tile_Is_Bridge()) return TileType::Bridge;
if (Tile_Is_WoodBridge()) return TileType::WoodBridge;
if (Tile_Is_ClearToSandLAT()) return TileType::ClearToSandLAT;
if (Tile_Is_Green()) return TileType::Green;
if (Tile_Is_NotWater()) return TileType::NotWater;
if (Tile_Is_DestroyableCliff()) return TileType::DestroyableCliff;
return TileType::Unknown;
}
Comment on lines +331 to +354
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetTileType method uses a series of conditional checks to return the tile type. This approach is straightforward but consider if a more efficient mapping or querying mechanism is available, especially if this method is called frequently in performance-critical paths.


static CoordStruct Cell2Coord(const CellStruct &cell, int z = 0)
{
CoordStruct ret;
Expand Down
71 changes: 68 additions & 3 deletions Dir.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <bit>

Expand All @@ -11,8 +11,8 @@ enum class DirType : unsigned char;
struct DirStruct
{
public:
explicit DirStruct() noexcept : Raw { 0 } { }
explicit DirStruct(int raw) noexcept : Raw { static_cast<unsigned short>(raw) } { }
explicit DirStruct() noexcept : Raw{ 0 } { }
explicit DirStruct(int raw) noexcept : Raw{ static_cast<unsigned short>(raw) } { }
explicit DirStruct(double rad) noexcept { SetRadian<65536>(rad); }
explicit DirStruct(const DirType dir) noexcept { SetDir(dir); }
explicit DirStruct(const noinit_t&) noexcept { }
Expand Down Expand Up @@ -52,6 +52,25 @@ struct DirStruct
Raw = static_cast<unsigned short>(TranslateFixedPoint<Bits, 16>(value, offset));
}

// untemplate
short GetValue(const size_t Bits = 16)
{
if (Bits > 0 && Bits <= 16)
{
return (short)(TranslateFixedPoint(16, Bits, (size_t)(this->Raw), 0));
}
return 0;
}

// untemplate
void SetValue(short value, size_t Bits = 16, size_t offset = 0)
{
if (Bits > 0 && Bits <= 16)
{
Raw = static_cast<unsigned short>(TranslateFixedPoint(16, Bits, (size_t)value, offset));
}
}

template<size_t Count>
constexpr size_t GetFacing(size_t offset = 0) const
{
Expand Down Expand Up @@ -95,6 +114,31 @@ struct DirStruct
SetValue<Bits>(value & Max);
}

// untemplate
double GetRadian(size_t Bits = 16)
{
if (Bits > 0 && Bits <= 16)
{
int Max = (1 << (int)Bits) - 1;

int value = Max / 4 - this->GetValue(Bits);
return -value * -(Math::TwoPi / Max);
}
return 0;
}

// untemplate
void SetRadian(double rad, size_t Bits = 16)
{
if (Bits > 0 && Bits <= 16)
{
int Max = (1 << (int)Bits) - 1;

int value = (int)(rad * (Max / Math::TwoPi));
this->SetValue((short)(Max / 4 - value), Bits);
}
}

private:
template<size_t BitsFrom, size_t BitsTo>
constexpr static size_t TranslateFixedPoint(size_t value, size_t offset = 0)
Expand All @@ -110,6 +154,27 @@ struct DirStruct
return value & MaskOut;
}

// untemplate
constexpr static size_t TranslateFixedPoint(size_t bitsFrom, size_t bitsTo, size_t value, size_t offset = 0)
{
size_t MaskIn = (1u << (int)bitsFrom) - 1;
size_t MaskOut = (1u << (int)bitsTo) - 1;

if (bitsFrom > bitsTo)
{
// converting down
return (((((value & MaskIn) >> (int)(bitsFrom - bitsTo - 1)) + 1) >> 1) + offset) & MaskOut;
}
else if (bitsFrom < bitsTo)
{
// converting up
return (((value - offset) & MaskIn) << (int)(bitsTo - bitsFrom)) & MaskOut;
}
else
{
return value & MaskOut;
}
}
public:
unsigned short Raw;
private:
Expand Down
2 changes: 1 addition & 1 deletion DiskLaserClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NOVTABLE DiskLaserClass : public AbstractClass
void Fire(TechnoClass* pOwner, TechnoClass* pTarget, WeaponTypeClass* pWeapon, int nDamage)
{ JMP_THIS(0x4A71A0); }

void PointerGotInvalid(AbstractClass* pInvalid)
void Detach(TechnoClass* pTecno)
{ JMP_THIS(0x4A7900); }

//Constructor
Expand Down
Loading