Blender  V2.59
rna_boid.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_boid.c 36095 2011-04-11 01:18:25Z campbellbarton $
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 
00035 #include <float.h>
00036 #include <limits.h>
00037 #include <stdlib.h>
00038 
00039 #include "RNA_define.h"
00040 
00041 #include "rna_internal.h"
00042 
00043 #include "DNA_scene_types.h"
00044 #include "DNA_boid_types.h"
00045 #include "DNA_object_types.h"
00046 #include "DNA_particle_types.h"
00047 
00048 #include "WM_api.h"
00049 #include "WM_types.h"
00050 
00051 EnumPropertyItem boidrule_type_items[] ={
00052         {eBoidRuleType_Goal, "GOAL", 0, "Goal", "Go to assigned object or loudest assigned signal source"},
00053         {eBoidRuleType_Avoid, "AVOID", 0, "Avoid", "Get away from assigned object or loudest assigned signal source"},
00054         {eBoidRuleType_AvoidCollision, "AVOID_COLLISION", 0, "Avoid Collision", "Manoeuvre to avoid collisions with other boids and deflector objects in near future"},
00055         {eBoidRuleType_Separate, "SEPARATE", 0, "Separate", "Keep from going through other boids"},
00056         {eBoidRuleType_Flock, "FLOCK", 0, "Flock", "Move to center of neighbors and match their velocity"},
00057         {eBoidRuleType_FollowLeader, "FOLLOW_LEADER", 0, "Follow Leader", "Follow a boid or assigned object"},
00058         {eBoidRuleType_AverageSpeed, "AVERAGE_SPEED", 0, "Average Speed", "Maintain speed, flight level or wander"},
00059         {eBoidRuleType_Fight, "FIGHT", 0, "Fight", "Go to closest enemy and attack when in range"},
00060         //{eBoidRuleType_Protect, "PROTECT", 0, "Protect", "Go to enemy closest to target and attack when in range"},
00061         //{eBoidRuleType_Hide, "HIDE", 0, "Hide", "Find a deflector move to it's other side from closest enemy"},
00062         //{eBoidRuleType_FollowPath, "FOLLOW_PATH", 0, "Follow Path", "Move along a assigned curve or closest curve in a group"},
00063         //{eBoidRuleType_FollowWall, "FOLLOW_WALL", 0, "Follow Wall", "Move next to a deflector object's in direction of it's tangent"},
00064         {0, NULL, 0, NULL, NULL}};
00065 
00066 EnumPropertyItem boidruleset_type_items[] ={
00067         {eBoidRulesetType_Fuzzy, "FUZZY", 0, "Fuzzy", "Rules are gone through top to bottom. Only the first rule that effect above fuzziness threshold is evaluated"},
00068         {eBoidRulesetType_Random, "RANDOM", 0, "Random", "A random rule is selected for each boid"},
00069         {eBoidRulesetType_Average, "AVERAGE", 0, "Average", "All rules are averaged"},
00070         {0, NULL, 0, NULL, NULL}};
00071 
00072 
00073 #ifdef RNA_RUNTIME
00074 
00075 #include "BKE_context.h"
00076 #include "BKE_depsgraph.h"
00077 #include "BKE_particle.h"
00078 
00079 static void rna_Boids_reset(Main *bmain, Scene *scene, PointerRNA *ptr)
00080 {
00081         if(ptr->type==&RNA_ParticleSystem) {
00082                 ParticleSystem *psys = (ParticleSystem*)ptr->data;
00083                 
00084                 psys->recalc = PSYS_RECALC_RESET;
00085 
00086                 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
00087         }
00088         else
00089                 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA|PSYS_RECALC_RESET);
00090 
00091         WM_main_add_notifier(NC_OBJECT|ND_PARTICLE|NA_EDITED, NULL);
00092 }
00093 static void rna_Boids_reset_deps(Main *bmain, Scene *scene, PointerRNA *ptr)
00094 {
00095         if(ptr->type==&RNA_ParticleSystem) {
00096                 ParticleSystem *psys = (ParticleSystem*)ptr->data;
00097                 
00098                 psys->recalc = PSYS_RECALC_RESET;
00099 
00100                 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
00101         }
00102         else
00103                 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA|PSYS_RECALC_RESET);
00104 
00105         DAG_scene_sort(bmain, scene);
00106 
00107         WM_main_add_notifier(NC_OBJECT|ND_PARTICLE|NA_EDITED, NULL);
00108 }
00109 
00110 static StructRNA* rna_BoidRule_refine(struct PointerRNA *ptr)
00111 {
00112         BoidRule *rule= (BoidRule*)ptr->data;
00113 
00114         switch(rule->type) {
00115                 case eBoidRuleType_Goal:
00116                         return &RNA_BoidRuleGoal;
00117                 case eBoidRuleType_Avoid:
00118                         return &RNA_BoidRuleAvoid;
00119                 case eBoidRuleType_AvoidCollision:
00120                         return &RNA_BoidRuleAvoidCollision;
00121                 case eBoidRuleType_FollowLeader:
00122                         return &RNA_BoidRuleFollowLeader;
00123                 case eBoidRuleType_AverageSpeed:
00124                         return &RNA_BoidRuleAverageSpeed;
00125                 case eBoidRuleType_Fight:
00126                         return &RNA_BoidRuleFight;
00127                 default:
00128                         return &RNA_BoidRule;
00129         }
00130 }
00131 
00132 static char *rna_BoidRule_path(PointerRNA *ptr)
00133 {
00134         return BLI_sprintfN("rules[\"%s\"]", ((BoidRule*)ptr->data)->name);  // XXX not unique
00135 }
00136 
00137 static PointerRNA rna_BoidState_active_boid_rule_get(PointerRNA *ptr)
00138 {
00139         BoidState *state= (BoidState*)ptr->data;
00140         BoidRule *rule = (BoidRule*)state->rules.first;
00141 
00142         for(; rule; rule=rule->next) {
00143                 if(rule->flag & BOIDRULE_CURRENT)
00144                         return rna_pointer_inherit_refine(ptr, &RNA_BoidRule, rule);
00145         }
00146         return rna_pointer_inherit_refine(ptr, &RNA_BoidRule, NULL);
00147 }
00148 static void rna_BoidState_active_boid_rule_index_range(PointerRNA *ptr, int *min, int *max)
00149 {
00150         BoidState *state= (BoidState*)ptr->data;
00151         *min= 0;
00152         *max= BLI_countlist(&state->rules)-1;
00153         *max= MAX2(0, *max);
00154 }
00155 
00156 static int rna_BoidState_active_boid_rule_index_get(PointerRNA *ptr)
00157 {
00158         BoidState *state= (BoidState*)ptr->data;
00159         BoidRule *rule = (BoidRule*)state->rules.first;
00160         int i=0;
00161 
00162         for(; rule; rule=rule->next, i++) {
00163                 if(rule->flag & BOIDRULE_CURRENT)
00164                         return i;
00165         }
00166         return 0;
00167 }
00168 
00169 static void rna_BoidState_active_boid_rule_index_set(struct PointerRNA *ptr, int value)
00170 {
00171         BoidState *state= (BoidState*)ptr->data;
00172         BoidRule *rule = (BoidRule*)state->rules.first;
00173         int i=0;
00174 
00175         for(; rule; rule=rule->next, i++) {
00176                 if(i==value)
00177                         rule->flag |= BOIDRULE_CURRENT;
00178                 else
00179                         rule->flag &= ~BOIDRULE_CURRENT;
00180         }
00181 }
00182 
00183 static int particle_id_check(PointerRNA *ptr)
00184 {
00185         ID *id= ptr->id.data;
00186 
00187         return (GS(id->name) == ID_PA);
00188 }
00189 
00190 static char *rna_BoidSettings_path(PointerRNA *ptr)
00191 {
00192         BoidSettings *boids = (BoidSettings *)ptr->data;
00193         
00194         if(particle_id_check(ptr)) {
00195                 ParticleSettings *part = (ParticleSettings*)ptr->id.data;
00196                 
00197                 if (part->boids == boids)
00198                         return BLI_sprintfN("boids");
00199         }
00200         return NULL;
00201 }
00202 
00203 static PointerRNA rna_BoidSettings_active_boid_state_get(PointerRNA *ptr)
00204 {
00205         BoidSettings *boids= (BoidSettings*)ptr->data;
00206         BoidState *state = (BoidState*)boids->states.first;
00207 
00208         for(; state; state=state->next) {
00209                 if(state->flag & BOIDSTATE_CURRENT)
00210                         return rna_pointer_inherit_refine(ptr, &RNA_BoidState, state);
00211         }
00212         return rna_pointer_inherit_refine(ptr, &RNA_BoidState, NULL);
00213 }
00214 static void rna_BoidSettings_active_boid_state_index_range(PointerRNA *ptr, int *min, int *max)
00215 {
00216         BoidSettings *boids= (BoidSettings*)ptr->data;
00217         *min= 0;
00218         *max= BLI_countlist(&boids->states)-1;
00219         *max= MAX2(0, *max);
00220 }
00221 
00222 static int rna_BoidSettings_active_boid_state_index_get(PointerRNA *ptr)
00223 {
00224         BoidSettings *boids= (BoidSettings*)ptr->data;
00225         BoidState *state = (BoidState*)boids->states.first;
00226         int i=0;
00227 
00228         for(; state; state=state->next, i++) {
00229                 if(state->flag & BOIDSTATE_CURRENT)
00230                         return i;
00231         }
00232         return 0;
00233 }
00234 
00235 static void rna_BoidSettings_active_boid_state_index_set(struct PointerRNA *ptr, int value)
00236 {
00237         BoidSettings *boids= (BoidSettings*)ptr->data;
00238         BoidState *state = (BoidState*)boids->states.first;
00239         int i=0;
00240 
00241         for(; state; state=state->next, i++) {
00242                 if(i==value)
00243                         state->flag |= BOIDSTATE_CURRENT;
00244                 else
00245                         state->flag &= ~BOIDSTATE_CURRENT;
00246         }
00247 }
00248 
00249 #else
00250 
00251 static void rna_def_boidrule_goal(BlenderRNA *brna)
00252 {
00253         StructRNA *srna;
00254         PropertyRNA *prop;
00255 
00256         srna= RNA_def_struct(brna, "BoidRuleGoal", "BoidRule");
00257         RNA_def_struct_ui_text(srna, "Goal", "");
00258         RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid");
00259 
00260         prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
00261         RNA_def_property_pointer_sdna(prop, NULL, "ob");
00262         RNA_def_property_flag(prop, PROP_EDITABLE);
00263         RNA_def_property_ui_text(prop, "Object", "Goal object");
00264         RNA_def_property_update(prop, 0, "rna_Boids_reset_deps");
00265 
00266         prop= RNA_def_property(srna, "use_predict", PROP_BOOLEAN, PROP_NONE);
00267         RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_GOAL_AVOID_PREDICT);
00268         RNA_def_property_ui_text(prop, "Predict", "Predict target movement");
00269         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00270 }
00271 
00272 static void rna_def_boidrule_avoid(BlenderRNA *brna)
00273 {
00274         StructRNA *srna;
00275         PropertyRNA *prop;
00276 
00277         srna= RNA_def_struct(brna, "BoidRuleAvoid", "BoidRule");
00278         RNA_def_struct_ui_text(srna, "Avoid", "");
00279         RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid");
00280 
00281         prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
00282         RNA_def_property_pointer_sdna(prop, NULL, "ob");
00283         RNA_def_property_flag(prop, PROP_EDITABLE);
00284         RNA_def_property_ui_text(prop, "Object", "Object to avoid");
00285         RNA_def_property_update(prop, 0, "rna_Boids_reset_deps");
00286 
00287         prop= RNA_def_property(srna, "use_predict", PROP_BOOLEAN, PROP_NONE);
00288         RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_GOAL_AVOID_PREDICT);
00289         RNA_def_property_ui_text(prop, "Predict", "Predict target movement");
00290         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00291 
00292         prop= RNA_def_property(srna, "fear_factor", PROP_FLOAT, PROP_NONE);
00293         RNA_def_property_range(prop, 0.0f, 100.0f);
00294         RNA_def_property_ui_text(prop, "Fear factor", "Avoid object if danger from it is above this threshold");
00295         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00296 }
00297 
00298 static void rna_def_boidrule_avoid_collision(BlenderRNA *brna)
00299 {
00300         StructRNA *srna;
00301         PropertyRNA *prop;
00302 
00303         srna= RNA_def_struct(brna, "BoidRuleAvoidCollision", "BoidRule");
00304         RNA_def_struct_ui_text(srna, "Avoid Collision", "");
00305 
00306         prop= RNA_def_property(srna, "use_avoid", PROP_BOOLEAN, PROP_NONE);
00307         RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_ACOLL_WITH_BOIDS);
00308         RNA_def_property_ui_text(prop, "Boids", "Avoid collision with other boids");
00309         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00310 
00311         prop= RNA_def_property(srna, "use_avoid_collision", PROP_BOOLEAN, PROP_NONE);
00312         RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_ACOLL_WITH_DEFLECTORS);
00313         RNA_def_property_ui_text(prop, "Deflectors", "Avoid collision with deflector objects");
00314         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00315 
00316         prop= RNA_def_property(srna, "look_ahead", PROP_FLOAT, PROP_NONE);
00317         RNA_def_property_range(prop, 0.0f, 100.0f);
00318         RNA_def_property_ui_text(prop, "Look ahead", "Time to look ahead in seconds");
00319         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00320 }
00321 
00322 static void rna_def_boidrule_follow_leader(BlenderRNA *brna)
00323 {
00324         StructRNA *srna;
00325         PropertyRNA *prop;
00326 
00327         srna= RNA_def_struct(brna, "BoidRuleFollowLeader", "BoidRule");
00328         RNA_def_struct_ui_text(srna, "Follow Leader", "");
00329 
00330         prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
00331         RNA_def_property_pointer_sdna(prop, NULL, "ob");
00332         RNA_def_property_flag(prop, PROP_EDITABLE);
00333         RNA_def_property_ui_text(prop, "Object", "Follow this object instead of a boid");
00334         RNA_def_property_update(prop, 0, "rna_Boids_reset_deps");
00335 
00336         prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
00337         RNA_def_property_range(prop, 0.0f, 100.0f);
00338         RNA_def_property_ui_text(prop, "Distance", "Distance behind leader to follow");
00339         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00340 
00341         prop= RNA_def_property(srna, "queue_count", PROP_INT, PROP_NONE);
00342         RNA_def_property_int_sdna(prop, NULL, "queue_size");
00343         RNA_def_property_range(prop, 0.0f, 100.0f);
00344         RNA_def_property_ui_text(prop, "Queue Size", "How many boids in a line");
00345         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00346 
00347         prop= RNA_def_property(srna, "use_line", PROP_BOOLEAN, PROP_NONE);
00348         RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_LEADER_IN_LINE);
00349         RNA_def_property_ui_text(prop, "Line", "Follow leader in a line");
00350         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00351 }
00352 
00353 static void rna_def_boidrule_average_speed(BlenderRNA *brna)
00354 {
00355         StructRNA *srna;
00356         PropertyRNA *prop;
00357 
00358         srna= RNA_def_struct(brna, "BoidRuleAverageSpeed", "BoidRule");
00359         RNA_def_struct_ui_text(srna, "Average Speed", "");
00360 
00361         prop= RNA_def_property(srna, "wander", PROP_FLOAT, PROP_NONE);
00362         RNA_def_property_range(prop, 0.0f, 1.0f);
00363         RNA_def_property_ui_text(prop, "Wander", "How fast velocity's direction is randomized");
00364         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00365 
00366         prop= RNA_def_property(srna, "level", PROP_FLOAT, PROP_NONE);
00367         RNA_def_property_range(prop, 0.0f, 1.0f);
00368         RNA_def_property_ui_text(prop, "Level", "How much velocity's z-component is kept constant");
00369         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00370 
00371         prop= RNA_def_property(srna, "speed", PROP_FLOAT, PROP_NONE);
00372         RNA_def_property_range(prop, 0.0f, 1.0f);
00373         RNA_def_property_ui_text(prop, "Speed", "Percentage of maximum speed");
00374         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00375 }
00376 
00377 static void rna_def_boidrule_fight(BlenderRNA *brna)
00378 {
00379         StructRNA *srna;
00380         PropertyRNA *prop;
00381 
00382         srna= RNA_def_struct(brna, "BoidRuleFight", "BoidRule");
00383         RNA_def_struct_ui_text(srna, "Fight", "");
00384 
00385         prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
00386         RNA_def_property_range(prop, 0.0f, 100.0f);
00387         RNA_def_property_ui_text(prop, "Fight Distance", "Attack boids at max this distance");
00388         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00389 
00390         prop= RNA_def_property(srna, "flee_distance", PROP_FLOAT, PROP_NONE);
00391         RNA_def_property_range(prop, 0.0f, 100.0f);
00392         RNA_def_property_ui_text(prop, "Flee Distance", "Flee to this distance");
00393         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00394 }
00395 
00396 static void rna_def_boidrule(BlenderRNA *brna)
00397 {
00398         StructRNA *srna;
00399         PropertyRNA *prop;
00400         
00401         /* data */
00402         srna= RNA_def_struct(brna, "BoidRule", NULL);
00403         RNA_def_struct_ui_text(srna , "Boid Rule", "");
00404         RNA_def_struct_refine_func(srna, "rna_BoidRule_refine");
00405         RNA_def_struct_path_func(srna, "rna_BoidRule_path");
00406         
00407         /* strings */
00408         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00409         RNA_def_property_ui_text(prop, "Name", "Boid rule name");
00410         RNA_def_struct_name_property(srna, prop);
00411         
00412         /* enums */
00413         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00414         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00415         RNA_def_property_enum_sdna(prop, NULL, "type");
00416         RNA_def_property_enum_items(prop, boidrule_type_items);
00417         RNA_def_property_ui_text(prop, "Type", "");
00418         
00419         /* flags */
00420         prop= RNA_def_property(srna, "use_in_air", PROP_BOOLEAN, PROP_NONE);
00421         RNA_def_property_boolean_sdna(prop, NULL, "flag", BOIDRULE_IN_AIR);
00422         RNA_def_property_ui_text(prop, "In Air", "Use rule when boid is flying");
00423         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00424         
00425         prop= RNA_def_property(srna, "use_on_land", PROP_BOOLEAN, PROP_NONE);
00426         RNA_def_property_boolean_sdna(prop, NULL, "flag", BOIDRULE_ON_LAND);
00427         RNA_def_property_ui_text(prop, "On Land", "Use rule when boid is on land");
00428         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00429         
00430         //prop= RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
00431         //RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Expanded);
00432         //RNA_def_property_ui_text(prop, "Expanded", "Set modifier expanded in the user interface");
00433 
00434         /* types */
00435         rna_def_boidrule_goal(brna);
00436         rna_def_boidrule_avoid(brna);
00437         rna_def_boidrule_avoid_collision(brna);
00438         rna_def_boidrule_follow_leader(brna);
00439         rna_def_boidrule_average_speed(brna);
00440         rna_def_boidrule_fight(brna);
00441 }
00442 
00443 static void rna_def_boidstate(BlenderRNA *brna)
00444 {
00445         StructRNA *srna;
00446         PropertyRNA *prop;
00447 
00448         srna = RNA_def_struct(brna, "BoidState", NULL);
00449         RNA_def_struct_ui_text(srna, "Boid State", "Boid state for boid physics");
00450 
00451         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00452         RNA_def_property_ui_text(prop, "Name", "Boid state name");
00453         RNA_def_struct_name_property(srna, prop);
00454 
00455         prop= RNA_def_property(srna, "ruleset_type", PROP_ENUM, PROP_NONE);
00456         RNA_def_property_enum_items(prop, boidruleset_type_items);
00457         RNA_def_property_ui_text(prop, "Rule Evaluation", "How the rules in the list are evaluated");
00458 
00459         prop= RNA_def_property(srna, "rules", PROP_COLLECTION, PROP_NONE);
00460         RNA_def_property_struct_type(prop, "BoidRule");
00461         RNA_def_property_ui_text(prop, "Boid Rules", "");
00462 
00463         prop= RNA_def_property(srna, "active_boid_rule", PROP_POINTER, PROP_NONE);
00464         RNA_def_property_struct_type(prop, "BoidRule");
00465         RNA_def_property_pointer_funcs(prop, "rna_BoidState_active_boid_rule_get", NULL, NULL, NULL);
00466         RNA_def_property_ui_text(prop, "Active Boid Rule", "");
00467 
00468         prop= RNA_def_property(srna, "active_boid_rule_index", PROP_INT, PROP_UNSIGNED);
00469         RNA_def_property_int_funcs(prop, "rna_BoidState_active_boid_rule_index_get", "rna_BoidState_active_boid_rule_index_set", "rna_BoidState_active_boid_rule_index_range");
00470         RNA_def_property_ui_text(prop, "Active Boid Rule Index", "");
00471 
00472         prop= RNA_def_property(srna, "rule_fuzzy", PROP_FLOAT, PROP_NONE);
00473         RNA_def_property_float_sdna(prop, NULL, "rule_fuzziness");
00474         RNA_def_property_range(prop, 0.0, 1.0);
00475         RNA_def_property_ui_text(prop, "Rule Fuzziness", "");
00476         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00477 
00478         prop= RNA_def_property(srna, "volume", PROP_FLOAT, PROP_NONE);
00479         RNA_def_property_range(prop, 0.0, 100.0);
00480         RNA_def_property_ui_text(prop, "Volume", "");
00481         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00482 
00483         prop= RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
00484         RNA_def_property_range(prop, 0.0, 10.0);
00485         RNA_def_property_ui_text(prop, "Falloff", "");
00486         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00487 }
00488 static void rna_def_boid_settings(BlenderRNA *brna)
00489 {
00490         StructRNA *srna;
00491         PropertyRNA *prop;
00492 
00493         srna = RNA_def_struct(brna, "BoidSettings", NULL);
00494         RNA_def_struct_path_func(srna, "rna_BoidSettings_path");
00495         RNA_def_struct_ui_text(srna, "Boid Settings", "Settings for boid physics");
00496 
00497         prop= RNA_def_property(srna, "land_smooth", PROP_FLOAT, PROP_NONE);
00498         RNA_def_property_float_sdna(prop, NULL, "landing_smoothness");
00499         RNA_def_property_range(prop, 0.0, 10.0);
00500         RNA_def_property_ui_text(prop, "Landing Smoothness", "How smoothly the boids land");
00501         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00502 
00503         prop= RNA_def_property(srna, "bank", PROP_FLOAT, PROP_NONE);
00504         RNA_def_property_float_sdna(prop, NULL, "banking");
00505         RNA_def_property_range(prop, 0.0, 2.0);
00506         RNA_def_property_ui_text(prop, "Banking", "Amount of rotation around velocity vector on turns");
00507         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00508 
00509         prop= RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE);
00510         RNA_def_property_float_sdna(prop, NULL, "pitch");
00511         RNA_def_property_range(prop, 0.0, 2.0);
00512         RNA_def_property_ui_text(prop, "Pitch", "Amount of rotation around side vector");
00513         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00514 
00515         prop= RNA_def_property(srna, "height", PROP_FLOAT, PROP_NONE);
00516         RNA_def_property_range(prop, 0.0, 2.0);
00517         RNA_def_property_ui_text(prop, "Height", "Boid height relative to particle size");
00518         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00519 
00520         /* states */
00521         prop= RNA_def_property(srna, "states", PROP_COLLECTION, PROP_NONE);
00522         RNA_def_property_struct_type(prop, "BoidState");
00523         RNA_def_property_ui_text(prop, "Boid States", "");
00524 
00525         prop= RNA_def_property(srna, "active_boid_state", PROP_POINTER, PROP_NONE);
00526         RNA_def_property_struct_type(prop, "BoidRule");
00527         RNA_def_property_pointer_funcs(prop, "rna_BoidSettings_active_boid_state_get", NULL, NULL, NULL);
00528         RNA_def_property_ui_text(prop, "Active Boid Rule", "");
00529 
00530         prop= RNA_def_property(srna, "active_boid_state_index", PROP_INT, PROP_UNSIGNED);
00531         RNA_def_property_int_funcs(prop, "rna_BoidSettings_active_boid_state_index_get", "rna_BoidSettings_active_boid_state_index_set", "rna_BoidSettings_active_boid_state_index_range");
00532         RNA_def_property_ui_text(prop, "Active Boid State Index", "");
00533 
00534         /* character properties */
00535         prop= RNA_def_property(srna, "health", PROP_FLOAT, PROP_NONE);
00536         RNA_def_property_range(prop, 0.0, 100.0);
00537         RNA_def_property_ui_text(prop, "Health", "Initial boid health when born");
00538         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00539 
00540         prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
00541         RNA_def_property_range(prop, 0.0, 100.0);
00542         RNA_def_property_ui_text(prop, "Strength", "Maximum caused damage on attack per second");
00543         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00544 
00545         prop= RNA_def_property(srna, "aggression", PROP_FLOAT, PROP_NONE);
00546         RNA_def_property_range(prop, 0.0, 100.0);
00547         RNA_def_property_ui_text(prop, "Aggression", "Boid will fight this times stronger enemy");
00548         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00549 
00550         prop= RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_NONE);
00551         RNA_def_property_range(prop, 0.0, 1.0);
00552         RNA_def_property_ui_text(prop, "Accuracy", "Accuracy of attack");
00553         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00554 
00555         prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
00556         RNA_def_property_range(prop, 0.0, 100.0);
00557         RNA_def_property_ui_text(prop, "Range", "The maximum distance from which a boid can attack");
00558         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00559 
00560         /* physical properties */
00561         prop= RNA_def_property(srna, "air_speed_min", PROP_FLOAT, PROP_NONE);
00562         RNA_def_property_float_sdna(prop, NULL, "air_min_speed");
00563         RNA_def_property_range(prop, 0.0, 1.0);
00564         RNA_def_property_ui_text(prop, "Min Air Speed", "Minimum speed in air (relative to maximum speed)");
00565         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00566 
00567         prop= RNA_def_property(srna, "air_speed_max", PROP_FLOAT, PROP_NONE);
00568         RNA_def_property_float_sdna(prop, NULL, "air_max_speed");
00569         RNA_def_property_range(prop, 0.0, 100.0);
00570         RNA_def_property_ui_text(prop, "Max Air Speed", "Maximum speed in air");
00571         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00572 
00573         prop= RNA_def_property(srna, "air_acc_max", PROP_FLOAT, PROP_NONE);
00574         RNA_def_property_float_sdna(prop, NULL, "air_max_acc");
00575         RNA_def_property_range(prop, 0.0, 1.0);
00576         RNA_def_property_ui_text(prop, "Max Air Acceleration", "Maximum acceleration in air (relative to maximum speed)");
00577         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00578 
00579         prop= RNA_def_property(srna, "air_ave_max", PROP_FLOAT, PROP_NONE);
00580         RNA_def_property_float_sdna(prop, NULL, "air_max_ave");
00581         RNA_def_property_range(prop, 0.0, 1.0);
00582         RNA_def_property_ui_text(prop, "Max Air Angular Velocity", "Maximum angular velocity in air (relative to 180 degrees)");
00583         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00584 
00585         prop= RNA_def_property(srna, "air_personal_space", PROP_FLOAT, PROP_NONE);
00586         RNA_def_property_range(prop, 0.0, 10.0);
00587         RNA_def_property_ui_text(prop, "Air Personal Space", "Radius of boids personal space in air (% of particle size)");
00588         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00589 
00590         prop= RNA_def_property(srna, "land_jump_speed", PROP_FLOAT, PROP_NONE);
00591         RNA_def_property_range(prop, 0.0, 100.0);
00592         RNA_def_property_ui_text(prop, "Jump Speed", "Maximum speed for jumping");
00593         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00594 
00595         prop= RNA_def_property(srna, "land_speed_max", PROP_FLOAT, PROP_NONE);
00596         RNA_def_property_float_sdna(prop, NULL, "land_max_speed");
00597         RNA_def_property_range(prop, 0.0, 100.0);
00598         RNA_def_property_ui_text(prop, "Max Land Speed", "Maximum speed on land");
00599         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00600 
00601         prop= RNA_def_property(srna, "land_acc_max", PROP_FLOAT, PROP_NONE);
00602         RNA_def_property_float_sdna(prop, NULL, "land_max_acc");
00603         RNA_def_property_range(prop, 0.0, 1.0);
00604         RNA_def_property_ui_text(prop, "Max Land Acceleration", "Maximum acceleration on land (relative to maximum speed)");
00605         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00606 
00607         prop= RNA_def_property(srna, "land_ave_max", PROP_FLOAT, PROP_NONE);
00608         RNA_def_property_float_sdna(prop, NULL, "land_max_ave");
00609         RNA_def_property_range(prop, 0.0, 1.0);
00610         RNA_def_property_ui_text(prop, "Max Land Angular Velocity", "Maximum angular velocity on land (relative to 180 degrees)");
00611         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00612 
00613         prop= RNA_def_property(srna, "land_personal_space", PROP_FLOAT, PROP_NONE);
00614         RNA_def_property_range(prop, 0.0, 10.0);
00615         RNA_def_property_ui_text(prop, "Land Personal Space", "Radius of boids personal space on land (% of particle size)");
00616         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00617 
00618         prop= RNA_def_property(srna, "land_stick_force", PROP_FLOAT, PROP_NONE);
00619         RNA_def_property_range(prop, 0.0, 1000.0);
00620         RNA_def_property_ui_text(prop, "Land Stick Force", "How strong a force must be to start effecting a boid on land");
00621         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00622 
00623         /* options */
00624         prop= RNA_def_property(srna, "use_flight", PROP_BOOLEAN, PROP_NONE);
00625         RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_FLIGHT);
00626         RNA_def_property_ui_text(prop, "Allow Flight", "Allow boids to move in air");
00627         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00628 
00629         prop= RNA_def_property(srna, "use_land", PROP_BOOLEAN, PROP_NONE);
00630         RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_LAND);
00631         RNA_def_property_ui_text(prop, "Allow Land", "Allow boids to move on land");
00632         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00633 
00634         prop= RNA_def_property(srna, "use_climb", PROP_BOOLEAN, PROP_NONE);
00635         RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_CLIMB);
00636         RNA_def_property_ui_text(prop, "Allow Climbing", "Allow boids to climb goal objects");
00637         RNA_def_property_update(prop, 0, "rna_Boids_reset");
00638 }
00639 
00640 void RNA_def_boid(BlenderRNA *brna)
00641 {
00642         rna_def_boidrule(brna);
00643         rna_def_boidstate(brna);
00644         rna_def_boid_settings(brna);
00645 }
00646 
00647 #endif