added NeonFun Bot with UNO Game
[NeonServV5.git] / src / modules / NeonFun.mod / game_uno.h
1 /* game_uno.h - NeonServ v5.4
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17 #ifndef _game_uno_h
18 #define _game_uno_h
19 #include "../../timeq.h"
20
21 #define UNO_STATE_WAITING 1
22 #define UNO_STATE_RUNNING 2
23
24 #define UNO_COLOR_BLACK  0
25 #define UNO_COLOR_RED    1
26 #define UNO_COLOR_BLUE   2
27 #define UNO_COLOR_GREEN  3
28 #define UNO_COLOR_YELLOW 4
29
30 #define UNO_CARD_NUMBER_0  0
31 #define UNO_CARD_NUMBER_1  1
32 #define UNO_CARD_NUMBER_2  2
33 #define UNO_CARD_NUMBER_3  3
34 #define UNO_CARD_NUMBER_4  4
35 #define UNO_CARD_NUMBER_5  5
36 #define UNO_CARD_NUMBER_6  6
37 #define UNO_CARD_NUMBER_7  7
38 #define UNO_CARD_NUMBER_8  8
39 #define UNO_CARD_NUMBER_9  9
40 #define UNO_CARD_SKIP      10
41 #define UNO_CARD_DIRECTION 11
42 #define UNO_CARD_ADD_2     12
43 #define UNO_CARD_ADD_4     13
44 #define UNO_CARD_COLOR     14
45
46 #define UNO_IS_NUMBER_CARD(ccard) (ccard->card <= 9)
47
48 struct UserNode;
49 struct ChanNode;
50 struct ChanUser;
51 struct ClientSocket;
52 extern struct uno_game *uno_active_games;
53
54 struct uno_card {
55     unsigned char color;
56     unsigned char card;
57     struct uno_card *prev, *next;
58 };
59
60 struct uno_card_deck {
61     struct uno_card *cards;
62     int count;
63 };
64
65 struct uno_player {
66     struct ChanUser *chanuser;
67     struct uno_card *cards;
68     int count;
69     int timeout;
70     struct uno_player *prev, *next;
71 };
72
73 struct uno_game {
74     struct ChanNode *channel;
75     struct ClientSocket *textbot;
76     int state : 3;
77     int reverse_direction : 1;
78     int take_cards_pending : 1;
79     struct uno_card_deck *deck;
80     struct uno_card *top_card;
81     struct uno_player *player;
82     struct uno_player *winner;
83     struct uno_player *active_player;
84     int players;
85     
86     struct timeq_entry *timer;
87     struct uno_game *next;
88 };
89
90 struct uno_card_deck *uno_shuffle_deck();
91 struct uno_card *uno_get_card(struct uno_card_deck *deck);
92 void uno_free_deck(struct uno_card_deck *deck);
93 void uno_free_player(struct uno_player *player, struct uno_card_deck *deck);
94 void uno_free_topcard(struct uno_card *card);
95 void uno_free_game(struct uno_game *game);
96 struct uno_player *uno_get_next_player(struct uno_game *game);
97 void uno_show_player_cards(struct uno_game *game, struct uno_player *player);
98 void uno_show_top_card(struct uno_game *game);
99
100 TIMEQ_CALLBACK(uno_game_wait_timeout);
101 TIMEQ_CALLBACK(uno_player_timeout);
102
103 void uno_action_take_card(struct uno_game *game, struct uno_player *player);
104 struct uno_card *uno_parse_card(struct uno_game *game, struct uno_player *player, char *arg1);
105 int uno_check_card_valid(struct uno_game *game, struct uno_card *card);
106 void uno_play_card(struct uno_game *game, struct uno_player *player, struct uno_card *card);
107
108 void uno_event_part(struct ChanUser *chanuser);
109 void uno_event_quit(struct UserNode *user);
110 void uno_event_freechan(struct ChanNode *chan);
111
112 #endif