1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include "geneprops.h" |
---|
6 | |
---|
7 | GeneProps GeneProps::standard_values; |
---|
8 | |
---|
9 | GeneProps::GeneProps() |
---|
10 | { |
---|
11 | length = 1.0; |
---|
12 | weight = 1.0; |
---|
13 | friction = 0.4; |
---|
14 | curvedness = 0.0; |
---|
15 | twist = 0.0; |
---|
16 | energy = 1.0; |
---|
17 | |
---|
18 | muscle_power = 0.25; // "biological" property |
---|
19 | assimilation = 0.25; // "biological" property |
---|
20 | stamina = 0.25; // "biological" property |
---|
21 | ingestion = 0.25; // "biological" property |
---|
22 | |
---|
23 | muscle_bend_range = 1.0; |
---|
24 | muscle_reset_range = true; |
---|
25 | |
---|
26 | visual_size = 0.2; |
---|
27 | cred = 0.5; |
---|
28 | cgreen = 0.5; |
---|
29 | cblue = 0.5; |
---|
30 | |
---|
31 | normalizeBiol4(); |
---|
32 | } |
---|
33 | |
---|
34 | void GeneProps::normalizeBiol4() |
---|
35 | { |
---|
36 | // make them sum to 1 |
---|
37 | double sum = muscle_power + assimilation + stamina + ingestion; |
---|
38 | if (sum == 0) |
---|
39 | { |
---|
40 | muscle_power = assimilation = stamina = ingestion = 0.25; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | muscle_power /= sum; |
---|
45 | assimilation /= sum; |
---|
46 | stamina /= sum; |
---|
47 | ingestion /= sum; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | int GeneProps::executeModifier(char modif) |
---|
52 | { |
---|
53 | switch (modif) |
---|
54 | { |
---|
55 | #ifdef v1f1COMPATIBLE |
---|
56 | case 'L': length += (3.0 - length)*0.3; |
---|
57 | length = min(length, Model::getMaxJoint().d.x); break; |
---|
58 | #else |
---|
59 | case 'L': length += (2.0 - length)*0.3; //2.0 is currently Model::getMaxJoint().d.x so min() does not limit the range |
---|
60 | length = min(length, Model::getMaxJoint().d.x); break; |
---|
61 | #endif |
---|
62 | case 'l': length += (0.33 - length)*0.3; |
---|
63 | length = max(length, Model::getMinJoint().d.x); break; |
---|
64 | |
---|
65 | case 'W': weight += (2.0 - weight)*0.3; break; |
---|
66 | case 'w': weight += (0.5 - weight)*0.3; break; |
---|
67 | case 'F': friction += (4 - friction)*0.2; break; |
---|
68 | case 'f': friction -= friction*0.2; break; |
---|
69 | case 'C': curvedness += (2.0 - curvedness) * 0.25; break; |
---|
70 | case 'c': curvedness += (-2.0 - curvedness) * 0.25; break; |
---|
71 | case 'Q': twist += (M_PI_2 - twist)*0.3; break; |
---|
72 | case 'q': twist += (-M_PI_2 - twist)*0.3; break; |
---|
73 | case 'E': energy += (10.0 - energy)*0.1; break; |
---|
74 | case 'e': energy -= energy*0.1; break; |
---|
75 | |
---|
76 | case 'A': assimilation += (1 - assimilation)*0.8; normalizeBiol4(); break; |
---|
77 | case 'a': assimilation -= assimilation*0.4; normalizeBiol4(); break; |
---|
78 | case 'I': ingestion += (1 - ingestion)*0.8; normalizeBiol4(); break; |
---|
79 | case 'i': ingestion -= ingestion * 0.4; normalizeBiol4(); break; |
---|
80 | case 'S': stamina += (1 - stamina)*0.8; normalizeBiol4(); break; |
---|
81 | case 's': stamina -= stamina*0.4; normalizeBiol4(); break; |
---|
82 | case 'M': muscle_power += (1 - muscle_power)*0.8; normalizeBiol4(); break; |
---|
83 | case 'm': muscle_power -= muscle_power*0.4; normalizeBiol4(); break; |
---|
84 | |
---|
85 | case 'D': cred += (1.0 - cred)*0.25; break; |
---|
86 | case 'd': cred += (0.0 - cred)*0.25; break; |
---|
87 | case 'G': cgreen += (1.0 - cgreen)*0.25; break; |
---|
88 | case 'g': cgreen += (0.0 - cgreen)*0.25; break; |
---|
89 | case 'B': cblue += (1.0 - cblue)*0.25; break; |
---|
90 | case 'b': cblue += (0.0 - cblue)*0.25; break; |
---|
91 | case 'H': visual_size += (0.7 - visual_size)*0.25; break; |
---|
92 | case 'h': visual_size += (0.05 - visual_size)*0.25; break; |
---|
93 | |
---|
94 | default: return -1; |
---|
95 | } |
---|
96 | return 0; |
---|
97 | } |
---|
98 | |
---|
99 | void GeneProps::propagateAlong(bool use_f1_muscle_reset_range) |
---|
100 | { |
---|
101 | length = 0.5*length + 0.5 * standard_values.length; |
---|
102 | weight += (standard_values.weight - weight) * 0.5; |
---|
103 | friction = 0.8 * friction + 0.2 * standard_values.friction; |
---|
104 | curvedness = 0.66 * curvedness; |
---|
105 | twist = 0.66 * twist; |
---|
106 | |
---|
107 | assimilation = 0.8 * assimilation + 0.2 * standard_values.assimilation; |
---|
108 | ingestion = 0.8 * ingestion + 0.2 * standard_values.ingestion; |
---|
109 | stamina = 0.8 * stamina + 0.2 * standard_values.stamina; |
---|
110 | muscle_power = 0.8 * muscle_power + 0.2 * standard_values.muscle_power; |
---|
111 | |
---|
112 | normalizeBiol4(); |
---|
113 | |
---|
114 | visual_size = 0.5*visual_size + 0.5 * standard_values.visual_size; |
---|
115 | |
---|
116 | if (use_f1_muscle_reset_range) |
---|
117 | { |
---|
118 | if (muscle_reset_range) muscle_bend_range = 1.0; else muscle_reset_range = true; |
---|
119 | } |
---|
120 | } |
---|