summaryrefslogtreecommitdiffstats
path: root/src/taskgungoal.cpp
blob: 9066c5ab55c7f3fd706ddad06199539601ec2438 (plain)
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
// taskgungoal.cpp

#define STRICT
#define D3D_OVERLOADS

#include <windows.h>
#include <stdio.h>
#include <d3d.h>

#include "struct.h"
#include "D3DEngine.h"
#include "math3d.h"
#include "event.h"
#include "misc.h"
#include "iman.h"
#include "object.h"
#include "sound.h"
#include "task.h"
#include "taskgungoal.h"




// Constructeur de l'objet.

CTaskGunGoal::CTaskGunGoal(CInstanceManager* iMan, CObject* object)
						  : CTask(iMan, object)
{
	CTask::CTask(iMan, object);
}

// Destructeur de l'objet.

CTaskGunGoal::~CTaskGunGoal()
{
}


// Gestion d'un �v�nement.

BOOL CTaskGunGoal::EventProcess(const Event &event)
{
	float		dir;

	if ( m_engine->RetPause() )  return TRUE;
	if ( event.event != EVENT_FRAME )  return TRUE;

	m_progress += event.rTime*m_speed;

	if ( m_progress < 1.0f )
	{
		dir = m_initialDirV + (m_finalDirV-m_initialDirV)*m_progress;
	}
	else
	{
		dir = m_finalDirV;
	}
	m_object->SetGunGoalV(dir);

	if ( m_progress < 1.0f )
	{
		dir = m_initialDirH + (m_finalDirH-m_initialDirH)*m_progress;
	}
	else
	{
		dir = m_finalDirH;
	}
	m_object->SetGunGoalH(dir);

	return TRUE;
}


// Assigne le but � atteindre.

Error CTaskGunGoal::Start(float dirV, float dirH)
{
	float	speedV, speedH;
	int		i;

	m_initialDirV = m_object->RetGunGoalV();
	m_object->SetGunGoalV(dirV);
	m_finalDirV = m_object->RetGunGoalV();  // direction possible
	m_object->SetGunGoalV(m_initialDirV);  // remet direction initiale

	if ( m_finalDirV == m_initialDirV )
	{
		speedV = 100.0f;
	}
	else
	{
		speedV = 1.0f/(Abs(m_finalDirV-m_initialDirV)*1.0f);
	}

	m_initialDirH = m_object->RetGunGoalH();
	m_object->SetGunGoalH(dirH);
	m_finalDirH = m_object->RetGunGoalH();  // direction possible
	m_object->SetGunGoalH(m_initialDirH);  // remet direction initiale

	if ( m_finalDirH == m_initialDirH )
	{
		speedH = 100.0f;
	}
	else
	{
		speedH = 1.0f/(Abs(m_finalDirH-m_initialDirH)*1.0f);
	}

	m_speed = Min(speedV, speedH);

	if ( m_finalDirV != m_initialDirV ||
		 m_finalDirH != m_initialDirH )
	{
		i = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 0.3f, 1.5f, TRUE);
		m_sound->AddEnvelope(i, 0.3f, 1.5f, 1.0f/m_speed, SOPER_STOP);
	}

	m_progress = 0.0f;

	return ERR_OK;
}

// Indique si l'action est termin�e.

Error CTaskGunGoal::IsEnded()
{
	if ( m_engine->RetPause() )  return ERR_CONTINUE;

	if ( m_initialDirV == m_finalDirV &&
		 m_initialDirH == m_finalDirH )  return ERR_STOP;
	if ( m_progress < 1.0f )  return ERR_CONTINUE;

	m_object->SetGunGoalV(m_finalDirV);
	m_object->SetGunGoalH(m_finalDirH);
	Abort();
	return ERR_STOP;
}

// Termine brutalement l'action en cours.

BOOL CTaskGunGoal::Abort()
{
	return TRUE;
}