4b825dc642cb6eb9a060e54bf8d69288fbee4904ebd360ec63ec976c05699f3180e866b3f69e5472
 
 
1
#include "system.h"
 
 
2
#include "prototyp.h"
 
 
3
#include "module.h"
 
 
4
#include "paintball.h"
 
 
5
#include "kshape.h"
 
 
6
#include "bh_types.h"
 
 
7
#include <stdio.h>
 
 
8
 
 
 
9
#define DECAL_Z_OFFSET 5
 
 
10
 
 
 
11
PAINTBALLMODE PaintBallMode;
 
 
12
 
 
 
13
void TogglePaintBallMode()
 
 
14
{
 
 
15
    PaintBallMode.IsOn = ~PaintBallMode.IsOn;
 
 
16
 
 
 
17
    if (PaintBallMode.IsOn)
 
 
18
    {
 
 
19
        PaintBallMode.CurrentDecalID = FIRST_PAINTBALL_DECAL;
 
 
20
        PaintBallMode.CurrentDecalSubclass = 0;
 
 
21
        PaintBallMode.CurrentDecalSize = DecalDescription[FIRST_PAINTBALL_DECAL].MinSize;
 
 
22
        PaintBallMode.CurrentDecalRotation = 0;
 
 
23
        PaintBallMode.DecalIsInverted = 0;
 
 
24
    }
 
 
25
}
 
 
26
 
 
 
27
DECAL CurrentDecal;
 
 
28
 
 
 
29
void PaintBallMode_DrawCurrentDecalAtTarget()
 
 
30
{
 
 
31
    DECAL_DESC *decalDescPtr = &DecalDescription[PaintBallMode.CurrentDecalID];
 
 
32
    extern void MakeMatrixFromDirection(VECTORCH *directionPtr, MATRIXCH *matrixPtr);
 
 
33
 
 
 
34
    MATRIXCH orientation;
 
 
35
    int sin = MUL_FIXED(PaintBallMode.CurrentDecalSize,GetSin(PaintBallMode.CurrentDecalRotation));
 
 
36
    int cos = MUL_FIXED(PaintBallMode.CurrentDecalSize,GetCos(PaintBallMode.CurrentDecalRotation));
 
 
37
    int z = DECAL_Z_OFFSET;
 
 
38
 
 
 
39
    if (!PaintBallMode.TargetDispPtr) 
 
 
40
        return;
 
 
41
 
 
 
42
    if (!(PaintBallMode.TargetDispPtr->Module && !PaintBallMode.TargetDispPtr->ObMorphCtrl))
 
 
43
        return;
 
 
44
 
 
 
45
    CurrentDecal.DecalID = PaintBallMode.CurrentDecalID;
 
 
46
 
 
 
47
    if(PaintBallMode.DecalIsInverted)
 
 
48
    {    
 
 
49
        PaintBallMode.TargetNormal.vx = -PaintBallMode.TargetNormal.vx;
 
 
50
        PaintBallMode.TargetNormal.vy = -PaintBallMode.TargetNormal.vy;
 
 
51
        PaintBallMode.TargetNormal.vz = -PaintBallMode.TargetNormal.vz;
 
 
52
        z = -z;
 
 
53
    }
 
 
54
 
 
 
55
    MakeMatrixFromDirection(&PaintBallMode.TargetNormal,&orientation);
 
 
56
 
 
 
57
    CurrentDecal.Vertices[0].vx = (-cos) - (-sin);
 
 
58
    CurrentDecal.Vertices[0].vy = (-sin) + (-cos);
 
 
59
    CurrentDecal.Vertices[0].vz = z;
 
 
60
    RotateVector(&(CurrentDecal.Vertices[0]),&orientation);
 
 
61
    CurrentDecal.Vertices[0].vx += PaintBallMode.TargetPosition.vx;
 
 
62
    CurrentDecal.Vertices[0].vy += PaintBallMode.TargetPosition.vy;
 
 
63
    CurrentDecal.Vertices[0].vz += PaintBallMode.TargetPosition.vz;
 
 
64
 
 
 
65
    CurrentDecal.Vertices[1].vx = (cos) - (-sin);
 
 
66
    CurrentDecal.Vertices[1].vy = (sin) + (-cos);
 
 
67
    CurrentDecal.Vertices[1].vz = z;
 
 
68
    RotateVector(&(CurrentDecal.Vertices[1]),&orientation);
 
 
69
    CurrentDecal.Vertices[1].vx += PaintBallMode.TargetPosition.vx;
 
 
70
    CurrentDecal.Vertices[1].vy += PaintBallMode.TargetPosition.vy;
 
 
71
    CurrentDecal.Vertices[1].vz += PaintBallMode.TargetPosition.vz;
 
 
72
 
 
 
73
    CurrentDecal.Vertices[2].vx = (cos) - (sin);
 
 
74
    CurrentDecal.Vertices[2].vy = (sin) + (cos);
 
 
75
    CurrentDecal.Vertices[2].vz = z;
 
 
76
    RotateVector(&(CurrentDecal.Vertices[2]),&orientation);
 
 
77
    CurrentDecal.Vertices[2].vx += PaintBallMode.TargetPosition.vx;
 
 
78
    CurrentDecal.Vertices[2].vy += PaintBallMode.TargetPosition.vy;
 
 
79
    CurrentDecal.Vertices[2].vz += PaintBallMode.TargetPosition.vz;
 
 
80
 
 
 
81
    CurrentDecal.Vertices[3].vx = (-cos) - (sin);
 
 
82
    CurrentDecal.Vertices[3].vy = (-sin) + (cos);
 
 
83
    CurrentDecal.Vertices[3].vz = z;
 
 
84
    RotateVector(&(CurrentDecal.Vertices[3]),&orientation);
 
 
85
    CurrentDecal.Vertices[3].vx += PaintBallMode.TargetPosition.vx;
 
 
86
    CurrentDecal.Vertices[3].vy += PaintBallMode.TargetPosition.vy;
 
 
87
    CurrentDecal.Vertices[3].vz += PaintBallMode.TargetPosition.vz;
 
 
88
 
 
 
89
    CurrentDecal.ModuleIndex = PlayerStatus.sbptr->containingModule->m_index;
 
 
90
 
 
 
91
    CurrentDecal.UOffset = PaintBallMode.CurrentDecalSubclass*decalDescPtr->UOffsetForSubclass;
 
 
92
    RenderDecal(&CurrentDecal);
 
 
93
 
 
 
94
    //printf("PAINTBALL MODE ACTIVE\n");
 
 
95
    printf("TOTAL PRE-DECALS: %d OUT OF 1024\n", NumFixedDecals);
 
 
96
}
 
 
97
 
 
 
98
void PaintBallMode_ChangeSelectedDecalID(int delta)
 
 
99
{
 
 
100
    PaintBallMode.CurrentDecalID += delta;
 
 
101
 
 
 
102
    if (PaintBallMode.CurrentDecalID > MAX_NO_OF_DECAL_IDS)
 
 
103
    {
 
 
104
        PaintBallMode.CurrentDecalID = FIRST_PAINTBALL_DECAL;
 
 
105
    }
 
 
106
    else if (PaintBallMode.CurrentDecalID < FIRST_PAINTBALL_DECAL)
 
 
107
    {
 
 
108
        PaintBallMode.CurrentDecalID = MAX_NO_OF_DECAL_IDS;
 
 
109
    }
 
 
110
 
 
 
111
    PaintBallMode.CurrentDecalSubclass = 0;
 
 
112
    PaintBallMode.CurrentDecalSize = DecalDescription[PaintBallMode.CurrentDecalID].MaxSize;
 
 
113
}
 
 
114
 
 
 
115
void PaintBallMode_ChangeSize(int delta)
 
 
116
{
 
 
117
    DECAL_DESC *decalDescPtr = &DecalDescription[PaintBallMode.CurrentDecalID];
 
 
118
 
 
 
119
    if (delta > 0)
 
 
120
    {
 
 
121
        PaintBallMode.CurrentDecalSize += NormalFrameTime>>6;
 
 
122
 
 
 
123
        if (PaintBallMode.CurrentDecalSize > decalDescPtr->MaxSize*2)
 
 
124
            PaintBallMode.CurrentDecalSize = decalDescPtr->MaxSize * 2;
 
 
125
    }
 
 
126
    else
 
 
127
    {
 
 
128
        PaintBallMode.CurrentDecalSize -= NormalFrameTime >> 6;
 
 
129
 
 
 
130
        if (PaintBallMode.CurrentDecalSize < decalDescPtr->MinSize)
 
 
131
            PaintBallMode.CurrentDecalSize = decalDescPtr->MinSize;
 
 
132
    }
 
 
133
}
 
 
134
 
 
 
135
void PaintBallMode_Rotate()
 
 
136
{
 
 
137
    PaintBallMode.CurrentDecalRotation += NormalFrameTime >> 5;
 
 
138
    PaintBallMode.CurrentDecalRotation &= 4095;
 
 
139
}
 
 
140
 
 
 
141
void PaintBallMode_ChangeSubclass(int delta)
 
 
142
{
 
 
143
    DECAL_DESC *decalDescPtr = &DecalDescription[PaintBallMode.CurrentDecalID];
 
 
144
 
 
 
145
    PaintBallMode.CurrentDecalSubclass += delta;
 
 
146
 
 
 
147
    if (PaintBallMode.CurrentDecalSubclass > decalDescPtr->MaxSubclassNumber)
 
 
148
    {
 
 
149
        PaintBallMode.CurrentDecalSubclass = 0;
 
 
150
    }
 
 
151
    else if (PaintBallMode.CurrentDecalSubclass < 0)
 
 
152
    {
 
 
153
        PaintBallMode.CurrentDecalSubclass = decalDescPtr->MaxSubclassNumber;
 
 
154
    }
 
 
155
}
 
 
156
 
 
 
157
void PaintBallMode_AddDecal()
 
 
158
{
 
 
159
    FIXED_DECAL *newDecalPtr = AllocateFixedDecal();
 
 
160
 
 
 
161
    newDecalPtr->DecalID = CurrentDecal.DecalID;
 
 
162
    newDecalPtr->Vertices[0] = CurrentDecal.Vertices[0];
 
 
163
    newDecalPtr->Vertices[1] = CurrentDecal.Vertices[1];
 
 
164
    newDecalPtr->Vertices[2] = CurrentDecal.Vertices[2];
 
 
165
    newDecalPtr->Vertices[3] = CurrentDecal.Vertices[3];
 
 
166
    newDecalPtr->ModuleIndex = CurrentDecal.ModuleIndex;
 
 
167
    newDecalPtr->UOffset = CurrentDecal.UOffset;
 
 
168
}
 
 
169
 
 
 
170
void PaintBallMode_RemoveDecal()
 
 
171
{
 
 
172
    RemoveFixedDecal();
 
 
173
}
 
 
174
 
 
 
175
void PaintBallMode_Randomise()
 
 
176
{
 
 
177
    DECAL_DESC *decalDescPtr = &DecalDescription[PaintBallMode.CurrentDecalID];
 
 
178
 
 
 
179
    int randomScale = ONE_FIXED+4096 - (FastRandom()&8191);
 
 
180
 
 
 
181
    PaintBallMode.CurrentDecalSize = MUL_FIXED(PaintBallMode.CurrentDecalSize,randomScale);
 
 
182
 
 
 
183
    if (PaintBallMode.CurrentDecalSize > decalDescPtr->MaxSize)
 
 
184
        PaintBallMode.CurrentDecalSize = decalDescPtr->MaxSize;
 
 
185
 
 
 
186
    if (PaintBallMode.CurrentDecalSize < decalDescPtr->MinSize)
 
 
187
         PaintBallMode.CurrentDecalSize = decalDescPtr->MinSize;
 
 
188
 
 
 
189
    PaintBallMode.CurrentDecalRotation = FastRandom()&4095;
 
 
190
}