-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBot.h
112 lines (93 loc) · 3.31 KB
/
Bot.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
// @Begin License@
// This file is part of Coldest.
//
// Coldest 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 3 of the License, or
// (at your option) any later version.
//
// Coldest 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 Coldest. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2008-2012 Ben Nemec
// @End License@
#ifndef __BOT_H
#define __BOT_H
#include <list>
#include <boost/shared_ptr.hpp>
#include <SDL/SDL_net.h>
#include "IDGen.h"
#include "Packet.h"
#include "BotNetCode.h"
#include "util.h"
#include "globals.h"
#include "PathNode.h"
/**
@author Ben Nemec <cybertron@nemebean.com>
*/
class Bot{
public:
Bot();
~Bot();
static void Initialize();
static void SetPlayers(vector<PlayerData>&);
static vector<PlayerData> GetPlayers();
static void SetPathNodes(vector<PathNodePtr>& p) {pathnodes = p;}
int Team() {return BotPlayer().team;}
void SetAllSpawns(vector<SpawnPointData> s) {allspawns = s;}
tsint baseattacker;
float checkdist;
private:
bool botrunning;
BotNetCodePtr netcode;
Uint32 lasttick;
Timer timer;
Timer movetimer;
Timer firetimer;
Timer updatetimer;
Timer targettimer;
SDL_Thread* thread;
vector<PlayerData> localplayers; // Thread-specific copy of players to avoid locking issues
size_t targetplayer;
vector<SpawnPointData> allspawns; // Netcode only gives us the ones for our team
SpawnPointData targetspawn;
Vector3 movetarget;
PathNodePtr currpathnode;
Vector3 heading;
// Determines how close the bot wants to get - smaller numbers make it closer
float closingdistance;
Uint32 lastupdate;
static vector<PlayerData> players;
static MutexPtr playermutex;
static vector<PathNodePtr> pathnodes;
static tsint lastserverupdate;
// Don't really want to copy this object because threads would need
// to be restarted every time. To use in an STL container use
// smart pointers
Bot(const Bot&);
Bot& operator=(const Bot&);
static int Start(void*);
void Update();
void Loop();
// Returns the PlayerData object that represents our current state (note that netcode->bot does not!)
PlayerData& BotPlayer() {return localplayers[netcode->PlayerNum()];}
size_t SelectTarget();
void SelectTargetSpawn();
void SelectSpawn();
void AimAtTarget(const Vector3&);
void FindCurrPathNode();
void UpdateHeading();
void TurnToHeading();
void CheckForNearerTarget();
intvec GetOpponents();
float SkillAverage() {return (console.GetFloat("botskillmax") + 1.f) / 2.f;}
float SkillMax() {return console.GetFloat("botskillmax");}
float Skill() {return console.GetFloat("botskill");}
};
typedef boost::shared_ptr<Bot> BotPtr;
#endif