1 /*
2 Solar Conquest
3 Copyright (C) 2006 Greg Beaman
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 class CFactory
21 {
22 public:
23 int team;
24 int obj;
25 int aiType;
26 CFactory* aiParent;
27
28 float spawnTime;
29
30 Vector position;
31
32 CFactory* nextObj;
33 CFactory* prevObj;
34
35 CObject* parent;
36
37 CFactory();
38 ~CFactory();
39
40 void Update(float elapsedTime);
41 void Render(float cameraX, float cameraY);
42 };
43
CFactory()44 CFactory::CFactory()
45 {
46 spawnTime = 0;
47
48 nextObj = NULL;
49 prevObj = NULL;
50 parent = NULL;
51
52 aiParent = NULL;
53 aiType = AI_TYPE_NORMAL;
54 obj = -1;
55 }
56
~CFactory()57 CFactory::~CFactory()
58 {
59 }
60
Update(float elapsedTime)61 void CFactory::Update(float elapsedTime)
62 {
63 if (spawnTime > 0)
64 spawnTime -= elapsedTime;
65 }
66
Render(float cameraX,float cameraY)67 void CFactory::Render(float cameraX, float cameraY)
68 {
69 //Render
70 if (team == 1)
71 glColor4f(0,0,1,0.4);
72 else if (team == 2)
73 glColor4f(1,0,0,0.4);
74 else
75 glColor4f(1,1,1,0.4);
76
77 if (Distance(cameraX+(g_screenWidth/2),cameraY+(g_screenHeight/2),position.x,position.y) <= ((g_screenWidth)+30))
78 {
79 glBegin(GL_TRIANGLE_FAN);
80 glVertex2f(position.x-cameraX,position.y-cameraY);
81 {
82 for (int i=0; i <= 8; i++)
83 glVertex2f((GetSin(ToRadians(360/8)*i)*30)+(position.x-cameraX),(GetCos(ToRadians(360/8)*i)*30)+(position.y-cameraY));
84 }
85 glEnd();
86
87 glBegin(GL_LINE_STRIP);
88 {
89 for (int i=0; i <= 8; i++)
90 glVertex2f((GetSin(ToRadians(360/8)*i)*30)+(position.x-cameraX),(GetCos(ToRadians(360/8)*i)*30)+(position.y-cameraY));
91 }
92 glEnd();
93 }
94 }
95
96 CFactory* g_firstFactory = NULL;
97
AddFactory()98 CFactory* AddFactory()
99 {
100 CFactory* newObj;
101 newObj = new CFactory();
102 if (!newObj)
103 return NULL;
104 newObj->nextObj = g_firstFactory;
105 if (g_firstFactory)
106 g_firstFactory->prevObj = newObj;
107 g_firstFactory = newObj;
108
109 return newObj;
110 }
111
DeleteFactory(CFactory * node)112 void DeleteFactory(CFactory* node)
113 {
114 if (!node)
115 return;
116
117 if (node->prevObj)
118 node->prevObj->nextObj = node->nextObj;
119 else
120 g_firstFactory = node->nextObj;
121 if (node->nextObj)
122 node->nextObj->prevObj = node->prevObj;
123 delete node;
124 }
125
DeleteAllFactories()126 void DeleteAllFactories()
127 {
128 CFactory* curObj;
129 CFactory* tmpObj;
130 curObj = g_firstFactory;
131 while (curObj)
132 {
133 tmpObj = curObj->nextObj;
134 delete curObj;
135 curObj = tmpObj;
136 }
137 g_firstFactory = NULL;
138 }
139
140
141