forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npc_attack.h
146 lines (134 loc) · 5.65 KB
/
npc_attack.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
#pragma once
#ifndef CATA_SRC_NPC_ATTACK_H
#define CATA_SRC_NPC_ATTACK_H
#include <vector>
#include "gun_mode.h"
#include "item.h"
#include "map_iterator.h"
#include "optional.h"
#include "point.h"
#include "type_id.h"
class Creature;
class item;
class npc;
class npc_attack_rating
{
// the total calculated effectiveness of this attack. no value means this attack is not possible.
cata::optional<int> _value = cata::nullopt;
// the target tile of the attack
tripoint _target;
public:
npc_attack_rating() = default;
npc_attack_rating( const cata::optional<int> &_value,
const tripoint &_target ) : _value( _value ), _target( _target ) {}
cata::optional<int> value() const {
return _value;
}
tripoint target() const {
return _target;
}
bool operator>( const npc_attack_rating &rhs ) const;
bool operator>( int rhs ) const;
bool operator<( int rhs ) const;
npc_attack_rating operator-=( int rhs );
};
class npc_attack
{
public:
/**
* Parameters:
* source - the npc making the attack
* target - the desired target of the npc. valued at 100%
*/
virtual npc_attack_rating evaluate( const npc &source, const Creature *target ) const = 0;
virtual void use( npc &source, const tripoint &location ) const = 0;
/**
* For debug information. returns all evaluated effectivenesses.
* This is abstracted out in evaluate() as it's faster to not use a container
*/
virtual std::vector<npc_attack_rating> all_evaluations( const npc &source,
const Creature *target ) const = 0;
virtual ~npc_attack() = default;
};
/**
* The type of npc_attack that is a spell.
* Assumption: if we made it this far, the npc is able to cast the spell.
*/
class npc_attack_spell : public npc_attack
{
const spell_id attack_spell_id;
public:
explicit npc_attack_spell( const spell_id &attack_spell_id ) : attack_spell_id( attack_spell_id ) {}
npc_attack_rating evaluate( const npc &source, const Creature *target ) const override;
std::vector<npc_attack_rating> all_evaluations( const npc &source,
const Creature *target ) const override;
void use( npc &source, const tripoint &location ) const override;
private:
bool can_use( const npc &source ) const;
int base_time_penalty( const npc &source ) const;
npc_attack_rating evaluate_tripoint(
const npc &source, const Creature *target, const tripoint &location ) const;
};
class npc_attack_melee : public npc_attack
{
item &weapon;
public:
explicit npc_attack_melee( item &weapon ) : weapon( weapon ) {}
npc_attack_rating evaluate( const npc &source, const Creature *target ) const override;
std::vector<npc_attack_rating> all_evaluations( const npc &source,
const Creature *target ) const override;
void use( npc &source, const tripoint &location ) const override;
private:
tripoint_range<tripoint> targetable_points( const npc &source ) const;
bool can_use( const npc &source ) const;
int base_time_penalty( const npc &source ) const;
npc_attack_rating evaluate_critter( const npc &source, const Creature *target,
Creature *critter ) const;
};
class npc_attack_gun : public npc_attack
{
const gun_mode gunmode;
item &gun;
public:
explicit npc_attack_gun( item &gun, const gun_mode &gunmode ) : gunmode( gunmode ), gun( gun ) {}
npc_attack_rating evaluate( const npc &source, const Creature *target ) const override;
std::vector<npc_attack_rating> all_evaluations( const npc &source,
const Creature *target ) const override;
void use( npc &source, const tripoint &location ) const override;
private:
tripoint_range<tripoint> targetable_points( const npc &source ) const;
bool can_use( const npc &source ) const;
int base_time_penalty( const npc &source ) const;
npc_attack_rating evaluate_tripoint(
const npc &source, const Creature *target, const tripoint &location ) const;
};
class npc_attack_throw : public npc_attack
{
item &thrown_item;
public:
explicit npc_attack_throw( item &thrown_item ) : thrown_item( thrown_item ) {}
npc_attack_rating evaluate( const npc &source, const Creature *target ) const override;
std::vector<npc_attack_rating> all_evaluations( const npc &source,
const Creature *target ) const override;
void use( npc &source, const tripoint &location ) const override;
private:
tripoint_range<tripoint> targetable_points( const npc &source ) const;
bool can_use( const npc &source ) const;
int base_penalty( const npc &source ) const;
npc_attack_rating evaluate_tripoint(
const npc &source, const Creature *target, const tripoint &location ) const;
};
class npc_attack_activate_item : public npc_attack
{
item &activatable_item;
public:
explicit npc_attack_activate_item( item &activatable_item ) :
activatable_item( activatable_item ) {}
npc_attack_rating evaluate( const npc &source, const Creature *target ) const override;
std::vector<npc_attack_rating> all_evaluations( const npc &source,
const Creature *target ) const override;
void use( npc &source, const tripoint &location ) const override;
private:
bool can_use( const npc &source ) const;
};
#endif // CATA_SRC_NPC_ATTACK_H