1 /* c_jovian_ai.hh 1.9 95/12/28 00:41:43 */
2 
3 
4 // xspacewarp by Greg Walker (gow@math.orst.edu)
5 
6 // This is free software. Non-profit redistribution and/or modification
7 // is allowed and welcome.
8 
9 
10 // parameters and inline functions to use for artificial intelligence
11 // routines.
12 
13 #ifndef _JOVIAN_AI_
14 #define _JOVIAN_AI_
15 
16 
17 #include <stdlib.h>		// rand()
18 #include "common.hh"
19 #include "params.hh"
20 #include "globals.hh"
21 
22 
23 // If the endever or a base being raided is in the same sector
24 // as a jovian, then the jovian moves or shoots (on average)
25 // every FASTFIGHT seconds in the highest skill level of game
26 // and every SLOWFIGHT seconds in lowest level of the
27 // game. Values for other skill levels are interpolated.
28 
29 #define FASTFIGHT  app_data.jovian_max_fight_frequency
30 #define SLOWFIGHT  app_data.jovian_min_fight_frequency
31 
32 
33 // When a sector contains a base but not the endever, there is a
34 // possibility of an attack or "raid" on the base. This constant
35 // is the average time in seconds before some jovian somewhere
36 // in the universe mounts a raid. FASTRAID is for the highest
37 // skill level, SLOWRAID is for the lowest skill level. Values
38 // for other skill levels are interpolated.
39 
40 #define FASTRAID  app_data.jovian_max_raid_frequency
41 #define SLOWRAID  app_data.jovian_min_raid_frequency
42 
43 
44 // If neither a base nor the endever is around, then this is the
45 // average number of seconds until some jovian somewhere in the
46 // universe leaps to a sector containing a base or the
47 // endever. FASTLEAP is for the highest skill level, SLOWLEAP is
48 // for the lowest skill level. Values for other skill levels are
49 // interpolated.
50 
51 #define FASTLEAP  app_data.jovian_max_leap_frequency
52 #define SLOWLEAP  app_data.jovian_min_leap_frequency
53 
54 
55 // Fit a cubic Lagrange interpolation polynomial through the following
56 // four points to determine whether to shoot the target.
57 //
58 // P0_Y = P(shoot target | squared dist to target is P0_X)
59 // P1_Y = P(shoot target | squared dist to target is P1_X)
60 // P2_Y = P(shoot target | squared dist to target is P2_X)
61 // P3_Y = P(shoot target | squared dist to target is P3_X)
62 
63 #define P0_X (float) 0
64 #define P0_Y (float) 0.5
65 #define P1_X (float) SECTDIAGSQ/4
66 #define P1_Y (float) 0.5
67 #define P2_X (float) SECTDIAGSQ/2
68 #define P2_Y (float) 0.5
69 #define P3_X (float) SECTDIAGSQ
70 #define P3_Y (float) 0.5
71 
72 
73 // parameters for determining whether a jovian will run away
74 // rather than fight. If the ion thruster energy is less than
75 // RETREAT_TRUST and the warpdrive energy is less than RETREAT_WARP
76 // and the faser energy is less than RETREAT_FASER and the shield
77 // energy is less than RETREAT_SHIELDS, then the jovian turns
78 // tail with probability RETREAT_PROB.
79 
80 #define RETREAT_THRUST  app_data.jovian_thrust_retreat_energy
81 #define RETREAT_WARP  app_data.jovian_warp_retreat_energy
82 #define RETREAT_FASER  app_data.jovian_faser_retreat_energy
83 #define RETREAT_SHIELD  app_data.jovian_shield_retreat_energy
84 #define RETREAT_PROB  app_data.jovian_retreat_probability
85 #define RETREAT_SPEED  app_data.jovian_retreat_speed // float. retreat rate
86 
87 
88 // If a Jovian fires at a target and its faser is blocked by a
89 // star or some other obstacle, then the "mustmove" flag is set.
90 // If the jov, the target and the obstacle lie along a vertical
91 // line and the "mustmove" flag is set, then the jov will need
92 // to move horizontally FORCEDHORIZ steps in some consistent
93 // horizontal direction to clear the obstacle. Similarly, if the
94 // jov, target and obstacle lie on a horizontal line and
95 // "mustmove" is set, then the jov will need to move FORCEDVERT
96 // steps in a consistent vertical direction to clear the
97 // target. At the very minimum, FORCEDHORIZ should be at least 3
98 // and FORCEDVERT should at least be 1. By making FORCEDHORIZ
99 // and FORCEDVERT larger than these minimums, it will be more
100 // likely that the jov will be able to fire its faser around the
101 // obstacle.
102 
103 #define FORCEDHORIZ  4
104 #define FORCEDVERT  2
105 
106 
107 // generate uniform random floats in [0, (RANDMAX-1)/RANDMAX]
108 
f_rand(void)109 inline float f_rand(void) {return ((float)(rand()%RANDMAX)/(float)RANDMAX);}
110 
111 // Given a time, (float) s, in seconds, time_to_prob() returns a
112 // float in [0,1] such that if a rand number, (float) r, is
113 // generated from 0 to 1 every JOVINT millisecs, then r <=
114 // time_to_prob(s) on average once every s seconds.
115 //
116 // Note JOVINT/1000 <= s <= JOVINT*RANDMAX/1000
117 // That is, once every JOVINT/1000 seconds is as frequent as
118 // an event can occur, and once every JOVINT*RANDMAX/1000
119 // seconds is the rarest an event can be.
120 
time_to_prob(float s)121 inline float time_to_prob(float s)
122 {return (max(min((float)JOVINT/(s*(float)1000), (float)1), (float)0));}
123 
124 
125 #endif             // _JOVIAN_AI_
126 
127 // end
128