Blender V2.61 - r43446

DNA_boid_types.h

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