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

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

Removed Part's "visual thickness" property

File size: 3.4 KB
Line 
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
7GeneProps GeneProps::standard_values;
8
9GeneProps::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        cred = 0.5;
27        cgreen = 0.5;
28        cblue = 0.5;
29
30        normalizeBiol4();
31}
32
33void GeneProps::normalizeBiol4()
34{
35        // make them sum to 1
36        double sum = muscle_power + assimilation + stamina + ingestion;
37        if (sum == 0)
38        {
39                muscle_power = assimilation = stamina = ingestion = 0.25;
40        }
41        else
42        {
43                muscle_power /= sum;
44                assimilation /= sum;
45                stamina /= sum;
46                ingestion /= sum;
47        }
48}
49
50int GeneProps::executeModifier(char modif)
51{
52        switch (modif)
53        {
54#ifdef v1f1COMPATIBLE
55        case 'L': length += (3.0 - length)*0.3;
56                length = min(length, Model::getMaxJoint().d.x); break;
57#else
58        case 'L': length += (2.0 - length)*0.3; //2.0 is currently Model::getMaxJoint().d.x so min() does not limit the range
59                length = min(length, Model::getMaxJoint().d.x); break;
60#endif
61        case 'l': length += (0.33 - length)*0.3;
62                length = max(length, Model::getMinJoint().d.x); break;
63
64        case 'W': weight += (2.0 - weight)*0.3;  break;
65        case 'w': weight += (0.5 - weight)*0.3;  break;
66        case 'F': friction += (4 - friction)*0.2;  break;
67        case 'f': friction -= friction*0.2;  break;
68        case 'C': curvedness += (2.0 - curvedness) * 0.25; break;
69        case 'c': curvedness += (-2.0 - curvedness) * 0.25; break;
70        case 'Q': twist += (M_PI_2 - twist)*0.3; break;
71        case 'q': twist += (-M_PI_2 - twist)*0.3; break;
72        case 'E': energy += (10.0 - energy)*0.1;  break;
73        case 'e': energy -= energy*0.1;  break;
74
75        case 'A': assimilation += (1 - assimilation)*0.8;       normalizeBiol4(); break;
76        case 'a': assimilation -= assimilation*0.4;     normalizeBiol4(); break;
77        case 'I': ingestion += (1 - ingestion)*0.8;     normalizeBiol4(); break;
78        case 'i': ingestion -= ingestion * 0.4; normalizeBiol4(); break;
79        case 'S': stamina += (1 - stamina)*0.8; normalizeBiol4(); break;
80        case 's': stamina -= stamina*0.4;       normalizeBiol4(); break;
81        case 'M': muscle_power += (1 - muscle_power)*0.8;       normalizeBiol4(); break;
82        case 'm': muscle_power -= muscle_power*0.4;     normalizeBiol4(); break;
83
84        case 'D': cred += (1.0 - cred)*0.25;  break;
85        case 'd': cred += (0.0 - cred)*0.25;  break;
86        case 'G': cgreen += (1.0 - cgreen)*0.25;  break;
87        case 'g': cgreen += (0.0 - cgreen)*0.25;  break;
88        case 'B': cblue += (1.0 - cblue)*0.25;  break;
89        case 'b': cblue += (0.0 - cblue)*0.25;  break;
90
91        default: return -1;
92        }
93        return 0;
94}
95
96void GeneProps::propagateAlong(bool use_f1_muscle_reset_range)
97{
98        length = 0.5*length + 0.5 * standard_values.length;
99        weight += (standard_values.weight - weight) * 0.5;
100        friction = 0.8 * friction + 0.2 * standard_values.friction;
101        curvedness = 0.66 * curvedness;
102        twist = 0.66 * twist;
103
104        assimilation = 0.8 * assimilation + 0.2 * standard_values.assimilation;
105        ingestion = 0.8 * ingestion + 0.2 * standard_values.ingestion;
106        stamina = 0.8 * stamina + 0.2 * standard_values.stamina;
107        muscle_power = 0.8 * muscle_power + 0.2 * standard_values.muscle_power;
108
109        normalizeBiol4();
110
111        if (use_f1_muscle_reset_range)
112        {
113                if (muscle_reset_range) muscle_bend_range = 1.0; else muscle_reset_range = true;
114        }
115}
Note: See TracBrowser for help on using the repository browser.