1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 by Janne Karhu.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_listBase.h"
27 
28 typedef enum eBoidRuleType {
29   eBoidRuleType_None = 0,
30   /** go to goal assigned object or loudest assigned signal source */
31   eBoidRuleType_Goal = 1,
32   /** get away from assigned object or loudest assigned signal source */
33   eBoidRuleType_Avoid = 2,
34   /** manoeuver to avoid collisions with other boids and deflector object in near future */
35   eBoidRuleType_AvoidCollision = 3,
36   /** keep from going through other boids */
37   eBoidRuleType_Separate = 4,
38   /** move to center of neighbors and match their velocity */
39   eBoidRuleType_Flock = 5,
40   /** follow a boid or assigned object */
41   eBoidRuleType_FollowLeader = 6,
42   /** maintain speed, flight level or wander*/
43   eBoidRuleType_AverageSpeed = 7,
44   /** go to closest enemy and attack when in range */
45   eBoidRuleType_Fight = 8,
46 #if 0
47   /** go to enemy closest to target and attack when in range */
48   eBoidRuleType_Protect = 9,
49   /** find a deflector move to its other side from closest enemy */
50   eBoidRuleType_Hide = 10,
51   /** move along a assigned curve or closest curve in a group */
52   eBoidRuleType_FollowPath = 11,
53   /** move next to a deflector object's in direction of its tangent */
54   eBoidRuleType_FollowWall = 12,
55 #endif
56 } eBoidRuleType;
57 
58 /* boidrule->flag */
59 #define BOIDRULE_CURRENT (1 << 0)
60 #define BOIDRULE_IN_AIR (1 << 2)
61 #define BOIDRULE_ON_LAND (1 << 3)
62 typedef struct BoidRule {
63   struct BoidRule *next, *prev;
64   int type, flag;
65   char name[32];
66 } BoidRule;
67 #define BRULE_GOAL_AVOID_PREDICT (1 << 0)
68 #define BRULE_GOAL_AVOID_ARRIVE (1 << 1)
69 #define BRULE_GOAL_AVOID_SIGNAL (1 << 2)
70 typedef struct BoidRuleGoalAvoid {
71   BoidRule rule;
72   struct Object *ob;
73   int options;
74   float fear_factor;
75 
76   /* signals */
77   int signal_id, channels;
78 } BoidRuleGoalAvoid;
79 #define BRULE_ACOLL_WITH_BOIDS (1 << 0)
80 #define BRULE_ACOLL_WITH_DEFLECTORS (1 << 1)
81 typedef struct BoidRuleAvoidCollision {
82   BoidRule rule;
83   int options;
84   float look_ahead;
85 } BoidRuleAvoidCollision;
86 #define BRULE_LEADER_IN_LINE (1 << 0)
87 typedef struct BoidRuleFollowLeader {
88   BoidRule rule;
89   struct Object *ob;
90   float loc[3], oloc[3];
91   float cfra, distance;
92   int options, queue_size;
93 } BoidRuleFollowLeader;
94 typedef struct BoidRuleAverageSpeed {
95   BoidRule rule;
96   float wander, level, speed, rt;
97 } BoidRuleAverageSpeed;
98 typedef struct BoidRuleFight {
99   BoidRule rule;
100   float distance, flee_distance;
101 } BoidRuleFight;
102 
103 typedef enum eBoidMode {
104   eBoidMode_InAir = 0,
105   eBoidMode_OnLand = 1,
106   eBoidMode_Climbing = 2,
107   eBoidMode_Falling = 3,
108   eBoidMode_Liftoff = 4,
109 } eBoidMode;
110 
111 typedef struct BoidData {
112   float health, acc[3];
113   short state_id, mode;
114 } BoidData;
115 
116 // planned for near future
117 // typedef enum BoidConditionMode {
118 //  eBoidConditionType_Then = 0,
119 //  eBoidConditionType_And = 1,
120 //  eBoidConditionType_Or = 2,
121 //  NUM_BOID_CONDITION_MODES
122 //} BoidConditionMode;
123 // typedef enum BoidConditionType {
124 //  eBoidConditionType_None = 0,
125 //  eBoidConditionType_Signal = 1,
126 //  eBoidConditionType_NoSignal = 2,
127 //  eBoidConditionType_HealthBelow = 3,
128 //  eBoidConditionType_HealthAbove = 4,
129 //  eBoidConditionType_See = 5,
130 //  eBoidConditionType_NotSee = 6,
131 //  eBoidConditionType_StateTime = 7,
132 //  eBoidConditionType_Touching = 8,
133 //  NUM_BOID_CONDITION_TYPES
134 //} BoidConditionType;
135 // typedef struct BoidCondition {
136 //  struct BoidCondition *next, *prev;
137 //  int state_id;
138 //  short type, mode;
139 //  float threshold, probability;
140 //
141 //  /* signals */
142 //  int signal_id, channels;
143 //} BoidCondition;
144 
145 typedef enum eBoidRulesetType {
146   eBoidRulesetType_Fuzzy = 0,
147   eBoidRulesetType_Random = 1,
148   eBoidRulesetType_Average = 2,
149 } eBoidRulesetType;
150 #define BOIDSTATE_CURRENT 1
151 typedef struct BoidState {
152   struct BoidState *next, *prev;
153   ListBase rules;
154   ListBase conditions;
155   ListBase actions;
156   char name[32];
157   int id, flag;
158 
159   /* rules */
160   int ruleset_type;
161   float rule_fuzziness;
162 
163   /* signal */
164   int signal_id, channels;
165   float volume, falloff;
166 } BoidState;
167 
168 // planned for near future
169 // typedef struct BoidSignal {
170 //  struct BoidSignal *next, *prev;
171 //  float loc[3];
172 //  float volume, falloff;
173 //  int id;
174 //} BoidSignal;
175 // typedef struct BoidSignalDefine {
176 //  struct BoidSignalDefine *next, *prev;
177 //  int id, rt;
178 //  char name[32];
179 //} BoidSignalDefine;
180 
181 // typedef struct BoidSimulationData {
182 //  ListBase signal_defines;/* list of defined signals */
183 //  ListBase signals[20];   /* gathers signals from all channels */
184 //  struct KDTree_3d *signaltrees[20];
185 //  char channel_names[20][32];
186 //  int last_signal_id;     /* used for incrementing signal ids */
187 //  int flag;               /* switches for drawing stuff */
188 //} BoidSimulationData;
189 
190 typedef struct BoidSettings {
191   int options, last_state_id;
192 
193   float landing_smoothness, height;
194   float banking, pitch;
195 
196   float health, aggression;
197   float strength, accuracy, range;
198 
199   /* flying related */
200   float air_min_speed, air_max_speed;
201   float air_max_acc, air_max_ave;
202   float air_personal_space;
203 
204   /* walk/run related */
205   float land_jump_speed, land_max_speed;
206   float land_max_acc, land_max_ave;
207   float land_personal_space;
208   float land_stick_force;
209 
210   struct ListBase states;
211 } BoidSettings;
212 
213 /* boidsettings->options */
214 #define BOID_ALLOW_FLIGHT (1 << 0)
215 #define BOID_ALLOW_LAND (1 << 1)
216 #define BOID_ALLOW_CLIMB (1 << 2)
217 
218 /* boidrule->options */
219 //#define BOID_RULE_FOLLOW_LINE     (1 << 0)        /* follow leader */
220 //#define BOID_RULE_PREDICT         (1 << 1)        /* goal/avoid */
221 //#define BOID_RULE_ARRIVAL         (1 << 2)        /* goal */
222 //#define BOID_RULE_LAND            (1 << 3)        /* goal */
223 //#define BOID_RULE_WITH_BOIDS      (1 << 4)        /* avoid collision */
224 //#define BOID_RULE_WITH_DEFLECTORS (1 << 5)    /* avoid collision */
225