]> git.jsancho.org Git - lugaru.git/blob - Source/Level/Awards.cpp
Update copyright year to 2017
[lugaru.git] / Source / Level / Awards.cpp
1 /*
2 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 Lugaru is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "Level/Awards.hpp"
21
22 #include "Game.hpp"
23 #include "Objects/Person.hpp"
24
25 int bonus;
26 int bonusvalue;
27 int bonustotal;
28 int startbonustotal;
29 float bonustime;
30 float bonusnum[100];
31
32 const char* bonus_names[bonus_count] = {
33 #define DECLARE_BONUS(id, name, ...) name,
34 #include "Bonuses.def"
35 #undef DECLARE_BONUS
36 };
37
38 const char* award_names[award_count] = {
39 #define DECLARE_AWARD(id, name) name,
40 #include "Awards.def"
41 #undef DECLARE_AWARD
42 };
43
44 static const int bonus_values[bonus_count] = {
45 #define DECLARE_BONUS(id, name, value) value,
46 #include "Bonuses.def"
47 #undef DECLARE_BONUS
48 };
49
50 void award_bonus(int playerid, int bonusid, int alt_value)
51 {
52     if (playerid != 0) {
53         return;
54     }
55     bonus = bonusid;
56     bonustime = 0;
57     bonusvalue = alt_value ? alt_value : bonus_values[bonusid];
58 }
59
60 // FIXME: make these per-player
61 float damagetaken;
62 int numfalls;
63 int numflipfail;
64 int numseen;
65 int numresponded;
66 int numstaffattack;
67 int numswordattack;
68 int numknifeattack;
69 int numunarmedattack;
70 int numescaped;
71 int numflipped;
72 int numwallflipped;
73 int numthrowkill;
74 int numafterkill;
75 int numreversals;
76 int numattacks;
77 int maxalarmed;
78
79 int award_awards(int* awards)
80 {
81     int numawards = 0;
82     if (damagetaken == 0 && Person::players[0]->bloodloss == 0) {
83         awards[numawards] = awardflawless;
84         numawards++;
85     }
86     bool alldead = true;
87     for (unsigned i = 1; i < Person::players.size(); i++) {
88         if (Person::players[i]->dead != 2) {
89             alldead = 0;
90         }
91     }
92     if (alldead) {
93         awards[numawards] = awardalldead;
94         numawards++;
95     }
96     alldead = 1;
97     for (unsigned i = 1; i < Person::players.size(); i++) {
98         if (Person::players[i]->dead != 1) {
99             alldead = 0;
100         }
101     }
102     if (alldead) {
103         awards[numawards] = awardnodead;
104         numawards++;
105     }
106     if (numresponded == 0 && !numthrowkill) {
107         awards[numawards] = awardstealth;
108         numawards++;
109     }
110     if (numattacks == numstaffattack && numattacks > 0) {
111         awards[numawards] = awardbojutsu;
112         numawards++;
113     }
114     if (numattacks == numswordattack && numattacks > 0) {
115         awards[numawards] = awardswordsman;
116         numawards++;
117     }
118     if (numattacks == numknifeattack && numattacks > 0) {
119         awards[numawards] = awardknifefighter;
120         numawards++;
121     }
122     if (numattacks == numunarmedattack && numthrowkill == 0 && weapons.size() > 0) {
123         awards[numawards] = awardkungfu;
124         numawards++;
125     }
126     if (numescaped > 0) {
127         awards[numawards] = awardevasion;
128         numawards++;
129     }
130     if (numflipfail == 0 && numflipped + numwallflipped * 2 > 20) {
131         awards[numawards] = awardacrobat;
132         numawards++;
133     }
134     if (numthrowkill == (int(Person::players.size()) - 1)) {
135         awards[numawards] = awardlongrange;
136         numawards++;
137     }
138     alldead = 1;
139     for (unsigned i = 1; i < Person::players.size(); i++) {
140         if (Person::players[i]->dead != 2) {
141             alldead = 0;
142         }
143     }
144     if (numafterkill > 0 && alldead) {
145         awards[numawards] = awardbrutal;
146         numawards++;
147     }
148     if (numreversals > ((float)numattacks) * .8 && numreversals > 3) {
149         awards[numawards] = awardaikido;
150         numawards++;
151     }
152     if (maxalarmed == 1 && Person::players.size() > 2) {
153         awards[numawards] = awardstrategy;
154         numawards++;
155     }
156     if (numflipfail > 3) {
157         awards[numawards] = awardklutz;
158         numawards++;
159     }
160     return numawards;
161 }