Blender  V2.93
rna_boid.c
Go to the documentation of this file.
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 
24 #include <float.h>
25 #include <limits.h>
26 #include <stdlib.h>
27 
28 #include "DNA_boid_types.h"
29 #include "DNA_object_types.h"
30 #include "DNA_particle_types.h"
31 #include "DNA_scene_types.h"
32 
33 #include "BLI_utildefines.h"
34 
35 #include "RNA_define.h"
36 #include "RNA_enum_types.h"
37 
38 #include "rna_internal.h"
39 
40 #include "WM_api.h"
41 #include "WM_types.h"
42 
45  "GOAL",
46  0,
47  "Goal",
48  "Go to assigned object or loudest assigned signal source"},
50  "AVOID",
51  0,
52  "Avoid",
53  "Get away from assigned object or loudest assigned signal source"},
55  "AVOID_COLLISION",
56  0,
57  "Avoid Collision",
58  "Maneuver to avoid collisions with other boids and deflector objects in "
59  "near future"},
60  {eBoidRuleType_Separate, "SEPARATE", 0, "Separate", "Keep from going through other boids"},
62  "FLOCK",
63  0,
64  "Flock",
65  "Move to center of neighbors and match their velocity"},
67  "FOLLOW_LEADER",
68  0,
69  "Follow Leader",
70  "Follow a boid or assigned object"},
72  "AVERAGE_SPEED",
73  0,
74  "Average Speed",
75  "Maintain speed, flight level or wander"},
76  {eBoidRuleType_Fight, "FIGHT", 0, "Fight", "Go to closest enemy and attack when in range"},
77 #if 0
78  {eBoidRuleType_Protect,
79  "PROTECT",
80  0,
81  "Protect",
82  "Go to enemy closest to target and attack when in range"},
83  {eBoidRuleType_Hide,
84  "HIDE",
85  0,
86  "Hide",
87  "Find a deflector move to its other side from closest enemy"},
88  {eBoidRuleType_FollowPath,
89  "FOLLOW_PATH",
90  0,
91  "Follow Path",
92  "Move along a assigned curve or closest curve in a group"},
93  {eBoidRuleType_FollowWall,
94  "FOLLOW_WALL",
95  0,
96  "Follow Wall",
97  "Move next to a deflector object's in direction of its tangent"},
98 #endif
99  {0, NULL, 0, NULL, NULL},
100 };
101 
102 #ifndef RNA_RUNTIME
105  "FUZZY",
106  0,
107  "Fuzzy",
108  "Rules are gone through top to bottom (only the first rule which effect is above "
109  "fuzziness threshold is evaluated)"},
110  {eBoidRulesetType_Random, "RANDOM", 0, "Random", "A random rule is selected for each boid"},
111  {eBoidRulesetType_Average, "AVERAGE", 0, "Average", "All rules are averaged"},
112  {0, NULL, 0, NULL, NULL},
113 };
114 #endif
115 
116 #ifdef RNA_RUNTIME
117 
118 # include "BLI_math_base.h"
119 
120 # include "BKE_context.h"
121 # include "BKE_particle.h"
122 
123 # include "DEG_depsgraph.h"
124 # include "DEG_depsgraph_build.h"
125 
126 static void rna_Boids_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
127 {
128  if (ptr->type == &RNA_ParticleSystem) {
130 
132 
134  }
135  else {
137  }
138 
140 }
141 static void rna_Boids_reset_deps(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
142 {
143  if (ptr->type == &RNA_ParticleSystem) {
145 
147 
149  }
150  else {
152  }
153 
155 
157 }
158 
159 static StructRNA *rna_BoidRule_refine(struct PointerRNA *ptr)
160 {
161  BoidRule *rule = (BoidRule *)ptr->data;
162 
163  switch (rule->type) {
164  case eBoidRuleType_Goal:
165  return &RNA_BoidRuleGoal;
166  case eBoidRuleType_Avoid:
167  return &RNA_BoidRuleAvoid;
171  return &RNA_BoidRuleFollowLeader;
173  return &RNA_BoidRuleAverageSpeed;
174  case eBoidRuleType_Fight:
175  return &RNA_BoidRuleFight;
176  default:
177  return &RNA_BoidRule;
178  }
179 }
180 
181 static char *rna_BoidRule_path(PointerRNA *ptr)
182 {
183  BoidRule *rule = (BoidRule *)ptr->data;
184  char name_esc[sizeof(rule->name) * 2];
185 
186  BLI_str_escape(name_esc, rule->name, sizeof(name_esc));
187 
188  return BLI_sprintfN("rules[\"%s\"]", name_esc); /* XXX not unique */
189 }
190 
191 static PointerRNA rna_BoidState_active_boid_rule_get(PointerRNA *ptr)
192 {
194  BoidRule *rule = (BoidRule *)state->rules.first;
195 
196  for (; rule; rule = rule->next) {
197  if (rule->flag & BOIDRULE_CURRENT) {
199  }
200  }
202 }
203 static void rna_BoidState_active_boid_rule_index_range(
204  PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
205 {
207  *min = 0;
208  *max = max_ii(0, BLI_listbase_count(&state->rules) - 1);
209 }
210 
211 static int rna_BoidState_active_boid_rule_index_get(PointerRNA *ptr)
212 {
214  BoidRule *rule = (BoidRule *)state->rules.first;
215  int i = 0;
216 
217  for (; rule; rule = rule->next, i++) {
218  if (rule->flag & BOIDRULE_CURRENT) {
219  return i;
220  }
221  }
222  return 0;
223 }
224 
225 static void rna_BoidState_active_boid_rule_index_set(struct PointerRNA *ptr, int value)
226 {
228  BoidRule *rule = (BoidRule *)state->rules.first;
229  int i = 0;
230 
231  for (; rule; rule = rule->next, i++) {
232  if (i == value) {
233  rule->flag |= BOIDRULE_CURRENT;
234  }
235  else {
236  rule->flag &= ~BOIDRULE_CURRENT;
237  }
238  }
239 }
240 
241 static int particle_id_check(PointerRNA *ptr)
242 {
243  ID *id = ptr->owner_id;
244 
245  return (GS(id->name) == ID_PA);
246 }
247 
248 static char *rna_BoidSettings_path(PointerRNA *ptr)
249 {
250  BoidSettings *boids = (BoidSettings *)ptr->data;
251 
252  if (particle_id_check(ptr)) {
254 
255  if (part->boids == boids) {
256  return BLI_strdup("boids");
257  }
258  }
259  return NULL;
260 }
261 
262 static PointerRNA rna_BoidSettings_active_boid_state_get(PointerRNA *ptr)
263 {
264  BoidSettings *boids = (BoidSettings *)ptr->data;
265  BoidState *state = (BoidState *)boids->states.first;
266 
267  for (; state; state = state->next) {
268  if (state->flag & BOIDSTATE_CURRENT) {
270  }
271  }
273 }
274 static void rna_BoidSettings_active_boid_state_index_range(
275  PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
276 {
277  BoidSettings *boids = (BoidSettings *)ptr->data;
278  *min = 0;
279  *max = max_ii(0, BLI_listbase_count(&boids->states) - 1);
280 }
281 
282 static int rna_BoidSettings_active_boid_state_index_get(PointerRNA *ptr)
283 {
284  BoidSettings *boids = (BoidSettings *)ptr->data;
285  BoidState *state = (BoidState *)boids->states.first;
286  int i = 0;
287 
288  for (; state; state = state->next, i++) {
289  if (state->flag & BOIDSTATE_CURRENT) {
290  return i;
291  }
292  }
293  return 0;
294 }
295 
296 static void rna_BoidSettings_active_boid_state_index_set(struct PointerRNA *ptr, int value)
297 {
298  BoidSettings *boids = (BoidSettings *)ptr->data;
299  BoidState *state = (BoidState *)boids->states.first;
300  int i = 0;
301 
302  for (; state; state = state->next, i++) {
303  if (i == value) {
304  state->flag |= BOIDSTATE_CURRENT;
305  }
306  else {
307  state->flag &= ~BOIDSTATE_CURRENT;
308  }
309  }
310 }
311 
312 #else
313 
315 {
316  StructRNA *srna;
317  PropertyRNA *prop;
318 
319  srna = RNA_def_struct(brna, "BoidRuleGoal", "BoidRule");
320  RNA_def_struct_ui_text(srna, "Goal", "");
321  RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid");
322 
323  prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
324  RNA_def_property_pointer_sdna(prop, NULL, "ob");
326  RNA_def_property_ui_text(prop, "Object", "Goal object");
327  RNA_def_property_update(prop, 0, "rna_Boids_reset_deps");
328 
329  prop = RNA_def_property(srna, "use_predict", PROP_BOOLEAN, PROP_NONE);
331  RNA_def_property_ui_text(prop, "Predict", "Predict target movement");
332  RNA_def_property_update(prop, 0, "rna_Boids_reset");
333 }
334 
336 {
337  StructRNA *srna;
338  PropertyRNA *prop;
339 
340  srna = RNA_def_struct(brna, "BoidRuleAvoid", "BoidRule");
341  RNA_def_struct_ui_text(srna, "Avoid", "");
342  RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid");
343 
344  prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
345  RNA_def_property_pointer_sdna(prop, NULL, "ob");
347  RNA_def_property_ui_text(prop, "Object", "Object to avoid");
348  RNA_def_property_update(prop, 0, "rna_Boids_reset_deps");
349 
350  prop = RNA_def_property(srna, "use_predict", PROP_BOOLEAN, PROP_NONE);
352  RNA_def_property_ui_text(prop, "Predict", "Predict target movement");
353  RNA_def_property_update(prop, 0, "rna_Boids_reset");
354 
355  prop = RNA_def_property(srna, "fear_factor", PROP_FLOAT, PROP_NONE);
356  RNA_def_property_range(prop, 0.0f, 100.0f);
358  prop, "Fear Factor", "Avoid object if danger from it is above this threshold");
359  RNA_def_property_update(prop, 0, "rna_Boids_reset");
360 }
361 
363 {
364  StructRNA *srna;
365  PropertyRNA *prop;
366 
367  srna = RNA_def_struct(brna, "BoidRuleAvoidCollision", "BoidRule");
368  RNA_def_struct_ui_text(srna, "Avoid Collision", "");
369 
370  prop = RNA_def_property(srna, "use_avoid", PROP_BOOLEAN, PROP_NONE);
372  RNA_def_property_ui_text(prop, "Boids", "Avoid collision with other boids");
373  RNA_def_property_update(prop, 0, "rna_Boids_reset");
374 
375  prop = RNA_def_property(srna, "use_avoid_collision", PROP_BOOLEAN, PROP_NONE);
377  RNA_def_property_ui_text(prop, "Deflectors", "Avoid collision with deflector objects");
378  RNA_def_property_update(prop, 0, "rna_Boids_reset");
379 
380  prop = RNA_def_property(srna, "look_ahead", PROP_FLOAT, PROP_NONE);
381  RNA_def_property_range(prop, 0.0f, 100.0f);
382  RNA_def_property_ui_text(prop, "Look Ahead", "Time to look ahead in seconds");
383  RNA_def_property_update(prop, 0, "rna_Boids_reset");
384 }
385 
387 {
388  StructRNA *srna;
389  PropertyRNA *prop;
390 
391  srna = RNA_def_struct(brna, "BoidRuleFollowLeader", "BoidRule");
392  RNA_def_struct_ui_text(srna, "Follow Leader", "");
393 
394  prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
395  RNA_def_property_pointer_sdna(prop, NULL, "ob");
397  RNA_def_property_ui_text(prop, "Object", "Follow this object instead of a boid");
398  RNA_def_property_update(prop, 0, "rna_Boids_reset_deps");
399 
400  prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
401  RNA_def_property_range(prop, 0.0f, 100.0f);
402  RNA_def_property_ui_text(prop, "Distance", "Distance behind leader to follow");
403  RNA_def_property_update(prop, 0, "rna_Boids_reset");
404 
405  prop = RNA_def_property(srna, "queue_count", PROP_INT, PROP_NONE);
406  RNA_def_property_int_sdna(prop, NULL, "queue_size");
407  RNA_def_property_range(prop, 0.0f, 100.0f);
408  RNA_def_property_ui_text(prop, "Queue Size", "How many boids in a line");
409  RNA_def_property_update(prop, 0, "rna_Boids_reset");
410 
411  prop = RNA_def_property(srna, "use_line", PROP_BOOLEAN, PROP_NONE);
413  RNA_def_property_ui_text(prop, "Line", "Follow leader in a line");
414  RNA_def_property_update(prop, 0, "rna_Boids_reset");
415 }
416 
418 {
419  StructRNA *srna;
420  PropertyRNA *prop;
421 
422  srna = RNA_def_struct(brna, "BoidRuleAverageSpeed", "BoidRule");
423  RNA_def_struct_ui_text(srna, "Average Speed", "");
424 
425  prop = RNA_def_property(srna, "wander", PROP_FLOAT, PROP_NONE);
426  RNA_def_property_range(prop, 0.0f, 1.0f);
427  RNA_def_property_ui_text(prop, "Wander", "How fast velocity's direction is randomized");
428  RNA_def_property_update(prop, 0, "rna_Boids_reset");
429 
430  prop = RNA_def_property(srna, "level", PROP_FLOAT, PROP_NONE);
431  RNA_def_property_range(prop, 0.0f, 1.0f);
432  RNA_def_property_ui_text(prop, "Level", "How much velocity's z-component is kept constant");
433  RNA_def_property_update(prop, 0, "rna_Boids_reset");
434 
435  prop = RNA_def_property(srna, "speed", PROP_FLOAT, PROP_FACTOR);
436  RNA_def_property_range(prop, 0.0f, 1.0f);
437  RNA_def_property_ui_text(prop, "Speed", "Percentage of maximum speed");
438  RNA_def_property_update(prop, 0, "rna_Boids_reset");
439 }
440 
442 {
443  StructRNA *srna;
444  PropertyRNA *prop;
445 
446  srna = RNA_def_struct(brna, "BoidRuleFight", "BoidRule");
447  RNA_def_struct_ui_text(srna, "Fight", "");
448 
449  prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
450  RNA_def_property_range(prop, 0.0f, 100.0f);
451  RNA_def_property_ui_text(prop, "Fight Distance", "Attack boids at max this distance");
452  RNA_def_property_update(prop, 0, "rna_Boids_reset");
453 
454  prop = RNA_def_property(srna, "flee_distance", PROP_FLOAT, PROP_NONE);
455  RNA_def_property_range(prop, 0.0f, 100.0f);
456  RNA_def_property_ui_text(prop, "Flee Distance", "Flee to this distance");
457  RNA_def_property_update(prop, 0, "rna_Boids_reset");
458 }
459 
460 static void rna_def_boidrule(BlenderRNA *brna)
461 {
462  StructRNA *srna;
463  PropertyRNA *prop;
464 
465  /* data */
466  srna = RNA_def_struct(brna, "BoidRule", NULL);
467  RNA_def_struct_ui_text(srna, "Boid Rule", "");
468  RNA_def_struct_refine_func(srna, "rna_BoidRule_refine");
469  RNA_def_struct_path_func(srna, "rna_BoidRule_path");
470 
471  /* strings */
472  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
473  RNA_def_property_ui_text(prop, "Name", "Boid rule name");
474  RNA_def_struct_name_property(srna, prop);
475 
476  /* enums */
477  prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
479  RNA_def_property_enum_sdna(prop, NULL, "type");
481  RNA_def_property_ui_text(prop, "Type", "");
482 
483  /* flags */
484  prop = RNA_def_property(srna, "use_in_air", PROP_BOOLEAN, PROP_NONE);
486  RNA_def_property_ui_text(prop, "In Air", "Use rule when boid is flying");
487  RNA_def_property_update(prop, 0, "rna_Boids_reset");
488 
489  prop = RNA_def_property(srna, "use_on_land", PROP_BOOLEAN, PROP_NONE);
491  RNA_def_property_ui_text(prop, "On Land", "Use rule when boid is on land");
492  RNA_def_property_update(prop, 0, "rna_Boids_reset");
493 
494  /*prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE); */
495  /*RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);*/
496  /*RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Expanded); */
497  /*RNA_def_property_ui_text(prop, "Expanded", "Set modifier expanded in the user interface"); */
498 
499  /* types */
500  rna_def_boidrule_goal(brna);
506 }
507 
508 static void rna_def_boidstate(BlenderRNA *brna)
509 {
510  StructRNA *srna;
511  PropertyRNA *prop;
512 
513  srna = RNA_def_struct(brna, "BoidState", NULL);
514  RNA_def_struct_ui_text(srna, "Boid State", "Boid state for boid physics");
515 
516  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
517  RNA_def_property_ui_text(prop, "Name", "Boid state name");
518  RNA_def_struct_name_property(srna, prop);
519 
520  prop = RNA_def_property(srna, "ruleset_type", PROP_ENUM, PROP_NONE);
522  RNA_def_property_ui_text(prop, "Rule Evaluation", "How the rules in the list are evaluated");
523 
524  prop = RNA_def_property(srna, "rules", PROP_COLLECTION, PROP_NONE);
525  RNA_def_property_struct_type(prop, "BoidRule");
526  RNA_def_property_ui_text(prop, "Boid Rules", "");
527 
528  prop = RNA_def_property(srna, "active_boid_rule", PROP_POINTER, PROP_NONE);
529  RNA_def_property_struct_type(prop, "BoidRule");
530  RNA_def_property_pointer_funcs(prop, "rna_BoidState_active_boid_rule_get", NULL, NULL, NULL);
531  RNA_def_property_ui_text(prop, "Active Boid Rule", "");
532 
533  prop = RNA_def_property(srna, "active_boid_rule_index", PROP_INT, PROP_UNSIGNED);
535  "rna_BoidState_active_boid_rule_index_get",
536  "rna_BoidState_active_boid_rule_index_set",
537  "rna_BoidState_active_boid_rule_index_range");
538  RNA_def_property_ui_text(prop, "Active Boid Rule Index", "");
539 
540  prop = RNA_def_property(srna, "rule_fuzzy", PROP_FLOAT, PROP_NONE);
541  RNA_def_property_float_sdna(prop, NULL, "rule_fuzziness");
542  RNA_def_property_range(prop, 0.0, 1.0);
543  RNA_def_property_ui_text(prop, "Rule Fuzziness", "");
544  RNA_def_property_update(prop, 0, "rna_Boids_reset");
545 
546  prop = RNA_def_property(srna, "volume", PROP_FLOAT, PROP_NONE);
547  RNA_def_property_range(prop, 0.0, 100.0);
548  RNA_def_property_ui_text(prop, "Volume", "");
549  RNA_def_property_update(prop, 0, "rna_Boids_reset");
550 
551  prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
552  RNA_def_property_range(prop, 0.0, 10.0);
553  RNA_def_property_ui_text(prop, "Falloff", "");
554  RNA_def_property_update(prop, 0, "rna_Boids_reset");
555 }
557 {
558  StructRNA *srna;
559  PropertyRNA *prop;
560 
561  srna = RNA_def_struct(brna, "BoidSettings", NULL);
562  RNA_def_struct_path_func(srna, "rna_BoidSettings_path");
563  RNA_def_struct_ui_text(srna, "Boid Settings", "Settings for boid physics");
564 
565  prop = RNA_def_property(srna, "land_smooth", PROP_FLOAT, PROP_NONE);
566  RNA_def_property_float_sdna(prop, NULL, "landing_smoothness");
567  RNA_def_property_range(prop, 0.0, 10.0);
568  RNA_def_property_ui_text(prop, "Landing Smoothness", "How smoothly the boids land");
569  RNA_def_property_update(prop, 0, "rna_Boids_reset");
570 
571  prop = RNA_def_property(srna, "bank", PROP_FLOAT, PROP_NONE);
572  RNA_def_property_float_sdna(prop, NULL, "banking");
573  RNA_def_property_range(prop, 0.0, 2.0);
574  RNA_def_property_ui_text(prop, "Banking", "Amount of rotation around velocity vector on turns");
575  RNA_def_property_update(prop, 0, "rna_Boids_reset");
576 
577  prop = RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE);
578  RNA_def_property_float_sdna(prop, NULL, "pitch");
579  RNA_def_property_range(prop, 0.0, 2.0);
580  RNA_def_property_ui_text(prop, "Pitch", "Amount of rotation around side vector");
581  RNA_def_property_update(prop, 0, "rna_Boids_reset");
582 
583  prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_NONE);
584  RNA_def_property_range(prop, 0.0, 2.0);
585  RNA_def_property_ui_text(prop, "Height", "Boid height relative to particle size");
586  RNA_def_property_update(prop, 0, "rna_Boids_reset");
587 
588  /* states */
589  prop = RNA_def_property(srna, "states", PROP_COLLECTION, PROP_NONE);
590  RNA_def_property_struct_type(prop, "BoidState");
591  RNA_def_property_ui_text(prop, "Boid States", "");
592 
593  prop = RNA_def_property(srna, "active_boid_state", PROP_POINTER, PROP_NONE);
594  RNA_def_property_struct_type(prop, "BoidRule");
595  RNA_def_property_pointer_funcs(prop, "rna_BoidSettings_active_boid_state_get", NULL, NULL, NULL);
596  RNA_def_property_ui_text(prop, "Active Boid Rule", "");
597 
598  prop = RNA_def_property(srna, "active_boid_state_index", PROP_INT, PROP_UNSIGNED);
600  "rna_BoidSettings_active_boid_state_index_get",
601  "rna_BoidSettings_active_boid_state_index_set",
602  "rna_BoidSettings_active_boid_state_index_range");
603  RNA_def_property_ui_text(prop, "Active Boid State Index", "");
604 
605  /* character properties */
606  prop = RNA_def_property(srna, "health", PROP_FLOAT, PROP_NONE);
607  RNA_def_property_range(prop, 0.0, 100.0);
608  RNA_def_property_ui_text(prop, "Health", "Initial boid health when born");
609  RNA_def_property_update(prop, 0, "rna_Boids_reset");
610 
611  prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
612  RNA_def_property_range(prop, 0.0, 100.0);
613  RNA_def_property_ui_text(prop, "Strength", "Maximum caused damage on attack per second");
614  RNA_def_property_update(prop, 0, "rna_Boids_reset");
615 
616  prop = RNA_def_property(srna, "aggression", PROP_FLOAT, PROP_NONE);
617  RNA_def_property_range(prop, 0.0, 100.0);
618  RNA_def_property_ui_text(prop, "Aggression", "Boid will fight this times stronger enemy");
619  RNA_def_property_update(prop, 0, "rna_Boids_reset");
620 
621  prop = RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_NONE);
622  RNA_def_property_range(prop, 0.0, 1.0);
623  RNA_def_property_ui_text(prop, "Accuracy", "Accuracy of attack");
624  RNA_def_property_update(prop, 0, "rna_Boids_reset");
625 
626  prop = RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
627  RNA_def_property_range(prop, 0.0, 100.0);
628  RNA_def_property_ui_text(prop, "Range", "Maximum distance from which a boid can attack");
629  RNA_def_property_update(prop, 0, "rna_Boids_reset");
630 
631  /* physical properties */
632  prop = RNA_def_property(srna, "air_speed_min", PROP_FLOAT, PROP_NONE);
633  RNA_def_property_float_sdna(prop, NULL, "air_min_speed");
634  RNA_def_property_range(prop, 0.0, 1.0);
636  prop, "Min Air Speed", "Minimum speed in air (relative to maximum speed)");
637  RNA_def_property_update(prop, 0, "rna_Boids_reset");
638 
639  prop = RNA_def_property(srna, "air_speed_max", PROP_FLOAT, PROP_NONE);
640  RNA_def_property_float_sdna(prop, NULL, "air_max_speed");
641  RNA_def_property_range(prop, 0.0, 100.0);
642  RNA_def_property_ui_text(prop, "Max Air Speed", "Maximum speed in air");
643  RNA_def_property_update(prop, 0, "rna_Boids_reset");
644 
645  prop = RNA_def_property(srna, "air_acc_max", PROP_FLOAT, PROP_NONE);
646  RNA_def_property_float_sdna(prop, NULL, "air_max_acc");
647  RNA_def_property_range(prop, 0.0, 1.0);
649  prop, "Max Air Acceleration", "Maximum acceleration in air (relative to maximum speed)");
650  RNA_def_property_update(prop, 0, "rna_Boids_reset");
651 
652  prop = RNA_def_property(srna, "air_ave_max", PROP_FLOAT, PROP_NONE);
653  RNA_def_property_float_sdna(prop, NULL, "air_max_ave");
654  RNA_def_property_range(prop, 0.0, 1.0);
656  "Max Air Angular Velocity",
657  "Maximum angular velocity in air (relative to 180 degrees)");
658  RNA_def_property_update(prop, 0, "rna_Boids_reset");
659 
660  prop = RNA_def_property(srna, "air_personal_space", PROP_FLOAT, PROP_NONE);
661  RNA_def_property_range(prop, 0.0, 10.0);
663  prop, "Air Personal Space", "Radius of boids personal space in air (% of particle size)");
664  RNA_def_property_update(prop, 0, "rna_Boids_reset");
665 
666  prop = RNA_def_property(srna, "land_jump_speed", PROP_FLOAT, PROP_NONE);
667  RNA_def_property_range(prop, 0.0, 100.0);
668  RNA_def_property_ui_text(prop, "Jump Speed", "Maximum speed for jumping");
669  RNA_def_property_update(prop, 0, "rna_Boids_reset");
670 
671  prop = RNA_def_property(srna, "land_speed_max", PROP_FLOAT, PROP_NONE);
672  RNA_def_property_float_sdna(prop, NULL, "land_max_speed");
673  RNA_def_property_range(prop, 0.0, 100.0);
674  RNA_def_property_ui_text(prop, "Max Land Speed", "Maximum speed on land");
675  RNA_def_property_update(prop, 0, "rna_Boids_reset");
676 
677  prop = RNA_def_property(srna, "land_acc_max", PROP_FLOAT, PROP_NONE);
678  RNA_def_property_float_sdna(prop, NULL, "land_max_acc");
679  RNA_def_property_range(prop, 0.0, 1.0);
681  prop, "Max Land Acceleration", "Maximum acceleration on land (relative to maximum speed)");
682  RNA_def_property_update(prop, 0, "rna_Boids_reset");
683 
684  prop = RNA_def_property(srna, "land_ave_max", PROP_FLOAT, PROP_NONE);
685  RNA_def_property_float_sdna(prop, NULL, "land_max_ave");
686  RNA_def_property_range(prop, 0.0, 1.0);
688  "Max Land Angular Velocity",
689  "Maximum angular velocity on land (relative to 180 degrees)");
690  RNA_def_property_update(prop, 0, "rna_Boids_reset");
691 
692  prop = RNA_def_property(srna, "land_personal_space", PROP_FLOAT, PROP_NONE);
693  RNA_def_property_range(prop, 0.0, 10.0);
695  prop, "Land Personal Space", "Radius of boids personal space on land (% of particle size)");
696  RNA_def_property_update(prop, 0, "rna_Boids_reset");
697 
698  prop = RNA_def_property(srna, "land_stick_force", PROP_FLOAT, PROP_NONE);
699  RNA_def_property_range(prop, 0.0, 1000.0);
701  prop, "Land Stick Force", "How strong a force must be to start effecting a boid on land");
702  RNA_def_property_update(prop, 0, "rna_Boids_reset");
703 
704  /* options */
705  prop = RNA_def_property(srna, "use_flight", PROP_BOOLEAN, PROP_NONE);
707  RNA_def_property_ui_text(prop, "Allow Flight", "Allow boids to move in air");
708  RNA_def_property_update(prop, 0, "rna_Boids_reset");
709 
710  prop = RNA_def_property(srna, "use_land", PROP_BOOLEAN, PROP_NONE);
712  RNA_def_property_ui_text(prop, "Allow Land", "Allow boids to move on land");
713  RNA_def_property_update(prop, 0, "rna_Boids_reset");
714 
715  prop = RNA_def_property(srna, "use_climb", PROP_BOOLEAN, PROP_NONE);
717  RNA_def_property_ui_text(prop, "Allow Climbing", "Allow boids to climb goal objects");
718  RNA_def_property_update(prop, 0, "rna_Boids_reset");
719 }
720 
722 {
723  rna_def_boidrule(brna);
724  rna_def_boidstate(brna);
725  rna_def_boid_settings(brna);
726 }
727 
728 #endif
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int max_ii(int a, int b)
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) ATTR_NONNULL()
Definition: string.c:333
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
#define UNUSED(x)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_PSYS_RESET
Definition: DNA_ID.h:620
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ ID_PA
Definition: DNA_ID_enums.h:82
#define BRULE_ACOLL_WITH_BOIDS
#define BOIDSTATE_CURRENT
#define BOID_ALLOW_FLIGHT
#define BRULE_ACOLL_WITH_DEFLECTORS
#define BRULE_LEADER_IN_LINE
#define BOIDRULE_IN_AIR
#define BOIDRULE_CURRENT
@ eBoidRulesetType_Average
@ eBoidRulesetType_Fuzzy
@ eBoidRulesetType_Random
#define BOID_ALLOW_LAND
#define BOIDRULE_ON_LAND
#define BOID_ALLOW_CLIMB
#define BRULE_GOAL_AVOID_PREDICT
@ eBoidRuleType_Flock
@ eBoidRuleType_Separate
@ eBoidRuleType_Goal
@ eBoidRuleType_Fight
@ eBoidRuleType_Avoid
@ eBoidRuleType_FollowLeader
@ eBoidRuleType_AvoidCollision
@ eBoidRuleType_AverageSpeed
Object is a sort of wrapper for general info.
StructRNA RNA_BoidRuleAvoid
StructRNA RNA_BoidRuleAvoidCollision
StructRNA RNA_BoidState
StructRNA RNA_BoidRule
StructRNA RNA_BoidRuleFollowLeader
StructRNA RNA_ParticleSystem
StructRNA RNA_BoidRuleFight
StructRNA RNA_BoidRuleAverageSpeed
StructRNA RNA_BoidRuleGoal
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_FACTOR
Definition: RNA_types.h:131
@ PROP_UNSIGNED
Definition: RNA_types.h:129
#define NA_EDITED
Definition: WM_types.h:462
#define ND_PARTICLE
Definition: WM_types.h:366
#define NC_OBJECT
Definition: WM_types.h:280
Scene scene
#define GS(x)
Definition: iris.c:241
static ulong state[N]
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
static const EnumPropertyItem boidruleset_type_items[]
Definition: rna_boid.c:103
void RNA_def_boid(BlenderRNA *brna)
Definition: rna_boid.c:721
static void rna_def_boidrule_average_speed(BlenderRNA *brna)
Definition: rna_boid.c:417
const EnumPropertyItem rna_enum_boidrule_type_items[]
Definition: rna_boid.c:43
static void rna_def_boidrule_avoid(BlenderRNA *brna)
Definition: rna_boid.c:335
static void rna_def_boidrule_avoid_collision(BlenderRNA *brna)
Definition: rna_boid.c:362
static void rna_def_boidrule(BlenderRNA *brna)
Definition: rna_boid.c:460
static void rna_def_boidrule_fight(BlenderRNA *brna)
Definition: rna_boid.c:441
static void rna_def_boidrule_goal(BlenderRNA *brna)
Definition: rna_boid.c:314
static void rna_def_boidrule_follow_leader(BlenderRNA *brna)
Definition: rna_boid.c:386
static void rna_def_boid_settings(BlenderRNA *brna)
Definition: rna_boid.c:556
static void rna_def_boidstate(BlenderRNA *brna)
Definition: rna_boid.c:508
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
Definition: rna_define.c:1167
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2762
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
Definition: rna_define.c:1212
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
Definition: rna_define.c:1122
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3373
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2623
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3055
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2515
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2364
#define min(a, b)
Definition: sort.c:51
struct BoidRule * next
char name[32]
struct ListBase states
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct BoidSettings * boids
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
float max
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157