-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathcareer_tasks.h
155 lines (129 loc) · 5.57 KB
/
career_tasks.h
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
/*
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*
*/
#ifndef CAREER_TASK_H
#define CAREER_TASK_H
#ifdef _WIN32
#pragma once
#endif
namespace sv {
class CCareerTask
{
public:
CCareerTask() = default;
virtual ~CCareerTask() = default;
CCareerTask(const char *taskName, GameEventType event, const char *weaponName, int n, bool mustLive, bool crossRounds, int id, bool isComplete);
public:
virtual void OnEvent(GameEventType event, CBasePlayer *pAttacker, CBasePlayer *pVictim);
virtual void Reset();
virtual bool IsTaskCompletableThisRound() { return true; }
public:
static CCareerTask *NewTask(const char *taskName, GameEventType event, const char *weaponName, int n, bool mustLive, bool crossRounds, int id, bool isComplete);
void OnWeaponKill(int weaponId, int weaponClassId, bool headshot, bool killerHasShield, CBasePlayer *pAttacker, CBasePlayer *pVictim);
void OnWeaponInjury(int weaponId, int weaponClassId, bool attackerHasShield, CBasePlayer *pAttacker);
bool IsComplete() { return m_isComplete;}
const char *GetTaskName() { return m_name; }
int GetWeaponId() { return m_weaponId; }
int GetWeaponClassId() { return m_weaponClassId; }
bool IsValidFor(CBasePlayer *pPlayer) { return true; }
void SendPartialNotification();
private:
bool m_isComplete;
const char *m_name;
int m_id;
GameEventType m_event;
int m_eventsNeeded;
int m_eventsSeen;
bool m_mustLive;
bool m_crossRounds;
bool m_diedThisRound;
int m_weaponId;
int m_weaponClassId;
bool m_rescuer;
bool m_defuser;
bool m_vip;
};
typedef std::list<CCareerTask *> CareerTaskList;
typedef CareerTaskList::iterator CareerTaskListIt;
typedef CCareerTask *(*TaskFactoryFunction)(const char *taskName, GameEventType event, const char *weaponName, int eventCount, bool mustLive, bool crossRounds, int nextId, bool isComplete);
class CPreventDefuseTask: public CCareerTask
{
public:
CPreventDefuseTask(const char *taskName, GameEventType event, const char *weaponName, int n, bool mustLive, bool crossRounds, int id, bool isComplete);
public:
virtual void OnEvent(GameEventType event, CBasePlayer *pAttacker, CBasePlayer *pVictim);
virtual void Reset();
virtual bool IsTaskCompletableThisRound() { return m_bombPlantedThisRound && !m_defuseStartedThisRound; }
public:
static CCareerTask *NewTask(const char *taskName, GameEventType event, const char *weaponName, int n, bool mustLive, bool crossRounds, int id, bool isComplete);
protected:
bool m_bombPlantedThisRound;
bool m_defuseStartedThisRound;
};
class CCareerTaskManager
{
public:
CCareerTaskManager();
public:
static void Create();
void Reset(bool deleteTasks = true);
void AddTask(const char *taskName, const char *weaponName, std::chrono::duration<int, std::ratio<1>> eventCount, bool mustLive, bool crossRounds, bool isComplete);
void HandleEvent(GameEventType event, CBasePlayer *pAttacker = NULL, CBasePlayer *pVictim = NULL);
void HandleEnemyKill(bool wasBlind, const char *weaponName, bool headshot, bool killerHasShield, CBasePlayer *pAttacker, CBasePlayer *pVictim);
void HandleWeaponKill(int weaponId, int weaponClassId, bool headshot, bool killerHasShield, CBasePlayer *pAttacker, CBasePlayer *pVictim);
void HandleDeath(int team, CBasePlayer *pAttacker = NULL);
void HandleWeaponInjury(int weaponId, int weaponClassId, bool attackerHasShield, CBasePlayer *pAttacker);
void HandleEnemyInjury(const char *weaponName, bool attackerHasShield, CBasePlayer *pAttacker);
bool AreAllTasksComplete();
int GetNumRemainingTasks();
duration_t GetRoundElapsedTime();
std::chrono::duration<int, std::ratio<1>> GetTaskTime() { return m_taskTime; }
void SetFinishedTaskTime(std::chrono::duration<int, std::ratio<1>> val);
std::chrono::duration<int, std::ratio<1>> GetFinishedTaskTime() { return m_finishedTaskTime; }
int GetFinishedTaskRound() { return m_finishedTaskRound; }
CareerTaskList *GetTasks() { return &m_tasks; }
void LatchRoundEndMessage();
void UnlatchRoundEndMessage();
private:
CareerTaskList m_tasks;
int m_nextId;
time_point_t m_roundStartTime;
std::chrono::duration<int, std::ratio<1>> m_taskTime;
std::chrono::duration<int, std::ratio<1>> m_finishedTaskTime;
int m_finishedTaskRound;
GameEventType m_roundEndMessage;
bool m_shouldLatchRoundEndMessage;
};
struct TaskInfo
{
const char *taskName;
GameEventType event;
TaskFactoryFunction factory;
};
extern CCareerTaskManager *TheCareerTasks;
}
#endif // CAREER_TASK_H