1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1997, 2005 - 3D Realms Entertainment
4
5 This file is part of Shadow Warrior version 1.2
6
7 Shadow Warrior is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 Original Source: 1997 - Frank Maddin and Jim Norwood
23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24 */
25 //-------------------------------------------------------------------------
26 #include "build.h"
27
28 #include "names2.h"
29 #include "game.h"
30 #include "tags.h"
31 #include "common_game.h"
32 #include "break.h"
33 #include "quake.h"
34 #include "pal.h"
35 #include "sprite.h"
36
37 extern short NormalVisibility; // player.c
38
39 #define VIS_VisCur(sp) (SP_TAG2(sp))
40 #define VIS_VisDir(sp) (SP_TAG3(sp))
41 #define VIS_VisGoal(sp) (SP_TAG4(sp))
42
ProcessVisOn(void)43 void ProcessVisOn(void)
44 {
45 short i, nexti;
46 SPRITEp sp;
47
48 TRAVERSE_SPRITE_STAT(headspritestat[STAT_VIS_ON], i, nexti)
49 {
50 sp = &sprite[i];
51
52 if (VIS_VisDir(sp))
53 {
54 // get brighter
55 VIS_VisCur(sp) >>= 1;
56 //VIS_VisCur(sp) -= 16;
57 if (VIS_VisCur(sp) <= VIS_VisGoal(sp))
58 {
59 VIS_VisCur(sp) = VIS_VisGoal(sp);
60 VIS_VisDir(sp) ^= 1;
61 }
62 }
63 else
64 {
65 // get darker
66 VIS_VisCur(sp) <<= 1;
67 VIS_VisCur(sp) += 1;
68 //VIS_VisCur(sp) += 16;
69 if (VIS_VisCur(sp) >= NormalVisibility)
70 {
71 VIS_VisCur(sp) = NormalVisibility;
72 if (sp->owner >= 0)
73 {
74 ASSERT(User[sp->owner]);
75 RESET(User[sp->owner]->Flags2, SPR2_VIS_SHADING);
76 }
77 KillSprite(i);
78 }
79 }
80 }
81 }
82
VisViewChange(PLAYERp pp,int * vis)83 void VisViewChange(PLAYERp pp, int *vis)
84 {
85 short i, nexti;
86 SPRITEp sp;
87 short BrightestVis = NormalVisibility;
88 int x,y,z;
89 short sectnum;
90
91 if (GamePaused)
92 return;
93
94 // find the closest quake - should be a strength value
95 TRAVERSE_SPRITE_STAT(headspritestat[STAT_VIS_ON], i, nexti)
96 {
97 sp = &sprite[i];
98
99 if (sp->owner >= 0)
100 {
101 x = sprite[sp->owner].x;
102 y = sprite[sp->owner].y;
103 z = sprite[sp->owner].z;
104 sectnum = sprite[sp->owner].sectnum;
105 }
106 else
107 {
108 x = sp->x;
109 y = sp->y;
110 z = sp->z;
111 sectnum = sp->sectnum;
112 }
113
114 // save off the brightest vis that you can see
115 if (FAFcansee(pp->posx, pp->posy, pp->posz, pp->cursectnum, x, y, z, sectnum))
116 {
117 if (VIS_VisCur(sp) < BrightestVis)
118 BrightestVis = VIS_VisCur(sp);
119 }
120 }
121
122 *vis = BrightestVis;
123 }
124
SpawnVis(short Parent,short sectnum,int x,int y,int z,int amt)125 int SpawnVis(short Parent, short sectnum, int x, int y, int z, int amt)
126 {
127 short SpriteNum;
128 SPRITEp sp;
129 short i,nexti;
130
131 if (Parent >= 0)
132 {
133 if (sector[sprite[Parent].sectnum].floorpal == PALETTE_FOG)
134 return -1;
135
136 if (sector[sprite[Parent].sectnum].floorpal == PALETTE_DIVE_LAVA)
137 return -1;
138
139 // kill any others with the same parent
140 TRAVERSE_SPRITE_STAT(headspritestat[STAT_VIS_ON], i, nexti)
141 {
142 sp = &sprite[i];
143 if (sp->owner == Parent)
144 {
145 KillSprite(i);
146 }
147 }
148
149 SpriteNum = COVERinsertsprite(sprite[Parent].sectnum, STAT_VIS_ON);
150 sp = &sprite[SpriteNum];
151
152 sp->owner = Parent;
153
154 ASSERT(User[Parent]);
155 SET(User[Parent]->Flags2, SPR2_CHILDREN);
156
157 sp->x = sprite[Parent].x;
158 sp->y = sprite[Parent].y;
159 sp->z = sprite[Parent].z;
160
161 SET(User[Parent]->Flags2, SPR2_VIS_SHADING);
162 }
163 else
164 {
165 if (sector[sectnum].floorpal == PALETTE_FOG)
166 return -1;
167
168 SpriteNum = COVERinsertsprite(sectnum, STAT_VIS_ON);
169 sp = &sprite[SpriteNum];
170
171 sp->x = x;
172 sp->y = y;
173 sp->z = z - Z(20);
174 sp->owner = -1;
175 }
176
177 sp->cstat = 0;
178 sp->extra = 0;
179
180 VIS_VisDir(sp) = 1;
181 VIS_VisCur(sp) = NormalVisibility;
182 VIS_VisGoal(sp) = amt;
183
184 return SpriteNum;
185 }
186
187