Blender  V2.59
DNA_boid_types.h
Go to the documentation of this file.
00001 /* 
00002  * $Id: DNA_boid_types.h 34941 2011-02-17 20:48:12Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2009 by Janne Karhu.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00030 #ifndef DNA_BOID_TYPES_H
00031 #define DNA_BOID_TYPES_H
00032 
00037 #include "DNA_listBase.h"
00038 
00039 typedef enum BoidRuleType {
00040         eBoidRuleType_None = 0,
00041         eBoidRuleType_Goal,                             /* go to goal assigned object or loudest assigned signal source */
00042         eBoidRuleType_Avoid,                    /* get away from assigned object or loudest assigned signal source */
00043         eBoidRuleType_AvoidCollision,   /* manoeuver to avoid collisions with other boids and deflector object in near future */
00044         eBoidRuleType_Separate,                 /* keep from going through other boids */
00045         eBoidRuleType_Flock,                    /* move to center of neighbors and match their velocity */
00046         eBoidRuleType_FollowLeader,             /* follow a boid or assigned object */
00047         eBoidRuleType_AverageSpeed,             /* maintain speed, flight level or wander*/
00048         eBoidRuleType_Fight,                    /* go to closest enemy and attack when in range */
00049         //eBoidRuleType_Protect,                /* go to enemy closest to target and attack when in range */
00050         //eBoidRuleType_Hide,                   /* find a deflector move to it's other side from closest enemy */
00051         //eBoidRuleType_FollowPath,             /* move along a assigned curve or closest curve in a group */
00052         //eBoidRuleType_FollowWall,             /* move next to a deflector object's in direction of it's tangent */
00053         NUM_BOID_RULE_TYPES
00054 } BoidRuleType;
00055 
00056 /* boidrule->flag */
00057 #define BOIDRULE_CURRENT                1
00058 #define BOIDRULE_IN_AIR                 4
00059 #define BOIDRULE_ON_LAND                8
00060 typedef struct BoidRule {
00061         struct BoidRule *next, *prev;
00062         int type, flag;
00063         char name[32];
00064 } BoidRule;
00065 #define BRULE_GOAL_AVOID_PREDICT        1
00066 #define BRULE_GOAL_AVOID_ARRIVE         2
00067 #define BRULE_GOAL_AVOID_SIGNAL         4
00068 typedef struct BoidRuleGoalAvoid {
00069         BoidRule rule;
00070         struct Object *ob;
00071         int options;
00072         float fear_factor;      
00073 
00074         /* signals */
00075         int signal_id, channels;
00076 } BoidRuleGoalAvoid;
00077 #define BRULE_ACOLL_WITH_BOIDS          1
00078 #define BRULE_ACOLL_WITH_DEFLECTORS     2
00079 typedef struct BoidRuleAvoidCollision {
00080         BoidRule rule;
00081         int options;
00082         float look_ahead;
00083 } BoidRuleAvoidCollision;
00084 #define BRULE_LEADER_IN_LINE            1
00085 typedef struct BoidRuleFollowLeader {
00086         BoidRule rule;
00087         struct Object *ob;
00088         float loc[3], oloc[3];
00089         float cfra, distance;
00090         int options, queue_size;
00091 } BoidRuleFollowLeader;
00092 typedef struct BoidRuleAverageSpeed {
00093         BoidRule rule;
00094         float wander, level, speed, rt;
00095 } BoidRuleAverageSpeed;
00096 typedef struct BoidRuleFight {
00097         BoidRule rule;
00098         float distance, flee_distance;
00099 } BoidRuleFight;
00100 
00101 typedef enum BoidMode {
00102         eBoidMode_InAir = 0,
00103         eBoidMode_OnLand,
00104         eBoidMode_Climbing,
00105         eBoidMode_Falling,
00106         eBoidMode_Liftoff,
00107         NUM_BOID_MODES
00108 } BoidMode;
00109 
00110 
00111 typedef struct BoidData {
00112         float health, acc[3];
00113         short state_id, mode;
00114 } BoidData;
00115 
00116 // planned for near future
00117 //typedef enum BoidConditionMode {
00118 //      eBoidConditionType_Then = 0,
00119 //      eBoidConditionType_And,
00120 //      eBoidConditionType_Or,
00121 //      NUM_BOID_CONDITION_MODES
00122 //} BoidConditionMode;
00123 //typedef enum BoidConditionType {
00124 //      eBoidConditionType_None = 0,
00125 //      eBoidConditionType_Signal,
00126 //      eBoidConditionType_NoSignal,
00127 //      eBoidConditionType_HealthBelow,
00128 //      eBoidConditionType_HealthAbove,
00129 //      eBoidConditionType_See,
00130 //      eBoidConditionType_NotSee,
00131 //      eBoidConditionType_StateTime,
00132 //      eBoidConditionType_Touching,
00133 //      NUM_BOID_CONDITION_TYPES
00134 //} BoidConditionType;
00135 //typedef struct BoidCondition {
00136 //      struct BoidCondition *next, *prev;
00137 //      int state_id;
00138 //      short type, mode;
00139 //      float threshold, probability;
00140 //
00141 //      /* signals */
00142 //      int signal_id, channels;
00143 //} BoidCondition;
00144 
00145 typedef enum BoidRulesetType {
00146         eBoidRulesetType_Fuzzy = 0,
00147         eBoidRulesetType_Random,
00148         eBoidRulesetType_Average,
00149         NUM_BOID_RULESET_TYPES
00150 } BoidRulesetType;
00151 #define BOIDSTATE_CURRENT       1
00152 typedef struct BoidState {
00153         struct BoidState *next, *prev;
00154         ListBase rules;
00155         ListBase conditions;
00156         ListBase actions;
00157         char name[32];
00158         int id, flag;
00159         
00160         /* rules */
00161         int ruleset_type;
00162         float rule_fuzziness;
00163 
00164         /* signal */
00165         int signal_id, channels;
00166         float volume, falloff;
00167 } BoidState;
00168 
00169 // planned for near future
00170 //typedef struct BoidSignal {
00171 //      struct BoidSignal *next, *prev;
00172 //      float loc[3];
00173 //      float volume, falloff;
00174 //      int id;
00175 //} BoidSignal;
00176 //typedef struct BoidSignalDefine {
00177 //      struct BoidSignalDefine *next, *prev;
00178 //      int id, rt;
00179 //      char name[32];
00180 //} BoidSignalDefine;
00181 
00182 //typedef struct BoidSimulationData {
00183 //      ListBase signal_defines;/* list of defined signals */
00184 //      ListBase signals[20];   /* gathers signals from all channels */
00185 //      struct KDTree *signaltrees[20];
00186 //      char channel_names[20][32];
00187 //      int last_signal_id;             /* used for incrementing signal ids */
00188 //      int flag;                               /* switches for drawing stuff */
00189 //} BoidSimulationData;
00190 
00191 typedef struct BoidSettings {
00192         int options, last_state_id;
00193 
00194         float landing_smoothness, height;
00195         float banking, pitch;
00196 
00197         float health, aggression;
00198         float strength, accuracy, range;
00199 
00200         /* flying related */
00201         float air_min_speed, air_max_speed;
00202         float air_max_acc, air_max_ave;
00203         float air_personal_space;
00204 
00205         /* walk/run related */
00206         float land_jump_speed, land_max_speed;
00207         float land_max_acc, land_max_ave;
00208         float land_personal_space;
00209         float land_stick_force;
00210 
00211         struct ListBase states;
00212 } BoidSettings;
00213 
00214 /* boidsettings->options */
00215 #define BOID_ALLOW_FLIGHT       1
00216 #define BOID_ALLOW_LAND         2
00217 #define BOID_ALLOW_CLIMB        4
00218 
00219 /* boidrule->options */
00220 //#define BOID_RULE_FOLLOW_LINE 1               /* follow leader */
00221 //#define BOID_RULE_PREDICT             2               /* goal/avoid */
00222 //#define BOID_RULE_ARRIVAL             4               /* goal */
00223 //#define BOID_RULE_LAND                        8               /* goal */
00224 //#define BOID_RULE_WITH_BOIDS  16              /* avoid collision */
00225 //#define BOID_RULE_WITH_DEFLECTORS     32      /* avoid collision */
00226 
00227 #endif