1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "player.h"
20
21 Player player[2];
22
calc_purple_balls_needed(Player * this_player)23 void calc_purple_balls_needed( Player *this_player )
24 {
25 static const uint purple_balls_required[12] = { 1, 1, 2, 4, 8, 12, 16, 20, 25, 30, 40, 50 };
26
27 this_player->purple_balls_needed = purple_balls_required[*this_player->lives];
28 }
29
power_up_weapon(Player * this_player,uint port)30 bool power_up_weapon( Player *this_player, uint port )
31 {
32 const bool can_power_up = this_player->items.weapon[port].id != 0 && // not None
33 this_player->items.weapon[port].power < 11; // not at max power
34 if (can_power_up)
35 {
36 ++this_player->items.weapon[port].power;
37 shotMultiPos[port] = 0; // TODO: should be part of Player structure
38
39 calc_purple_balls_needed(this_player);
40 }
41 else // cash consolation prize
42 {
43 this_player->cash += 1000;
44 }
45
46 return can_power_up;
47 }
48
handle_got_purple_ball(Player * this_player)49 void handle_got_purple_ball( Player *this_player )
50 {
51 if (this_player->purple_balls_needed > 1)
52 --this_player->purple_balls_needed;
53 else
54 power_up_weapon(this_player, this_player->is_dragonwing ? REAR_WEAPON : FRONT_WEAPON);
55 }
56