source: cpp/frams/genetics/geneprops.cpp @ 1139

Last change on this file since 1139 was 1130, checked in by Maciej Komosinski, 4 years ago

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

File size: 3.5 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include "geneprops.h"
6#include <algorithm>
7
8GeneProps GeneProps::standard_values;
9
10GeneProps::GeneProps()
11{
12        length = 1.0;
13        weight = 1.0;
14        friction = 0.4;
15        curvedness = 0.0;
16        twist = 0.0;
17        energy = 1.0;
18
19        muscle_power = 0.25; // "biological" property
20        assimilation = 0.25; // "biological" property
21        stamina = 0.25; // "biological" property
22        ingestion = 0.25; // "biological" property
23
24        muscle_bend_range = 1.0;
25        muscle_reset_range = true;
26
27        cred = 0.5;
28        cgreen = 0.5;
29        cblue = 0.5;
30
31        normalizeBiol4();
32}
33
34void 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
51int GeneProps::executeModifier(char modif)
52{
53        switch (modif)
54        {
55#ifdef v1f1COMPATIBLE
56        case 'L': length += (3.0 - length)*0.3;
57                length = std::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 = std::min(length, Model::getMaxJoint().d.x); break;
61#endif
62        case 'l': length += (0.33 - length)*0.3;
63                length = std::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
92        default: return -1;
93        }
94        return 0;
95}
96
97void GeneProps::propagateAlong(bool use_f1_muscle_reset_range)
98{
99        length = 0.5*length + 0.5 * standard_values.length;
100        weight += (standard_values.weight - weight) * 0.5;
101        friction = 0.8 * friction + 0.2 * standard_values.friction;
102        curvedness = 0.66 * curvedness;
103        twist = 0.66 * twist;
104
105        assimilation = 0.8 * assimilation + 0.2 * standard_values.assimilation;
106        ingestion = 0.8 * ingestion + 0.2 * standard_values.ingestion;
107        stamina = 0.8 * stamina + 0.2 * standard_values.stamina;
108        muscle_power = 0.8 * muscle_power + 0.2 * standard_values.muscle_power;
109
110        normalizeBiol4();
111
112        if (use_f1_muscle_reset_range)
113        {
114                if (muscle_reset_range) muscle_bend_range = 1.0; else muscle_reset_range = true;
115        }
116}
Note: See TracBrowser for help on using the repository browser.