~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to .pc/02_blinking_triangles.patch/AstroMenaceSource/Object3D/GroundObject/GroundObject.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek, 1
  • Date: 2013-12-19 15:37:09 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131219153709-vs62lyk7ts7o3rf5
Tags: 1.3.2+repack-2
Add patch debian/patches/fix_work_on_intel_videocards.patch:
Mesa developers have enabled GL_ARB_texture_storage for all drivers [1], so
i915 and i965 drivers now claim the support of this OpenGL extension, but
texture storage feature does not actually work there.
.
[1] http://lists.freedesktop.org/archives/mesa-dev/2013-June/041188.html
.
This patch is just workaround to make the game work on intel videocards with
new Mesa. But real problem should be fixed in Mesa.
(Closes: #718680)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/************************************************************************************
2
 
 
3
 
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
4
 
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
5
 
 
6
 
 
7
 
        AstroMenace is free software: you can redistribute it and/or modify
8
 
        it under the terms of the GNU General Public License as published by
9
 
        the Free Software Foundation, either version 3 of the License, or
10
 
        (at your option) any later version.
11
 
 
12
 
        AstroMenace 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. See the
15
 
        GNU General Public License for more details.
16
 
 
17
 
        You should have received a copy of the GNU General Public License
18
 
        along with AstroMenace. If not, see <http://www.gnu.org/licenses/>.
19
 
 
20
 
 
21
 
        Web Site: http://www.viewizard.com/
22
 
        Project: http://sourceforge.net/projects/openastromenace/
23
 
        E-mail: viewizard@viewizard.com
24
 
 
25
 
*************************************************************************************/
26
 
 
27
 
 
28
 
/// подключаем нужные файлы
29
 
#include "GroundObject.h"
30
 
#include "../../Game.h"
31
 
 
32
 
 
33
 
//-----------------------------------------------------------------------------
34
 
// Конструктор, инициализация всех переменных
35
 
//-----------------------------------------------------------------------------
36
 
CGroundObject::CGroundObject(void)
37
 
{
38
 
 
39
 
        ObjectStatus = 1; // чужой
40
 
 
41
 
        // колес или траков нет
42
 
        WheelQuantity = 0;
43
 
        WheelObjectsNum = 0;
44
 
        WheelRotateQuantity = 0;
45
 
        WheelRotateObjectsNum = 0;
46
 
        WheelRotateSpeed = 0.0f;
47
 
        MaxWheelRotateAngle = 20.0f;
48
 
        TrackObjectNum = -1;
49
 
        TrackRotationDirection = 1;
50
 
 
51
 
        TargetHorizObjectQuantity = 0;
52
 
        TargetHorizObject = 0;
53
 
        TargetHorizObjectCurrentAngle = 0.0f;
54
 
        TargetHorizObjectNeedAngle = 0.0f;
55
 
        TargetVertObjectQuantity = 0;
56
 
        TargetVertObject = 0;
57
 
        TargetVertObjectMaxAngle = 80.0f;
58
 
        TargetVertObjectMinAngle = 0.0f;
59
 
        TargetVertObjectCurrentAngle = 0.0f;
60
 
        TargetVertObjectNeedAngle = 0.0f;
61
 
 
62
 
        BarrelObjectQuantity = 0;
63
 
        BarrelObject = 0;
64
 
 
65
 
 
66
 
        // и никуда не нужно поворачивать
67
 
        NeedRotate = VECTOR3D(0.0f, 0.0f, 0.0f);
68
 
        RotationSpeed = VECTOR3D(1.0f, 1.0f, 1.0f);
69
 
 
70
 
        // скорость
71
 
        MaxSpeed = Speed = NeedSpeed = 0.0f;
72
 
 
73
 
        // ускорение, пока нет двигателей - его нет...
74
 
        MaxAcceler = MaxSpeedRotate = Acceler = 0.0f;
75
 
        // даем максимальное ускорение
76
 
        NeedAcceler = 1.0f;
77
 
 
78
 
        SpeedToRotate = 0.0f;
79
 
 
80
 
 
81
 
        // наведение на цель
82
 
        WeaponTargeting = false;
83
 
 
84
 
 
85
 
        // оружие пока не установлено
86
 
        WeaponQuantity = 0;
87
 
        WeaponSetFire = 0;
88
 
        WeaponLocation = 0;
89
 
        Weapon = 0;
90
 
        WeaponFireType = 2;
91
 
        WeaponGroupCurrentFireNum = -1;
92
 
        WeaponGroupCurrentFireDelay = 0.0f;
93
 
 
94
 
        BaseBound = VECTOR3D(0.0f,0.0f,0.0f);
95
 
        MiddleBound = VECTOR3D(0.0f,0.0f,0.0f);
96
 
        WeaponBound = 0;
97
 
        DoNotCalculateRotation = false;
98
 
 
99
 
        // подключаем к своему списку
100
 
        Next = Prev = 0;
101
 
        AttachGroundObject(this);
102
 
 
103
 
}
104
 
 
105
 
 
106
 
 
107
 
//-----------------------------------------------------------------------------
108
 
// Деструктор
109
 
//-----------------------------------------------------------------------------
110
 
CGroundObject::~CGroundObject(void)
111
 
{
112
 
        if (WheelObjectsNum != 0){delete [] WheelObjectsNum; WheelObjectsNum = 0;};
113
 
        if (WheelRotateObjectsNum != 0){delete [] WheelRotateObjectsNum; WheelRotateObjectsNum = 0;};
114
 
        if (WeaponBound != 0){delete [] WeaponBound; WeaponBound = 0;};
115
 
 
116
 
        if (TargetHorizObject != 0){delete [] TargetHorizObject; TargetHorizObject = 0;};
117
 
        if (TargetVertObject != 0){delete [] TargetVertObject; TargetVertObject = 0;};
118
 
 
119
 
        if (BarrelObject != 0){delete [] BarrelObject; BarrelObject = 0;};
120
 
 
121
 
        DetachGroundObject(this);
122
 
}
123
 
 
124
 
 
125
 
 
126
 
 
127
 
 
128
 
 
129
 
 
130
 
 
131
 
 
132
 
 
133
 
//-----------------------------------------------------------------------------
134
 
// Установка положения объекта
135
 
//-----------------------------------------------------------------------------
136
 
void CGroundObject::SetLocation(VECTOR3D NewLocation)
137
 
{
138
 
        // вызываем родительскую функцию
139
 
        ::CObject3D::SetLocation(NewLocation);
140
 
 
141
 
        // если оружие вообще есть
142
 
        if (Weapon != 0)
143
 
        for (int i=0; i<WeaponQuantity; i++)
144
 
        {
145
 
                if (Weapon[i] != 0) Weapon[i]->SetLocation(NewLocation + WeaponLocation[i]);
146
 
        }
147
 
}
148
 
 
149
 
 
150
 
 
151
 
 
152
 
//-----------------------------------------------------------------------------
153
 
// Установка углов поворота объекта
154
 
//-----------------------------------------------------------------------------
155
 
void CGroundObject::SetRotation(VECTOR3D NewRotation)
156
 
{
157
 
        // вызываем родительскую функцию
158
 
        ::CObject3D::SetRotation(NewRotation);
159
 
 
160
 
        // оружие
161
 
        VECTOR3D RotationBase = Rotation;
162
 
        VECTOR3D BaseBoundTMP = BaseBound;
163
 
        RotatePoint(&BaseBoundTMP, RotationBase);
164
 
 
165
 
        VECTOR3D RotationMiddle = Rotation;
166
 
        VECTOR3D MiddleBoundTMP = MiddleBound;
167
 
        if (TargetHorizObject != 0)
168
 
        {
169
 
                RotationMiddle = DrawObjectList[TargetHorizObject[0]].Rotation + Rotation;
170
 
        }
171
 
        RotatePoint(&MiddleBoundTMP, RotationMiddle);
172
 
 
173
 
        VECTOR3D RotationWeapon = Rotation;
174
 
        if (TargetVertObject != 0)
175
 
        {
176
 
                RotationWeapon = DrawObjectList[TargetVertObject[0]].Rotation + Rotation;
177
 
        }
178
 
 
179
 
 
180
 
        if (Weapon != 0)
181
 
        for (int i=0; i<WeaponQuantity; i++)
182
 
        if (Weapon[i] != 0)
183
 
        {
184
 
                VECTOR3D WeaponBoundTMP = WeaponBound[i];
185
 
                RotatePoint(&WeaponBoundTMP, RotationWeapon);
186
 
 
187
 
                WeaponLocation[i] = BaseBoundTMP + MiddleBoundTMP + WeaponBoundTMP;
188
 
 
189
 
 
190
 
                // особый случай, испускаем без вращающихся частей (антиматерия, ион)
191
 
                if (TargetHorizObject == 0 && TargetVertObject == 0)
192
 
                if (!DoNotCalculateRotation) // и если нужно считать...
193
 
                {
194
 
                        RotationWeapon = VECTOR3D(TargetVertObjectNeedAngle, TargetHorizObjectNeedAngle, 0.0f)+Rotation;
195
 
                }
196
 
                Weapon[i]->SetRotation(Weapon[i]->Rotation^(-1.0f));
197
 
                Weapon[i]->SetRotation(RotationWeapon);
198
 
 
199
 
                Weapon[i]->SetLocation(Location + WeaponLocation[i]);
200
 
        }
201
 
}
202
 
 
203
 
 
204
 
 
205
 
 
206
 
 
207
 
 
208
 
 
209
 
 
210
 
 
211
 
//-----------------------------------------------------------------------------
212
 
// Обновление данных объектa Object3D
213
 
//-----------------------------------------------------------------------------
214
 
bool CGroundObject::Update(float Time)
215
 
{
216
 
        // вызываем родительскую функцию
217
 
        // если там передали удалить - выходим
218
 
        if (!::CObject3D::Update(Time)) return false;
219
 
        // быстро вызвали еще раз... время не изменилось, или почти не изменилось
220
 
        if (TimeDelta == 0.0f) return true;
221
 
 
222
 
 
223
 
 
224
 
 
225
 
 
226
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
227
 
        // обработка скрипта
228
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
229
 
        if (StartTimeSheet != 0)
230
 
        if (!StartTimeSheet->InUse)
231
 
        {
232
 
                StartTimeSheet->InUse = true;
233
 
 
234
 
                NeedSpeed = StartTimeSheet->Speed;
235
 
                NeedAcceler = StartTimeSheet->Acceler;
236
 
                NeedRotate = StartTimeSheet->Rotation;
237
 
                RotationSpeed = StartTimeSheet->RotationAcceler;
238
 
                WeaponTargeting = StartTimeSheet->Targeting;
239
 
 
240
 
                if (Weapon != 0)
241
 
                for (int i=0; i<WeaponQuantity; i++)
242
 
                {
243
 
                        if (Weapon[i] != 0)
244
 
                                WeaponSetFire[i] = StartTimeSheet->Fire;
245
 
                }
246
 
        }
247
 
 
248
 
 
249
 
 
250
 
 
251
 
 
252
 
 
253
 
 
254
 
 
255
 
 
256
 
 
257
 
 
258
 
 
259
 
 
260
 
        // если нужно наводить на цель
261
 
        if (WeaponTargeting)
262
 
        {
263
 
 
264
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
265
 
                // наводим на цель, если есть возможность
266
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267
 
 
268
 
                // находимся в начальном состоянии поворота ствола
269
 
                int WeapNum = 204; // номер самого простого из пиратского оружия
270
 
                VECTOR3D        FirePos(0.0f,0.0f,0.0f);
271
 
                if (Weapon != 0)
272
 
                {
273
 
                        if (Weapon[0] != 0)
274
 
                        {
275
 
                                WeapNum = Weapon[0]->ObjectCreationType;
276
 
                                //FirePos = WeaponLocation[0];
277
 
                        }
278
 
 
279
 
                        int Count = 0;
280
 
                        for (int i=0; i<WeaponQuantity; i++)
281
 
                        if (Weapon[i] != 0)
282
 
                        {
283
 
                                FirePos += WeaponLocation[i];
284
 
                                Count++;
285
 
                        }
286
 
                        FirePos = FirePos^(1.0f/Count);
287
 
                }
288
 
                VECTOR3D NeedAngle(TargetVertObjectNeedAngle,TargetHorizObjectNeedAngle,0);
289
 
                if (GetTurretOnTargetOrientateion(ObjectStatus, Location+FirePos, Rotation,
290
 
                                CurrentRotationMat,     &NeedAngle, WeapNum))
291
 
                {
292
 
                        // наводим на цель
293
 
                        TargetHorizObjectNeedAngle = NeedAngle.y;
294
 
                        TargetVertObjectNeedAngle = NeedAngle.x;
295
 
                }
296
 
                else
297
 
                {
298
 
                        // врагов нет, нужно просто поднять ствол
299
 
                        TargetVertObjectNeedAngle = TargetVertObjectMaxAngle*0.5f;
300
 
                }
301
 
        }
302
 
        else
303
 
        {
304
 
                // устанавливаем в начальное положение
305
 
                TargetHorizObjectNeedAngle = 0.0f;
306
 
                TargetVertObjectNeedAngle = 0.0f;
307
 
 
308
 
        }
309
 
 
310
 
 
311
 
        // собственно повороты элементов модели на углы
312
 
        {
313
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
314
 
                // поворот башни по горизонтале
315
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
316
 
                if (TargetHorizObject != 0)
317
 
                if (TargetHorizObjectNeedAngle != TargetHorizObjectCurrentAngle)
318
 
                {
319
 
                        if (fabsf(TargetHorizObjectNeedAngle-TargetHorizObjectCurrentAngle) > 180.0f)
320
 
                        {
321
 
                                if (TargetHorizObjectCurrentAngle - TargetHorizObjectNeedAngle > 180.0f) TargetHorizObjectCurrentAngle -= 360.0f;
322
 
                                if (TargetHorizObjectNeedAngle - TargetHorizObjectCurrentAngle > 180.0f) TargetHorizObjectCurrentAngle += 360.0f;
323
 
                        }
324
 
 
325
 
                        // находим угол, на который нужно повернуть
326
 
                        float NeedRotate = TargetHorizObjectCurrentAngle;
327
 
 
328
 
                        if (TargetHorizObjectNeedAngle>TargetHorizObjectCurrentAngle)
329
 
                        {
330
 
                                NeedRotate += 80.0f*TimeDelta/GameNPCTargetingSpeedPenalty;
331
 
                                if (NeedRotate > TargetHorizObjectNeedAngle) NeedRotate = TargetHorizObjectNeedAngle;
332
 
                        }
333
 
                        else
334
 
                        {
335
 
                                NeedRotate -= 80.0f*TimeDelta/GameNPCTargetingSpeedPenalty;
336
 
                                if (NeedRotate < TargetHorizObjectNeedAngle) NeedRotate = TargetHorizObjectNeedAngle;
337
 
                        }
338
 
 
339
 
                        // устанавливаем текущий поворот
340
 
                        TargetHorizObjectCurrentAngle = NeedRotate;
341
 
 
342
 
                        // поворачиваем все объекты
343
 
                        for (int i=0; i<TargetHorizObjectQuantity; i++)
344
 
                        {
345
 
 
346
 
                                VECTOR3D tmp = DrawObjectList[TargetHorizObject[i]].Location-DrawObjectList[TargetHorizObject[0]].Location;
347
 
 
348
 
                                RotatePointInv(&tmp, DrawObjectList[TargetHorizObject[i]].Rotation^(-1.0f));
349
 
 
350
 
                                SetObjectRotation(VECTOR3D(DrawObjectList[TargetHorizObject[i]].Rotation.x,
351
 
                                        -NeedRotate,
352
 
                                        DrawObjectList[TargetHorizObject[i]].Rotation.z), TargetHorizObject[i]);
353
 
 
354
 
                                RotatePoint(&tmp, DrawObjectList[TargetHorizObject[i]].Rotation);
355
 
 
356
 
                                SetObjectLocation(tmp+DrawObjectList[TargetHorizObject[0]].Location, TargetHorizObject[i]);
357
 
                        }
358
 
                }
359
 
 
360
 
 
361
 
 
362
 
 
363
 
 
364
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
365
 
                // поворот стволов по вертикали
366
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
367
 
                if (TargetVertObject != 0)
368
 
                if (TargetVertObjectNeedAngle != TargetVertObjectCurrentAngle)
369
 
                {
370
 
 
371
 
                        // находим угол, на который нужно повернуть
372
 
                        float NeedRotate = TargetVertObjectCurrentAngle;
373
 
                        if (TargetVertObjectNeedAngle>TargetVertObjectCurrentAngle)
374
 
                        {
375
 
                                NeedRotate += 80.0f*TimeDelta/GameNPCTargetingSpeedPenalty;
376
 
                                if (NeedRotate > TargetVertObjectNeedAngle) NeedRotate = TargetVertObjectNeedAngle;
377
 
                                if (NeedRotate > TargetVertObjectMaxAngle) NeedRotate = TargetVertObjectMaxAngle;
378
 
                        }
379
 
                        else
380
 
                        {
381
 
                                NeedRotate -= 80.0f*TimeDelta/GameNPCTargetingSpeedPenalty;
382
 
                                if (NeedRotate < TargetVertObjectNeedAngle) NeedRotate = TargetVertObjectNeedAngle;
383
 
                                if (NeedRotate < TargetVertObjectMinAngle) NeedRotate = TargetVertObjectMinAngle;
384
 
                        }
385
 
 
386
 
                        // устанавливаем текущий поворот
387
 
                        TargetVertObjectCurrentAngle = NeedRotate;
388
 
 
389
 
                        // поворачиваем все объекты
390
 
                        for (int i=0; i<TargetVertObjectQuantity; i++)
391
 
                        {
392
 
 
393
 
                                VECTOR3D tmp = DrawObjectList[TargetVertObject[i]].Location-DrawObjectList[TargetVertObject[0]].Location;
394
 
 
395
 
                                RotatePointInv(&tmp, DrawObjectList[TargetVertObject[i]].Rotation^(-1.0f));
396
 
 
397
 
                                SetObjectRotation(VECTOR3D(-NeedRotate,
398
 
                                        DrawObjectList[TargetVertObject[i]].Rotation.y,
399
 
                                        DrawObjectList[TargetVertObject[i]].Rotation.z), TargetVertObject[i]);
400
 
 
401
 
                                RotatePoint(&tmp, DrawObjectList[TargetVertObject[i]].Rotation);
402
 
 
403
 
                                SetObjectLocation(tmp+DrawObjectList[TargetVertObject[0]].Location, TargetVertObject[i]);
404
 
                        }
405
 
                }
406
 
        }
407
 
 
408
 
 
409
 
 
410
 
 
411
 
 
412
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
413
 
        // находим точку стрельбы и учитываем направление
414
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
415
 
        VECTOR3D RotationBase = Rotation;
416
 
        VECTOR3D BaseBoundTMP = BaseBound;
417
 
        RotatePoint(&BaseBoundTMP, RotationBase);
418
 
 
419
 
        VECTOR3D RotationMiddle = Rotation;
420
 
        VECTOR3D MiddleBoundTMP = MiddleBound;
421
 
        if (TargetHorizObject != 0)
422
 
        {
423
 
                RotationMiddle = DrawObjectList[TargetHorizObject[0]].Rotation + Rotation;
424
 
        }
425
 
        RotatePoint(&MiddleBoundTMP, RotationMiddle);
426
 
 
427
 
        VECTOR3D RotationWeapon = Rotation;
428
 
        if (TargetVertObject != 0)
429
 
        {
430
 
                RotationWeapon = DrawObjectList[TargetVertObject[0]].Rotation + Rotation;
431
 
        }
432
 
 
433
 
 
434
 
        if (Weapon != 0)
435
 
        for (int i=0; i<WeaponQuantity; i++)
436
 
        if (Weapon[i] != 0)
437
 
        {
438
 
                VECTOR3D WeaponBoundTMP = WeaponBound[i];
439
 
                RotatePoint(&WeaponBoundTMP, RotationWeapon);
440
 
 
441
 
                WeaponLocation[i] = BaseBoundTMP + MiddleBoundTMP + WeaponBoundTMP;
442
 
 
443
 
                // особый случай, испускаем без вращающихся частей (антиматерия, ион)
444
 
                if (TargetHorizObject == 0 && TargetVertObject == 0)
445
 
                if (!DoNotCalculateRotation) // и если нужно считать...
446
 
                {
447
 
                        RotationWeapon = Rotation - VECTOR3D(TargetVertObjectNeedAngle, TargetHorizObjectNeedAngle, 0.0f);
448
 
                }
449
 
 
450
 
 
451
 
                Weapon[i]->SetRotation(Weapon[i]->Rotation^(-1.0f));
452
 
                Weapon[i]->SetRotation(RotationWeapon);
453
 
 
454
 
                Weapon[i]->SetLocation(Location + WeaponLocation[i]);
455
 
        }
456
 
 
457
 
 
458
 
 
459
 
 
460
 
 
461
 
 
462
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
463
 
        // смотрим, есть ли команда открыть огонь
464
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
465
 
        if (Weapon != 0)
466
 
        {
467
 
                // если залп или игрок (игроку регулируем сами)
468
 
                if (WeaponFireType == 1)
469
 
                {
470
 
                        for (int i=0; i<WeaponQuantity; i++)
471
 
                                if (Weapon[i] != 0)
472
 
                                        if (WeaponSetFire[i])
473
 
                                                Weapon[i]->WeaponFire(Time);
474
 
                }
475
 
                else// переменный огонь
476
 
                if (WeaponFireType == 2)
477
 
                {
478
 
 
479
 
                        int PrimCount = 0;
480
 
                        float PrimTime = 0.0f;
481
 
                        int FirstWeapon = 6;
482
 
                        int LastWeapon = 0;
483
 
 
484
 
                        WeaponGroupCurrentFireDelay -= TimeDelta;
485
 
 
486
 
                        // находим кол-во оружия
487
 
                        for (int i=0; i<WeaponQuantity; i++)
488
 
                        if (Weapon[i] != 0)
489
 
                        {
490
 
                                PrimCount++;
491
 
                                PrimTime += Weapon[i]->NextFireTime;
492
 
                                if (FirstWeapon > i) FirstWeapon = i;
493
 
                                if (LastWeapon < i) LastWeapon = i;
494
 
                        }
495
 
                        // если еще не было начальной установки
496
 
                        if (WeaponGroupCurrentFireNum == -1) WeaponGroupCurrentFireNum = FirstWeapon;
497
 
 
498
 
 
499
 
                        // стреляем
500
 
                        for (int i=0; i<WeaponQuantity; i++)
501
 
                        if (Weapon[i] != 0)
502
 
                        if (WeaponSetFire[i])
503
 
                        {
504
 
                                if (WeaponGroupCurrentFireNum == i &&
505
 
                                        WeaponGroupCurrentFireDelay <= 0.0f)
506
 
                                {
507
 
                                        Weapon[i]->WeaponFire(Time);
508
 
 
509
 
                                        WeaponGroupCurrentFireDelay = (PrimTime/PrimCount)*((1.0f+GameNPCWeaponPenalty)/2.0f);
510
 
                                        WeaponGroupCurrentFireNum ++;
511
 
                                        if (WeaponGroupCurrentFireNum > LastWeapon) WeaponGroupCurrentFireNum = FirstWeapon;
512
 
 
513
 
                                        // если такого оружия нет, берем что есть
514
 
                                        if (Weapon[WeaponGroupCurrentFireNum] == 0)
515
 
                                        {
516
 
                                                bool exit = false;
517
 
                                                while (!exit)
518
 
                                                {
519
 
                                                        WeaponGroupCurrentFireNum ++;
520
 
                                                        if (WeaponGroupCurrentFireNum > LastWeapon) WeaponGroupCurrentFireNum = FirstWeapon;
521
 
                                                        if (Weapon[WeaponGroupCurrentFireNum] != 0) exit = true;
522
 
                                                }
523
 
                                        }
524
 
 
525
 
                                }
526
 
                        }
527
 
 
528
 
                }
529
 
                else// переменный огонь2 (залп ракет или чего-то еще)
530
 
                if (WeaponFireType == 3)
531
 
                {
532
 
 
533
 
                        int PrimCount = 0;
534
 
                        float PrimTime = 0.0f;
535
 
                        int FirstWeapon = 6;
536
 
                        int LastWeapon = 0;
537
 
 
538
 
                        WeaponGroupCurrentFireDelay -= TimeDelta;
539
 
 
540
 
                        // находим кол-во оружия
541
 
                        for (int i=0; i<WeaponQuantity; i++)
542
 
                        if (Weapon[i] != 0)
543
 
                        {
544
 
                                PrimCount++;
545
 
                                PrimTime += Weapon[i]->NextFireTime;
546
 
                                if (FirstWeapon > i) FirstWeapon = i;
547
 
                                if (LastWeapon < i) LastWeapon = i;
548
 
                        }
549
 
                        // если еще не было начальной установки
550
 
                        if (WeaponGroupCurrentFireNum == -1) WeaponGroupCurrentFireNum = FirstWeapon;
551
 
 
552
 
 
553
 
                        // стреляем
554
 
                        for (int i=0; i<WeaponQuantity; i++)
555
 
                        if (Weapon[i] != 0)
556
 
                        if (WeaponSetFire[i])
557
 
                        {
558
 
                                if (WeaponGroupCurrentFireNum == i &&
559
 
                                        WeaponGroupCurrentFireDelay <= 0.0f)
560
 
                                {
561
 
                                        Weapon[i]->WeaponFire(Time);
562
 
 
563
 
                                        WeaponGroupCurrentFireDelay = PrimTime/(PrimCount*PrimCount);
564
 
                                        WeaponGroupCurrentFireNum ++;
565
 
                                        if (WeaponGroupCurrentFireNum > LastWeapon) WeaponGroupCurrentFireNum = FirstWeapon;
566
 
 
567
 
                                        // если такого оружия нет, берем что есть
568
 
                                        if (Weapon[WeaponGroupCurrentFireNum] == 0)
569
 
                                        {
570
 
                                                bool exit = false;
571
 
                                                while (!exit)
572
 
                                                {
573
 
                                                        WeaponGroupCurrentFireNum ++;
574
 
                                                        if (WeaponGroupCurrentFireNum > LastWeapon) WeaponGroupCurrentFireNum = FirstWeapon;
575
 
                                                        if (Weapon[WeaponGroupCurrentFireNum] != 0) exit = true;
576
 
                                                }
577
 
                                        }
578
 
 
579
 
                                }
580
 
                        }
581
 
 
582
 
                }
583
 
 
584
 
 
585
 
        }
586
 
 
587
 
 
588
 
 
589
 
 
590
 
 
591
 
 
592
 
 
593
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
594
 
        // вращение стволов пулемета
595
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
596
 
        if (BarrelObjectQuantity != 0)
597
 
        if (BarrelObject != 0)
598
 
        {
599
 
                for (int i=0; i<BarrelObjectQuantity; i++)
600
 
                {
601
 
                        DrawObjectList[BarrelObject[i]].NeedGeometryAnimation = true;
602
 
                        DrawObjectList[BarrelObject[i]].GeometryAnimation += VECTOR3D(0.0f,0.0f,500.0f*TimeDelta);
603
 
                        if (DrawObjectList[BarrelObject[i]].GeometryAnimation.z > 360.0f) DrawObjectList[BarrelObject[i]].GeometryAnimation.z -= 360.0f;
604
 
                }
605
 
        }
606
 
 
607
 
 
608
 
 
609
 
 
610
 
 
611
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
612
 
        // вращение колес в транспорте
613
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
614
 
        if (WheelObjectsNum != 0 && (WheelTrackSpeed >= 0.00001f || WheelTrackSpeed <= -0.00001f))
615
 
        {
616
 
                // перебираем все и ув. их угол вращения
617
 
                for (int i=0; i<WheelQuantity; i++)
618
 
                {
619
 
                        DrawObjectList[WheelObjectsNum[i]].Rotation.x += WheelTrackSpeed*TimeDelta;
620
 
 
621
 
                        if (DrawObjectList[WheelObjectsNum[i]].Rotation.x > 360.0f) DrawObjectList[WheelObjectsNum[i]].Rotation.x -= 360.0f;
622
 
                        if (DrawObjectList[WheelObjectsNum[i]].Rotation.x < -360.0f) DrawObjectList[WheelObjectsNum[i]].Rotation.x += 360.0f;
623
 
                }
624
 
        }
625
 
 
626
 
 
627
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
628
 
        // тайловая анимация для траков
629
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
630
 
        if (TrackObjectNum != -1 && (WheelTrackSpeed >= 0.00001f || WheelTrackSpeed <= -0.00001f))
631
 
        {
632
 
                DrawObjectList[TrackObjectNum].NeedTextureAnimation = true;
633
 
                DrawObjectList[TrackObjectNum].TextureAnimation.x += (WheelTrackSpeed/500.0f)*TimeDelta*TrackRotationDirection;
634
 
                if (DrawObjectList[TrackObjectNum].TextureAnimation.x > 1.0f) DrawObjectList[TrackObjectNum].TextureAnimation.x -= 1.0f;
635
 
                if (DrawObjectList[TrackObjectNum].TextureAnimation.x < -1.0f) DrawObjectList[TrackObjectNum].TextureAnimation.x += 1.0f;
636
 
        }
637
 
 
638
 
 
639
 
 
640
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
641
 
        // повотор
642
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
643
 
        if (NeedRotate.x != 0.0f || NeedRotate.y != 0.0f || NeedRotate.z != 0.0f)
644
 
        {
645
 
                // Находим допустимый поворот по углу
646
 
                VECTOR3D tmpRotate(0.0f, 0.0f, 0.0f);
647
 
 
648
 
                // угол по x
649
 
                if (NeedRotate.x != 0.0f)
650
 
                {
651
 
                        float Sign = 1.0f;
652
 
                        if (NeedRotate.x < 0.0f) Sign = -1.0f;
653
 
                        // вычисляем скорость поворота по данным двигателя
654
 
                        tmpRotate.x = Sign*MaxSpeedRotate*RotationSpeed.x*TimeDelta;
655
 
                        // смотрим, если уже повернули - снимаем
656
 
                        if (Sign == 1.0f)
657
 
                        {if (tmpRotate.x >= NeedRotate.x) {tmpRotate.x = NeedRotate.x; NeedRotate.x = 0.0f;}}
658
 
                        else {if (tmpRotate.x <= NeedRotate.x) {tmpRotate.x = NeedRotate.x; NeedRotate.x = 0.0f;}}
659
 
                        // меняем значение
660
 
                        if (NeedRotate.x != 0.0f) NeedRotate.x -= tmpRotate.x;
661
 
                }
662
 
 
663
 
                // угол по y
664
 
                if (NeedRotate.y != 0.0f)
665
 
                {
666
 
                        float Sign = 1.0f;
667
 
                        if (NeedRotate.y < 0.0f) Sign = -1.0f;
668
 
                        // вычисляем скорость поворота по данным двигателя
669
 
                        tmpRotate.y = Sign*MaxSpeedRotate*RotationSpeed.y*TimeDelta;
670
 
                        // смотрим, если уже повернули - снимаем
671
 
                        if (Sign == 1.0f)
672
 
                        {if (tmpRotate.y >= NeedRotate.y) {tmpRotate.y = NeedRotate.y; NeedRotate.y = 0.0f;}}
673
 
                        else {if (tmpRotate.y <= NeedRotate.y) {tmpRotate.y = NeedRotate.y; NeedRotate.y = 0.0f;}}
674
 
                        // меняем значение
675
 
                        if (NeedRotate.y != 0.0f) NeedRotate.y -= tmpRotate.y;
676
 
                }
677
 
 
678
 
 
679
 
                // угол по z
680
 
                if (NeedRotate.z != 0.0f)
681
 
                {
682
 
                        float Sign = 1.0f;
683
 
                        if (NeedRotate.z < 0.0f) Sign = -1.0f;
684
 
                        // вычисляем скорость поворота по данным двигателя
685
 
                        tmpRotate.z = Sign*MaxSpeedRotate*RotationSpeed.z*TimeDelta;
686
 
                        // смотрим, если уже повернули - снимаем
687
 
                        if (Sign == 1.0f)
688
 
                        {if (tmpRotate.z >= NeedRotate.z) {tmpRotate.z = NeedRotate.z; NeedRotate.z = 0.0f;}}
689
 
                        else {if (tmpRotate.z <= NeedRotate.z) {tmpRotate.z = NeedRotate.z; NeedRotate.z = 0.0f;}}
690
 
                        // меняем значение
691
 
                        if (NeedRotate.z != 0.0f) NeedRotate.z -= tmpRotate.z;
692
 
                }
693
 
 
694
 
                // установка поворота там же сохраняем, какой общий поворот модели
695
 
                SetRotation(tmpRotate);
696
 
 
697
 
 
698
 
 
699
 
 
700
 
 
701
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
702
 
                // поворот колес в транспорте
703
 
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
704
 
                if (WheelRotateObjectsNum != 0)
705
 
                {
706
 
                        // перебираем все и ув. их угол вращения
707
 
                        for (int i=0; i<WheelRotateQuantity; i++)
708
 
                        {
709
 
                                float NeedRotateY = DrawObjectList[WheelRotateObjectsNum[i]].Rotation.y;
710
 
                                if (DrawObjectList[WheelRotateObjectsNum[i]].Rotation.y > NeedRotate.y)
711
 
                                {
712
 
                                        NeedRotateY -= 90.0f*TimeDelta;
713
 
                                        if (NeedRotateY < NeedRotate.y)
714
 
                                                NeedRotateY = NeedRotate.y;
715
 
                                }
716
 
                                else
717
 
                                if (DrawObjectList[WheelRotateObjectsNum[i]].Rotation.y < NeedRotate.y)
718
 
                                {
719
 
                                        NeedRotateY += 90.0f*TimeDelta;
720
 
                                        if (NeedRotateY > NeedRotate.y)
721
 
                                                NeedRotateY = NeedRotate.y;
722
 
                                }
723
 
 
724
 
                                if (NeedRotateY>MaxWheelRotateAngle)
725
 
                                        NeedRotateY = MaxWheelRotateAngle;
726
 
                                if (NeedRotateY<-MaxWheelRotateAngle)
727
 
                                        NeedRotateY = -MaxWheelRotateAngle;
728
 
 
729
 
 
730
 
                                SetObjectRotation(VECTOR3D(DrawObjectList[WheelRotateObjectsNum[i]].Rotation.x,
731
 
                                        NeedRotateY,
732
 
                                        DrawObjectList[WheelRotateObjectsNum[i]].Rotation.z), WheelRotateObjectsNum[i]);
733
 
 
734
 
                        }
735
 
                }
736
 
 
737
 
        }
738
 
 
739
 
 
740
 
 
741
 
 
742
 
 
743
 
 
744
 
 
745
 
 
746
 
 
747
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
748
 
        // ускорение-замедление
749
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
750
 
 
751
 
        // если нужно разогнаться, или управление на игроке - и нужно стремиться к нулю
752
 
        if (NeedSpeed != 0.0f)
753
 
        {
754
 
                float Sign = 1.0f;
755
 
                // нужно двигать назад
756
 
                if (NeedSpeed < 0.0f) Sign = -1.0f;
757
 
 
758
 
                // "ровняем" скорость под модель
759
 
                if (Sign == 1.0f)
760
 
                {Clamp(NeedSpeed, 0.0f, MaxSpeed);}
761
 
                else
762
 
                {Clamp(NeedSpeed, -MaxSpeed, 0.0f);}
763
 
 
764
 
                // случай, когда нужно затормозить а не менять направление
765
 
                if (Sign == 1.0f)
766
 
                {if (NeedSpeed < Speed) Sign = -1.0f;}
767
 
                else
768
 
                {if (NeedSpeed > Speed) Sign = 1.0f;}
769
 
 
770
 
 
771
 
                // даем полный газ, учитывая сколько процентов можем выдать
772
 
                Acceler = Sign*MaxAcceler*NeedAcceler;
773
 
 
774
 
                // считаем текущую скорость
775
 
                Speed = Speed + Acceler*TimeDelta;
776
 
 
777
 
                // смотрим, если уже разогнались - снимаем
778
 
                if (Sign == 1.0f)
779
 
                {if (NeedSpeed <= Speed) {Speed = NeedSpeed; NeedSpeed = 0.0f;}}
780
 
                else {if (NeedSpeed >= Speed) {Speed = NeedSpeed; NeedSpeed = 0.0f;}}
781
 
        }
782
 
 
783
 
 
784
 
 
785
 
 
786
 
 
787
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
788
 
        // небольшая девиация-болтание колес, если нужно
789
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
790
 
        if (DeviationOn)
791
 
        for (int i=0; i<DeviationObjQuantity; i++)
792
 
        {
793
 
                float Sign = 1.0f;
794
 
                // нужно двигать
795
 
                if (NeedDeviation[i] < 0.0f) Sign = -1.0f;
796
 
                if (Sign == 1.0f)
797
 
                {if (NeedDeviation[i] < CurentDeviationSum[i]) Sign = -1.0f;}
798
 
                else
799
 
                {if (NeedDeviation[i] > CurentDeviationSum[i]) Sign = 1.0f;}
800
 
 
801
 
                CurentDeviation[i] = Sign*0.35f*TimeDelta;
802
 
 
803
 
                if (Sign == 1.0f)
804
 
                {
805
 
                        if (NeedDeviation[i] <= CurentDeviationSum[i]+CurentDeviation[i])
806
 
                        {
807
 
                                CurentDeviation[i] -= CurentDeviationSum[i]+CurentDeviation[i]-NeedDeviation[i];
808
 
                                CurentDeviationSum[i] += CurentDeviation[i];
809
 
                                NeedDeviation[i] = vw_Randf0*0.1f;
810
 
                        }
811
 
                        else CurentDeviationSum[i] += CurentDeviation[i];
812
 
                }
813
 
                else
814
 
                {
815
 
                        if (NeedDeviation[i] >= CurentDeviationSum[i]+CurentDeviation[i])
816
 
                        {
817
 
                                CurentDeviation[i] += CurentDeviationSum[i]+CurentDeviation[i]-NeedDeviation[i];
818
 
                                CurentDeviationSum[i] += CurentDeviation[i];
819
 
                                NeedDeviation[i] = vw_Randf0*0.1f;
820
 
                        }
821
 
                        else CurentDeviationSum[i] += CurentDeviation[i];
822
 
                }
823
 
 
824
 
                VECTOR3D Tmp = Deviation[i]^CurentDeviation[i];
825
 
                SetObjectLocation(DrawObjectList[DeviationObjNum[i]].Location + Tmp, DeviationObjNum[i]);
826
 
        }
827
 
 
828
 
 
829
 
 
830
 
 
831
 
 
832
 
 
833
 
 
834
 
 
835
 
 
836
 
 
837
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
838
 
        // считаем вектор движения
839
 
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
840
 
        //VECTOR3D Velocity = (Orientation^(Speed*TimeDelta))+(VECTOR3D(0.0f,0.0f,10.0f)^TimeDelta);
841
 
        VECTOR3D Velocity = (Orientation^(Speed*TimeDelta));
842
 
 
843
 
        // перемещение объекта, если нужно
844
 
        if (Velocity.x != 0.0f || Velocity.y != 0.0f  || Velocity.z != 0.0f )
845
 
        {
846
 
                WheelTrackSpeed = Speed*SpeedToRotate;
847
 
                // делаем сдвиг модели в указанную точку
848
 
                SetLocation(Location+Velocity);
849
 
        }
850
 
 
851
 
 
852
 
 
853
 
 
854
 
 
855
 
        // объект в порядке - удалять не нужно
856
 
        return true;
857
 
}
858
 
 
859
 
 
860