~ares-developers/ares/gd03

« back to all changes in this revision

Viewing changes to src/Ext/House/Hooks.cpp

  • Committer: Renegade
  • Date: 2010-05-29 08:12:17 UTC
  • Revision ID: git-v1:0a1bb6321f04d723afe64d1b843dc87b4da783ec
Creating /trunk/src.

git-svn-id: svn://svn.renegadeprojects.com/ares/trunk@622 859b54a9-7a54-0410-aeb3-f8d2f1fa40fd

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Body.h"
 
2
#include "../TechnoType/Body.h"
 
3
 
 
4
#include <StringTable.h>
 
5
#include <GameModeOptionsClass.h>
 
6
#include <BuildingClass.h>
 
7
#include <AircraftClass.h>
 
8
#include <InfantryClass.h>
 
9
#include <UnitClass.h>
 
10
#include <ArrayClasses.h>
 
11
#include <Helpers/Template.h>
 
12
#include <CRT.h>
 
13
 
 
14
// =============================
 
15
// other hooks
 
16
 
 
17
DEFINE_HOOK(4F7870, HouseClass_PrereqValidator, 7)
 
18
{
 
19
        // int (TechnoTypeClass *item, bool BuildLimitOnly, bool includeQueued)
 
20
        /* return
 
21
                 1 - cameo shown
 
22
                 0 - cameo not shown
 
23
                -1 - cameo greyed out
 
24
         */
 
25
 
 
26
        GET(HouseClass *, pHouse, ECX);
 
27
        GET_STACK(TechnoTypeClass *, pItem, 0x4);
 
28
        GET_STACK(bool, BuildLimitOnly, 0x8);
 
29
        GET_STACK(bool, IncludeQueued, 0xC);
 
30
 
 
31
        R->EAX(HouseExt::PrereqValidate(pHouse, pItem, BuildLimitOnly, IncludeQueued));
 
32
        return 0x4F8361;
 
33
}
 
34
 
 
35
// upgrades as prereqs, facepalm of epic proportions
 
36
// not needed anymore since the whole function's been replaced
 
37
/*
 
38
A_FINE_HOOK(4F7E49, HouseClass_CanBuildHowMany_Upgrades, 5)
 
39
{
 
40
                return R->get_EAX() < 3 ? 0x4F7E41 : 0x4F7E34;
 
41
}
 
42
*/
 
43
 
 
44
/*
 
45
 * Attention: This is a rewrite of the "is this house defeated yet?" check that should clear up the
 
46
 * "On rare occasions, a player may lose every single unit they have but will not be 'defeated'." issues
 
47
 * But! It does so by detecting if you have any objects that are not in limbo, and defeating you if you don't.
 
48
 * An exception was added for parasites - they will count as eligible even when in limbo...
 
49
 */
 
50
 
 
51
DEFINE_HOOK(4F8EBD, HouseClass_Update_HasBeenDefeated, 0)
 
52
{
 
53
        GET(HouseClass *, H, ESI);
 
54
 
 
55
        if(H->OwnedBuildings) {
 
56
                return 0x4F8F87;
 
57
        }
 
58
 
 
59
        struct EligibleObject {
 
60
                HouseClass *H;
 
61
                EligibleObject(HouseClass *pHouse) : H(pHouse) {};
 
62
                bool operator()(TechnoClass *T) {
 
63
                        if(T->Owner != H) {
 
64
                                return false;
 
65
                        }
 
66
                        if(!T->InLimbo) {
 
67
                                return true;
 
68
                        }
 
69
                        if(FootClass *F = generic_cast<FootClass *>(T)) {
 
70
                                return F->ParasiteImUsing != NULL;
 
71
                        }
 
72
                        return false;
 
73
                }
 
74
        } Eligible(H);
 
75
 
 
76
        if(GameModeOptionsClass::Instance->ShortGame) {
 
77
                for(int i = 0; i < RulesClass::Instance->BaseUnit.Count; ++i) {
 
78
                        UnitTypeClass *U = RulesClass::Instance->BaseUnit[i];
 
79
                        if(H->OwnedUnitTypes.GetItemCount(U->ArrayIndex)) {
 
80
                                return 0x4F8F87;
 
81
                        }
 
82
                }
 
83
        } else {
 
84
                if(H->OwnedUnitTypes1.Count) {
 
85
                        for(int i = 0; i < UnitClass::Array->Count; ++i) {
 
86
                                TechnoClass *T = UnitClass::Array->Items[i];
 
87
                                if(Eligible(T)) {
 
88
                                        return 0x4F8F87;
 
89
                                }
 
90
                        }
 
91
                }
 
92
 
 
93
                if(H->OwnedInfantryTypes1.Count) {
 
94
                        for(int i = 0; i < InfantryClass::Array->Count; ++i) {
 
95
                                TechnoClass *T = InfantryClass::Array->Items[i];
 
96
                                if(Eligible(T)) {
 
97
                                        return 0x4F8F87;
 
98
                                }
 
99
                        }
 
100
                }
 
101
 
 
102
                if(H->OwnedAircraftTypes1.Count) {
 
103
                        for(int i = 0; i < AircraftClass::Array->Count; ++i) {
 
104
                                TechnoClass *T = AircraftClass::Array->Items[i];
 
105
                                if(Eligible(T)) {
 
106
                                        return 0x4F8F87;
 
107
                                }
 
108
                        }
 
109
                }
 
110
 
 
111
        }
 
112
 
 
113
        H->DestroyAll();
 
114
        H->AcceptDefeat();
 
115
 
 
116
        return 0x4F8F87;
 
117
}
 
118
 
 
119
DEFINE_HOOK(4F645F, HouseClass_CTOR_FixSideIndices, 5)
 
120
{
 
121
        GET(HouseClass *, pHouse, EBP);
 
122
        if(HouseTypeClass * pCountry = pHouse->Type) {
 
123
                if(strcmp(pCountry->ID, "Neutral") && strcmp(pCountry->ID, "Special")) {
 
124
                        pHouse->SideIndex = pCountry->SideIndex;
 
125
                }
 
126
        }
 
127
        return 0x4F6490;
 
128
}
 
129
 
 
130
DEFINE_HOOK(500CC5, HouseClass_InitFromINI_FixBufferLimits, 6)
 
131
{
 
132
        GET(HouseClass *, H, EBX);
 
133
 
 
134
        if(H->UINameString[0]) {
 
135
                const wchar_t *str = StringTable::LoadString(H->UINameString);
 
136
                CRT::wcsncpy(H->UIName, str, 20);
 
137
        } else {
 
138
                CRT::wcsncpy(H->UIName, H->Type->UIName, 20);
 
139
        }
 
140
 
 
141
        H->UIName[20] = 0;
 
142
        return 0x500D0D;
 
143
}
 
144
 
 
145
DEFINE_HOOK(4F62FF, HouseClass_CTOR_FixNameOverflow, 6)
 
146
{
 
147
        GET(HouseClass *, H, EBP);
 
148
        GET_STACK(HouseTypeClass *, Country, 0x48);
 
149
 
 
150
        CRT::wcsncpy(H->UIName, Country->UIName, 20);
 
151
 
 
152
        H->UIName[20] = 0;
 
153
 
 
154
        return 0x4F6312;
 
155
}