15 #ifndef PIE_NOON_CHARACTER_H_
16 #define PIE_NOON_CHARACTER_H_
18 #include "character_state_machine.h"
19 #include "character_state_machine_def_generated.h"
20 #include "config_generated.h"
21 #include "motive/math/angle.h"
22 #include "motive/motivator.h"
23 #include "motive/util.h"
24 #include "pie_noon_common_generated.h"
25 #include "player_controller.h"
26 #include "timeline_generated.h"
37 typedef int CharacterHealth;
51 enum VictoryState { kResultUnknown, kVictorious, kFailure };
60 const CharacterStateMachineDef* character_state_machine_def);
63 void Reset(CharacterId target, CharacterHealth health,
64 motive::Angle face_angle,
const mathfu::vec3& position,
65 motive::MotiveEngine* engine);
70 void TwitchFaceAngle(motive::TwitchDirection twitch);
73 void force_target(CharacterId target) { target_ = target; }
76 motive::Angle FaceAngle()
const {
return motive::Angle(face_angle_.Value()); }
79 void SetTarget(CharacterId target, motive::Angle angle_to_target);
82 uint16_t RenderableId(WorldTime anim_time)
const;
86 uint16_t Variant()
const;
89 mathfu::vec4 Color()
const;
92 mathfu::vec4 ButtonColor()
const;
95 const Timeline* CurrentTimeline()
const {
96 return state_machine_.current_state()->timeline();
100 uint16_t State()
const {
101 return static_cast<uint16_t
>(state_machine_.current_state()->id());
104 uint16_t state_last_update()
const {
return state_last_update_; }
108 void UpdatePreviousState() { state_last_update_ = State(); }
111 bool Active()
const {
return State() != StateId_KO; }
114 void PlaySound(
const char* sound)
const;
116 CharacterHealth health()
const {
return health_; }
117 void set_health(CharacterHealth health) { health_ = health; }
119 CharacterId id()
const {
return id_; }
121 CharacterId target()
const {
return target_; }
123 CharacterHealth pie_damage()
const {
return pie_damage_; }
124 void set_pie_damage(CharacterHealth pie_damage) { pie_damage_ = pie_damage; }
126 mathfu::vec3 position()
const {
return position_; }
127 void set_position(
const mathfu::vec3& position) { position_ = position; }
129 const Controller* controller()
const {
return controller_; }
130 Controller* controller() {
return controller_; }
131 void set_controller(
Controller* controller) { controller_ = controller; }
137 void IncrementStat(PlayerStats stat);
138 uint64_t& GetStat(PlayerStats stat) {
return player_stats_[stat]; }
140 void set_score(
int score) { score_ = score; }
141 int score() {
return score_; }
143 void set_just_joined_game(
bool just_joined_game) {
144 just_joined_game_ = just_joined_game;
146 bool just_joined_game() {
return just_joined_game_; }
148 void set_victory_state(VictoryState state) { victory_state_ = state; }
149 VictoryState victory_state() {
return victory_state_; }
155 bool visible()
const {
return visible_; }
156 void set_visible(
bool visible) { visible_ = visible; }
160 const Config* config_;
169 CharacterHealth health_;
173 CharacterHealth pie_damage_;
176 motive::Motivator1f face_angle_;
179 mathfu::vec3 position_;
185 bool just_joined_game_;
191 uint64_t player_stats_[kMaxStats];
198 VictoryState victory_state_;
201 uint16_t state_last_update_;
210 const Character& target, WorldTime start_time,
211 WorldTime flight_time, CharacterHealth original_damage,
212 CharacterHealth damage,
float start_height,
float peak_height,
213 int rotations,
float y_rotation, motive::MotiveEngine* engine);
215 CharacterId original_source()
const {
return original_source_; }
216 CharacterId source()
const {
return source_; }
217 CharacterId target()
const {
return target_; }
218 WorldTime start_time()
const {
return start_time_; }
219 WorldTime flight_time()
const {
return flight_time_; }
220 CharacterHealth original_damage()
const {
return original_damage_; }
221 CharacterHealth damage()
const {
return damage_; }
222 const mathfu::mat4& Matrix()
const {
return motivator_.Value(); }
223 mathfu::vec3 Position()
const {
return motivator_.Position(); }
226 CharacterId original_source_;
229 WorldTime start_time_;
230 WorldTime flight_time_;
231 CharacterHealth original_damage_;
232 CharacterHealth damage_;
233 motive::MatrixMotivator4f motivator_;
239 inline int TimelineIndexAfterTime(
const T& arr,
const int start_index,
243 for (
int i = start_index; i < static_cast<int>(arr->Length()); ++i) {
244 if (arr->Get(i)->time() >= t)
return i;
246 return arr->Length();
252 inline int TimelineIndexBeforeTime(
const T& arr,
const WorldTime t) {
253 if (!arr || arr->Length() == 0)
return 0;
255 for (
int i = 1; i < static_cast<int>(arr->Length()); ++i) {
256 if (arr->Get(i)->time() > t)
return i - 1;
258 return arr->Length() - 1;
264 inline std::vector<int> TimelineIndicesWithTime(
const T& arr,
266 std::vector<int> ret;
267 if (!arr)
return ret;
269 for (
int i = 0; i < static_cast<int>(arr->Length()); ++i) {
270 const float end_time = arr->Get(i)->end_time();
271 if (arr->Get(i)->time() <= t && (t < end_time || end_time == 0.0f))
277 void ApplyScoringRule(
const ScoringRules* scoring_rules, ScoreEvent event,
278 unsigned int damage, Character* character);
283 #endif // PIE_NOON_CHARACTER_H_
Definition: character.h:55
Definition: character_state_machine.h:44
Definition: controller.h:26
Definition: character.h:207