1 /*
2  * XPilot NG, a multiplayer space war game.
3  *
4  * Copyright (C) 1991-2001 by
5  *
6  *      Bj�rn Stabell        <bjoern@xpilot.org>
7  *      Ken Ronny Schouten   <ken@xpilot.org>
8  *      Bert Gijsbers        <bert@xpilot.org>
9  *      Dick Balaska         <dick@xpilot.org>
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  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25 
26 /* Robot code originally submitted by Maurice Abraham. */
27 
28 #ifndef ROBOT_H
29 #define ROBOT_H
30 
31 #ifndef MAP_H
32 # include "map.h"
33 #endif
34 
35 /*
36  * We would like to support several different robot types.
37  * Each robot type is defined by one name and is accessed
38  * by several functions or methods.
39  * The name is used to enable configuration files to
40  * specify which robot type to use for which robot name.
41  * The functions are:
42  *
43  *    1) The global initialization function for this specific robot type.
44  *       It is called once at startup to initialise a structure with
45  *       function pointers to the robot type action routines.
46  *
47  *    2) The next round function, which is called only once per round
48  *       to allow the robot type adjust type generic parameters.
49  *
50  *    3) The initialization function to enable robot type
51  *       specific adjustments and possible memory allocation
52  *       of private data structures for one specific robot instance.
53  *       This function will be called with an extra string argument.
54  *       The string argument may contain robot type specific
55  *       configuration data, like attack and defend mode.
56  *       Each robot type is free to define the format
57  *       for this string as it sees fit.  But when this string
58  *       is empty the robot type initialization code will
59  *       have to provide suitable default configuration values.
60  *
61  *    4) The go home function which is called whenever the robot
62  *       is placed at its homebase.
63  *
64  *    5) The playing function which gets called each loop.
65  *       The programming challenge here is to implement
66  *       different characters per robot, while at the
67  *       same time not calculating 'everything' every
68  *       time this function is called.  i.e., try to give
69  *       the robot some long term goals which are only
70  *       recalculated once every couple of seconds or so.
71  *
72  *    6) The war function which is called when the robot declares war.
73  *       This function takes an extra killer argument, which is
74  *       the player id of the player the robot has declared war against.
75  *       If this id equals NO_ID then the routine should reset the war state.
76  *
77  *    7) The war_on_player function returns the id of the player
78  *       who the robot is in a state of war with.
79  *       If the robot is not in war with another player
80  *       then this function should return NO_ID.
81  *
82  *    8) The message function can accept any possible commands to the robot.
83  *       The suggestion here is that if you plan to let the robot type
84  *       be controllable by messages that you give feedback to all
85  *       of the players what commands the robot has accepted.
86  *
87  *    9) The cleanup function should free any allocated resources
88  *       for this specific robot instance.
89  *
90  * The recommended practice is to define your new robot types
91  * in a separate file and to only declare your robot type
92  * specific initialisation function prototype in robot.c and add one
93  * function pointer to the robot_type_setups array.
94  */
95 typedef struct {
96     const char		*name;
97     void		(*robot_round_tick)(void);
98     void		(*robot_create)(player_t *robot, char *str);
99     void		(*robot_go_home)(player_t *robot);
100     void		(*robot_play)(player_t *robot);
101     void		(*robot_set_war)(player_t *victim, int killer);
102     int			(*robot_war_on_player)(player_t *robot);
103     void		(*robot_message)(player_t *robot, const char *str);
104     void		(*robot_destroy)(player_t *robot);
105     void		(*robot_invite)(player_t *robot, player_t *inviter);
106 } robot_type_t;
107 
108 /*
109  * Different talk commands.
110  * The talk code is done by the robot manager,
111  * not by the robot type implementation.
112  */
113 enum robot_talk_t {
114     ROBOT_TALK_ENTER,
115     ROBOT_TALK_LEAVE,
116     ROBOT_TALK_KILL,
117     ROBOT_TALK_WAR,
118     NUM_ROBOT_TALK_TYPES
119 };
120 
121 /*
122  * Configuration data for each robot available.
123  */
124 typedef struct {
125     char	driver[MAX_NAME_LEN];	/* Which code controls robot? */
126     char	name[MAX_NAME_LEN];	/* Name of this robot. */
127     char	config[MAX_CHARS];	/* Attack + defense ~ 100 */
128     unsigned	used;			/* How often has this robot been used */
129     char	shape[2*MSG_LEN];	/* shipshape string definition */
130 } robot_t;
131 
132 /*
133  * Robot manager data for each robot instance.
134  */
135 typedef struct robot_data {
136     int		robots_ind;		/* index into Robots[] */
137     int		robot_types_ind;	/* index into robot_types[] */
138     void	*private_data;		/* robot type private data */
139 } robot_data_t;
140 
141 /*
142  * The private robot instance data for the default robot.
143  */
144 typedef struct robot_default_data {
145     int		robot_lock;		/* lock mode */
146     int		robot_lock_id;		/* target player if in war mode */
147     int		robot_mode;		/* ultrashort term mode of robot. */
148     int		robot_count;		/* Misc timings, minimizes rand use */
149     int		attack;			/* how aggressive (1-99) */
150     int		defense;		/* how defensive (1-99) */
151     double	robot_normal_speed;
152     double	robot_attack_speed;
153     double	robot_max_speed;
154     int		last_dropped_mine;      /* relative to robot_count */
155     int		last_fired_missile;     /* relative to robot_count */
156     int		last_thrown_ball;	/* relative to robot_count */
157     int		longterm_mode;		/* long term robot mode */
158     double	fuel_l1;		/* Fuel critical level */
159     double	fuel_l2;		/* Fuel warning level */
160     double	fuel_l3;		/* Fuel notify level */
161 } robot_default_data_t;
162 
163 /*
164  * The private robot instance data for the simple ng robot.
165  */
166 typedef struct robot_suibot_data {
167     int         robot_lock;             /* lock mode */
168     int         robot_lock_id;          /* target player if in war mode */
169     int         robot_mode;             /* ultrashort term mode of robot. */
170     int         robot_count;            /* Misc timings, minimizes rand use */
171     int         attack;                 /* how aggressive (1-99) */
172     int         defense;                /* how defensive (1-99) */
173     int         longterm_mode;          /* long term robot mode */
174     double      fuel_l1;                /* Fuel critical level */
175     double      fuel_l2;                /* Fuel warning level */
176     int last_attacked_player; /* relative to robot_count */
177 } robot_suibot_data_t;
178 
179 
180 /*
181  * Prototypes for robot.c
182  */
183 void Parse_robot_file(void);
184 void Robot_init(void);
185 void Robot_delete(player_t *robot, bool kicked);
186 void Robot_destroy(player_t *robot);
187 void Robot_update(bool tick);
188 void Robot_invite(player_t *robot, player_t *inviter);
189 void Robot_war(player_t *robot, player_t *killer);
190 void Robot_reset_war(player_t *robot);
191 int Robot_war_on_player(player_t *robot);
192 void Robot_go_home(player_t *robot);
193 void Robot_program(player_t *robot, int victim_id);
194 void Robot_message(player_t *robot, const char *message);
195 
196 #endif
197