Fix for the problem that SDL applications exited
[AROS-Contrib.git] / Games / lbreakout2 / client / player.c
blob302c40889f95e08fdc04c4a4de97888ee7f40dd8
1 /***************************************************************************
2 player.c - description
3 -------------------
4 begin : Thu Sep 6 2001
5 copyright : (C) 2001 by Michael Speck
6 email : kulkanie@gmx.net
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "../client/lbreakout.h"
19 #include "../game/levels.h"
20 #include "player.h"
22 int current_player = 0;
23 int player_count = 0;
24 Player players[MAX_PLAYERS];
27 ====================================================================
28 Add this player to the list and increase the counter until
29 MAX_PLAYERS is reached.
30 Return Value: True if successful
31 ====================================================================
33 int player_add( char *name, int lives, Level *level )
35 if ( player_count == MAX_PLAYERS ) return 0;
36 memset( &players[player_count], 0, sizeof( Player ) );
37 strcpy( players[player_count].name, name );
38 players[player_count].lives = lives;
39 player_init_level( &players[player_count], level, 0 );
40 player_count++;
41 return 1;
44 ====================================================================
45 Get first player.
46 Return Value: first player in list
47 ====================================================================
49 Player* players_get_first()
51 current_player = -1;
52 return players_get_next();
55 ====================================================================
56 Get next player in list (cycle: return first player after
57 last player).
58 Return Value: current player
59 ====================================================================
61 Player* players_get_next()
63 if ( players_count() == 0 ) return 0;
64 do {
65 current_player++;
66 if ( current_player == player_count ) current_player = 0;
68 while ( players[current_player].lives == 0 );
69 return &players[current_player];
72 ====================================================================
73 player_count players give id's 0,1,...,player_count-1. Select
74 the player with id 'current' as current player. The id used is
75 the absolute one, not the relative one resulting from dead players.
76 Return Value: current player
77 ====================================================================
79 Player* players_set_current( int current )
81 if ( current < 0 || current >= player_count ) return 0;
82 current_player = current;
83 return &players[current_player];
86 ====================================================================
87 Reset player counter.
88 ====================================================================
90 void players_clear()
92 player_count = 0;
95 ====================================================================
96 Return number of players still in game (lives > 0)
97 ====================================================================
99 int players_count()
101 int i;
102 int count = 0;
103 for ( i = 0; i < player_count; i++ )
104 if ( players[i].lives > 0 )
105 count++;
106 return count;
109 /* set level_id and init snapshot with the new leveldata */
110 void player_init_level( Player *player, Level *level, int id )
112 player->level_id = id;
113 player->snapshot = *level;