~ares-developers/ares/gd03

« back to all changes in this revision

Viewing changes to Ext/WeaponType/Hooks.Wave.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 "../Techno/Body.h"
3
 
 
4
 
// custom beam styles
5
 
// 6FF5F5, 6
6
 
DEFINE_HOOK(6FF5F5, TechnoClass_Fire, 6)
7
 
{
8
 
        GET(WeaponTypeClass *, Source, EBX);
9
 
        GET(TechnoClass *, Owner, ESI);
10
 
        GET(TechnoClass *, Target, EDI);
11
 
 
12
 
        WeaponTypeExt::ExtData *pData = WeaponTypeExt::ExtMap.Find(Source);
13
 
 
14
 
        RET_UNLESS(Source->IsMagBeam || Source->IsSonic || pData->Wave_IsLaser || pData->Wave_IsBigLaser);
15
 
 
16
 
        GET_BASE(byte, idxWeapon, 0xC);
17
 
 
18
 
        TechnoExt::ExtMap.Find(Owner)->idxSlot_Wave = idxWeapon;
19
 
 
20
 
        RET_UNLESS(pData->Wave_IsLaser || pData->Wave_IsBigLaser);
21
 
 
22
 
        LEA_STACK(CoordStruct *, xyzSrc, 0x44);
23
 
        LEA_STACK(CoordStruct *, xyzTgt, 0x88);
24
 
 
25
 
        WaveClass *Wave;
26
 
        GAME_ALLOC(WaveClass, Wave, xyzSrc, xyzTgt, Owner, pData->Wave_IsBigLaser ? 2 : 1, Target);
27
 
 
28
 
        WeaponTypeExt::WaveExt[Wave] = pData;
29
 
        Owner->Wave = Wave;
30
 
        return 0x6FF650;
31
 
}
32
 
 
33
 
// 75E963, 6
34
 
DEFINE_HOOK(75E963, WaveClass_CTOR, 6)
35
 
{
36
 
        GET(WaveClass *, Wave, ESI);
37
 
        GET(DWORD, Type, ECX);
38
 
        if(Type == wave_Laser || Type == wave_BigLaser) {
39
 
                return 0;
40
 
        }
41
 
        GET(WeaponTypeClass *, Weapon, EBX);
42
 
 
43
 
        if(Weapon) {
44
 
                WeaponTypeExt::ExtData *pData = WeaponTypeExt::ExtMap.Find(Weapon);
45
 
                WeaponTypeExt::WaveExt[Wave] = pData;
46
 
        }
47
 
        return 0;
48
 
}
49
 
 
50
 
/*
51
 
// 75EB87, 0A // fsdblargh, a single instruction spanning 10 bytes
52
 
XPORT_FUNC(WaveClass_CTOR2)
53
 
{
54
 
        GET(WaveClass *, Wave, ESI);
55
 
        RET_UNLESS(CONTAINS(WeaponTypeExt::WaveExt, Wave));
56
 
        WeaponTypeExt::WeaponTypeClassData *pData = WeaponTypeExt::WaveExt[Wave];
57
 
//      Wave->set_WaveIntensity(pData->Wave_InitialIntensity);
58
 
        return 0x75EB91;
59
 
}
60
 
*/
61
 
 
62
 
// 763226, 6
63
 
DEFINE_HOOK(763226, WaveClass_DTOR, 6)
64
 
{
65
 
        GET(WaveClass *, Wave, EDI);
66
 
        hash_waveExt::iterator i = WeaponTypeExt::WaveExt.find(Wave);
67
 
        if(i != WeaponTypeExt::WaveExt.end()) {
68
 
                WeaponTypeExt::WaveExt.erase(i);
69
 
        }
70
 
 
71
 
        return 0;
72
 
}
73
 
 
74
 
// 760F50, 6
75
 
// complete replacement for WaveClass::Update
76
 
DEFINE_HOOK(760F50, WaveClass_Update, 6)
77
 
{
78
 
        GET(WaveClass *, pThis, ECX);
79
 
 
80
 
        WeaponTypeExt::ExtData *pData = WeaponTypeExt::WaveExt[pThis];
81
 
        const WeaponTypeClass *Weap = pData->AttachedToObject;
82
 
 
83
 
        RET_UNLESS(Weap);
84
 
 
85
 
        int Intensity;
86
 
 
87
 
        if(Weap->AmbientDamage) {
88
 
                CoordStruct coords;
89
 
//              Debug::Log("Damaging Cells for weapon %X (Intensity = %d)\n", pData, pThis->WaveIntensity);
90
 
                for(int i = 0; i < pThis->Cells.Count; ++i) {
91
 
                        CellClass *Cell = pThis->Cells.GetItem(i);
92
 
//                      Debug::Log("\t(%hd,%hd)\n", Cell->MapCoords.X, Cell->MapCoords.Y);
93
 
                        pThis->DamageArea(Cell->Get3DCoords3(&coords));
94
 
                }
95
 
//              Debug::Log("Done damaging %X\n", pData);
96
 
        }
97
 
 
98
 
        switch(pThis->Type) {
99
 
                case wave_Sonic:
100
 
                        pThis->Update_Wave();
101
 
                        Intensity = pThis->WaveIntensity;
102
 
                        --Intensity;
103
 
                        pThis->WaveIntensity = Intensity;
104
 
                        if(Intensity < 0) {
105
 
                                pThis->UnInit();
106
 
                        } else {
107
 
                                SET_REG32(ECX, pThis);
108
 
                                CALL(0x5F3E70); // ObjectClass::Update
109
 
                        }
110
 
                        break;
111
 
                case wave_BigLaser:
112
 
                case wave_Laser:
113
 
                        Intensity = pThis->LaserIntensity;
114
 
                        Intensity -= 6;
115
 
                        pThis->LaserIntensity = Intensity;
116
 
                        if(Intensity < 32) {
117
 
                                pThis->UnInit();
118
 
                        }
119
 
                        break;
120
 
                case wave_Magnetron:
121
 
                        pThis->Update_Wave();
122
 
                        Intensity = pThis->WaveIntensity;
123
 
                        --Intensity;
124
 
                        pThis->WaveIntensity = Intensity;
125
 
                        if(Intensity < 0) {
126
 
                                pThis->UnInit();
127
 
                        } else {
128
 
                                SET_REG32(ECX, pThis);
129
 
                                CALL(0x5F3E70); // ObjectClass::Update
130
 
                        }
131
 
                        break;
132
 
        }
133
 
 
134
 
        return 0x76101A;
135
 
}
136
 
 
137
 
/*
138
 
// 760FFC, 5
139
 
// Alt beams update
140
 
XPORT_FUNC(WaveClass_UpdateLaser)
141
 
{
142
 
        GET(WaveClass *, Wave, ESI);
143
 
        Wave->Update_Beam();
144
 
        RET_UNLESS(CONTAINS(WeaponTypeExt::WaveExt, Wave));
145
 
        WeaponTypeExt::WeaponTypeClassData *pData = WeaponTypeExt::WaveExt[Wave];
146
 
        int intense = Wave->get_WaveIntensity() + pData->Wave_IntensityStep;
147
 
        Wave->set_WaveIntensity(intense);
148
 
        return intense >= pData->Wave_FinalIntensity ? 0x761016 : 0x76100C;
149
 
}
150
 
*/
151
 
 
152
 
DEFINE_HOOK(760BC2, WaveClass_Draw2, 9)
153
 
{
154
 
        GET(WaveClass *, Wave, EBX);
155
 
        GET(WORD *, dest, EBP);
156
 
 
157
 
        return (WeaponTypeExt::ModifyWaveColor(dest, dest, Wave->LaserIntensity, Wave))
158
 
                ? 0x760CAF
159
 
                : 0
160
 
        ;
161
 
}
162
 
 
163
 
// 760DE2, 6
164
 
DEFINE_HOOK(760DE2, WaveClass_Draw3, 9)
165
 
{
166
 
        GET(WaveClass *, Wave, EBX);
167
 
        GET(WORD *, dest, EDI);
168
 
 
169
 
        return (WeaponTypeExt::ModifyWaveColor(dest, dest, Wave->LaserIntensity, Wave))
170
 
                ? 0x760ECB
171
 
                : 0
172
 
        ;
173
 
}
174
 
 
175
 
// 75EE57, 7
176
 
DEFINE_HOOK(75EE57, WaveClass_Draw_Sonic, 7)
177
 
{
178
 
        GET_STACK(WaveClass *, Wave, 0x4);
179
 
        GET(DWORD, src, EDI);
180
 
        GET(DWORD, offset, ECX);
181
 
        DWORD offs = src + offset * 2;
182
 
 
183
 
        return (WeaponTypeExt::ModifyWaveColor((WORD *)offs, (WORD *)src, R->ESI(), Wave))
184
 
                ? 0x75EF1C
185
 
                : 0
186
 
        ;
187
 
}
188
 
 
189
 
// 7601FB, 0B
190
 
DEFINE_HOOK(7601FB, WaveClass_Draw_Magnetron, 0B)
191
 
{
192
 
        GET_STACK(WaveClass *, Wave, 0x8);
193
 
        GET(DWORD, src, EBX);
194
 
        GET(DWORD, offset, ECX);
195
 
        DWORD offs = src + offset * 2;
196
 
 
197
 
        return (WeaponTypeExt::ModifyWaveColor((WORD *)offs, (WORD *)src, R->EBP(), Wave))
198
 
                ? 0x760285
199
 
                : 0
200
 
        ;
201
 
}
202
 
 
203
 
// 760286, 5
204
 
DEFINE_HOOK(760286, WaveClass_Draw_Magnetron2, 5)
205
 
{
206
 
        return 0x7602D3;
207
 
}
208
 
 
209
 
bool WeaponTypeExt::ModifyWaveColor(WORD *src, WORD *dst, int Intensity, WaveClass *Wave)
210
 
{
211
 
        WeaponTypeExt::ExtData *pData = WeaponTypeExt::WaveExt[Wave];
212
 
 
213
 
        ColorStruct *CurrentColor = (pData->Wave_IsHouseColor && Wave->Owner)
214
 
                ? &Wave->Owner->Owner->Color
215
 
                : &pData->Wave_Color;
216
 
 
217
 
        if(*CurrentColor == ColorStruct(0, 0, 0)) {
218
 
                return false;
219
 
        }
220
 
 
221
 
        ColorStruct initial = Drawing::WordColor(*src);
222
 
 
223
 
        ColorStruct modified = initial;
224
 
 
225
 
// ugly hack to fix byte wraparound problems
226
 
#define upcolor(c) \
227
 
        int _ ## c = initial. c + (Intensity * CurrentColor-> c ) / 256; \
228
 
        _ ## c = min(_ ## c, 255); \
229
 
        modified. c = (BYTE)_ ## c;
230
 
 
231
 
        upcolor(R);
232
 
        upcolor(G);
233
 
        upcolor(B);
234
 
 
235
 
        WORD color = Drawing::Color16bit(&modified);
236
 
 
237
 
        *dst = color;
238
 
        return true;
239
 
}
240
 
 
241
 
// 762C5C, 6
242
 
DEFINE_HOOK(762C5C, WaveClass_Update_Wave, 6)
243
 
{
244
 
        GET(WaveClass *, Wave, ESI);
245
 
        TechnoClass *Firer = Wave->Owner;
246
 
        TechnoClass *Target = Wave->Target;
247
 
        if(!Target || !Firer) {
248
 
                return 0x762D57;
249
 
        }
250
 
 
251
 
        RET_UNLESS(WeaponTypeExt::WaveExt.find(Wave) != WeaponTypeExt::WaveExt.end());
252
 
        WeaponTypeExt::ExtData *pData = WeaponTypeExt::WaveExt[Wave];
253
 
        int weaponIdx = TechnoExt::ExtMap.Find(Firer)->idxSlot_Wave;
254
 
 
255
 
        CoordStruct xyzSrc, xyzTgt, xyzDummy = {0, 0, 0};
256
 
        Firer->GetFLH(&xyzSrc, weaponIdx, xyzDummy);
257
 
        Target->GetCoords__(&xyzTgt); // not GetCoords() !
258
 
 
259
 
        char idx = WeaponTypeExt:: AbsIDtoIdx(Target->WhatAmI());
260
 
 
261
 
        bool reversed = pData->Wave_Reverse[idx];
262
 
 
263
 
        if(Wave->Type == wave_Magnetron) {
264
 
                reversed
265
 
                        ? Wave->Draw_Magnetic(&xyzTgt, &xyzSrc)
266
 
                        : Wave->Draw_Magnetic(&xyzSrc, &xyzTgt);
267
 
        } else {
268
 
                reversed
269
 
                        ? Wave->Draw_NonMagnetic(&xyzTgt, &xyzSrc)
270
 
                        : Wave->Draw_NonMagnetic(&xyzSrc, &xyzTgt);
271
 
        }
272
 
 
273
 
        return 0x762D57;
274
 
}
275
 
 
276
 
// 75F38F, 6
277
 
DEFINE_HOOK(75F38F, WaveClass_DamageCell, 6)
278
 
{
279
 
        GET(WaveClass *, Wave, EBP);
280
 
        WeaponTypeExt::ExtData *pData = WeaponTypeExt::WaveExt[Wave];
281
 
        R->EDI(R->EAX());
282
 
        R->EBX(pData->AttachedToObject);
283
 
        return 0x75F39D;
284
 
}
285
 
 
286
 
DEFINE_HOOK(7601C7, WaveClass_Draw_Purple, 8)
287
 
{
288
 
        GET(int, Q, EDX);
289
 
        if(Q > 0x15F90) {
290
 
                Q = 0x15F90;
291
 
        }
292
 
        R->EDX(Q);
293
 
        return 0;
294
 
}