forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapdisplay.cpp
180 lines (161 loc) · 4.85 KB
/
mapdisplay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
MapDisplay - Renders the world view necessary for the intelligence map
Alex McLean, Pumpkin Studios, EIDOS Interactive, 1997
Makes heavy use of the functions available in display3d.c. Could have
messed about with display3d.c to make to world render dual purpose, but
it's neater as a separate file, as the intelligence map has special requirements
and overlays and needs to render to a specified buffer for later use.
*/
#include "lib/framework/frame.h"
#include "lib/ivis_opengl/piematrix.h"
#include "component.h"
#include "intdisplay.h"
#include "mapdisplay.h"
#define ROTATE_TIME (2*GAME_TICKS_PER_SEC)
/* renders the Research IMDs into the surface - used by message display in
Intelligence Map */
void renderResearchToBuffer(RESEARCH *psResearch, UDWORD OriginX, UDWORD OriginY)
{
UDWORD angle = 0;
BASE_STATS *psResGraphic;
UDWORD compID, IMDType;
Vector3i Rotation,Position;
UDWORD basePlateSize, Radius;
SDWORD scale = 0;
// Set identity (present) context
pie_MatBegin();
pie_SetGeometricOffset(OriginX+10, OriginY+10);
// Pitch down a bit
//pie_MatRotX(-65536/12);
// Rotate round
// full rotation once every 2 seconds..
angle = (gameTime2 % ROTATE_TIME) * 360 / ROTATE_TIME;
Position.x = 0;
Position.y = 0;
Position.z = BUTTON_DEPTH;
// Rotate round
Rotation.x = -30;
Rotation.y = angle;
Rotation.z = 0;
//draw the IMD for the research
if (psResearch->psStat)
{
//we have a Stat associated with this research topic
if (StatIsStructure(psResearch->psStat))
{
//this defines how the button is drawn
IMDType = IMDTYPE_STRUCTURESTAT;
psResGraphic = psResearch->psStat;
//set up the scale
basePlateSize= getStructureStatSizeMax((STRUCTURE_STATS*)psResearch->psStat);
if(basePlateSize == 1)
{
scale = RESEARCH_COMPONENT_SCALE / 2;
/*HACK HACK HACK!
if its a 'tall thin (ie tower)' structure stat with something on
the top - offset the position to show the object on top*/
if (((STRUCTURE_STATS*)psResearch->psStat)->pIMD[0]->nconnectors &&
getStructureStatHeight((STRUCTURE_STATS*)psResearch->psStat) > TOWER_HEIGHT)
{
Position.y -= 30;
}
}
else if(basePlateSize == 2)
{
scale = RESEARCH_COMPONENT_SCALE / 4;
}
else
{
scale = RESEARCH_COMPONENT_SCALE / 5;
}
}
else
{
compID = StatIsComponent(psResearch->psStat);
if (compID != COMP_UNKNOWN)
{
//this defines how the button is drawn
IMDType = IMDTYPE_COMPONENT;
psResGraphic = psResearch->psStat;
// NOTE: Another kludge to deal with the superTransport to make it "fit" the display.
// Using pName, should be safe to compare, pName doesn't get translated.
if (!strcmp("SuperTransport", psResearch->pName))
{
scale = RESEARCH_COMPONENT_SCALE / 3;
}
else
{
scale = RESEARCH_COMPONENT_SCALE;
}
}
else
{
ASSERT( false, "intDisplayMessageButton: invalid stat" );
IMDType = IMDTYPE_RESEARCH;
psResGraphic = (BASE_STATS *)psResearch;
}
}
}
else
{
//no Stat for this research topic so use the research topic to define what is drawn
psResGraphic = (BASE_STATS *)psResearch;
IMDType = IMDTYPE_RESEARCH;
}
//scale the research according to size of IMD
if (IMDType == IMDTYPE_RESEARCH)
{
Radius = getResearchRadius((BASE_STATS*)psResGraphic);
if(Radius <= 100)
{
scale = RESEARCH_COMPONENT_SCALE / 2;
}
else if(Radius <= 128)
{
scale = RESEARCH_COMPONENT_SCALE / 3;
}
else if(Radius <= 256)
{
scale = RESEARCH_COMPONENT_SCALE / 4;
}
else
{
scale = RESEARCH_COMPONENT_SCALE / 5;
}
}
/* display the IMDs */
if(IMDType == IMDTYPE_COMPONENT)
{
displayComponentButton(psResGraphic, &Rotation, &Position, true, scale);
}
else if(IMDType == IMDTYPE_RESEARCH)
{
displayResearchButton(psResGraphic, &Rotation, &Position, true, scale);
}
else if(IMDType == IMDTYPE_STRUCTURESTAT)
{
displayStructureStatButton((STRUCTURE_STATS *)psResGraphic, &Rotation, &Position, true, scale);
}
else
{
ASSERT( false, "Unknown PIEType" );
}
// close matrix context
pie_MatEnd();
}