source: cpp/frams/genetics/geneprops.h @ 1242

Last change on this file since 1242 was 1242, checked in by Maciej Komosinski, 11 months ago

Changed the default behavior of modifier genes in f1 and f4 to GenePropsOps_New05: the coefficient of change is set to 0.5 for all properties and for both increase and decrease, which ensures an equal distribution of target property values with a relatively fast convergence to minimal and maximal values; the four "biological" properties are no longer aggregated and normalized

File size: 6.9 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#ifndef _GENEPROPS_H
6#define _GENEPROPS_H
7
8#include <common/nonstd_math.h>
9#include <frams/model/model.h>
10
11
12
13
14
15#define F14_MODIFIERS_VISUAL "DdGgBb"
16#define F14_MODIFIERS_RARE "EeWwAaSs" //expdef would need to handle these properly/specifically to ensure reasonable behavior, and hardly any expdef does. Modifying initial energy of a creature as a result of its genes (Ee) is in general not a good idea. Weight (Ww) works only in water, and in water sinking/going up should usually be caused by real "intentional" activity of a creature, not by its inherited weight. For assimilation (Aa), there is a dedicated parameter in CreaturesGroup. Stamina (Ss) is no longer needed as destructive collisions are not supported, and even if they were, some expdef would need to impose reasonable restrictions on the value of this parameter (e.g. similar to normalizeBiol4()) so there is some cost associated with it, and the specific consequences of destructions should be defined as needed.
17#define F14_MODIFIERS "LlRrCcQqFfMmIi" F14_MODIFIERS_RARE F14_MODIFIERS_VISUAL
18
19
20
21class GenePropsOp
22{
23public:
24        virtual ~GenePropsOp() {}
25        virtual double increase(double value) const = 0;
26        virtual double decrease(double value) const = 0;
27        void apply(double &value, char modif) const;
28};
29
30class GenePropsOp_Old : public GenePropsOp
31{
32        double minvalue, maxvalue, defvalue, change, revchange;
33public:
34        GenePropsOp_Old(double minvalue, double maxvalue, double defvalue, double change, double revchange = -1);
35        double increase(double value) const;
36        double decrease(double value) const;
37        friend class GenePropsOps_New05;
38};
39
40class GenePropsOp_NormalizedAndScaled : public GenePropsOp
41{
42        GenePropsOp_Old normalized;
43public:
44        GenePropsOp_NormalizedAndScaled(double change) :normalized(-1, 1, 0, change) {}
45        virtual double scale(double value) const { return value; }
46        virtual double scaleInv(double value) const { return value; }
47        double increase(double value) const { return scale(normalized.increase(scaleInv(value))); }
48        double decrease(double value) const { return scale(normalized.decrease(scaleInv(value))); }
49};
50
51class GenePropsOp_Exponential : public GenePropsOp_NormalizedAndScaled
52{
53        double a, b, c;
54        double log_a;
55        bool linear;
56public:
57        GenePropsOp_Exponential(double minvalue, double maxvalue, double defvalue, double change = 0.5);
58        double scale(double) const;
59        double scaleInv(double) const;
60};
61
62class GenePropsOps
63{
64public:
65        ~GenePropsOps();
66
67        GenePropsOp* length;
68        GenePropsOp* curvedness;
69        GenePropsOp* weight;
70        GenePropsOp* friction;
71        GenePropsOp* muscle_power;
72        GenePropsOp* assimilation;
73        GenePropsOp* stamina;
74        GenePropsOp* ingestion;
75        GenePropsOp* twist;
76        GenePropsOp* energy;
77        GenePropsOp* cred, *cgreen, *cblue;
78        bool use_normalizebiol4;
79};
80
81class GenePropsOps_Old : public GenePropsOps
82{
83public:
84        GenePropsOps_Old();
85};
86
87class GenePropsOps_New05 : public GenePropsOps_Old
88{
89public:
90        GenePropsOps_New05();
91};
92
93class GenePropsOps_Exponential : public GenePropsOps
94{
95public:
96        GenePropsOps_Exponential();
97};
98
99/**
100 * Contains physical, biological and other properties of
101 * stick, except for rotation. The constructor initializes properties of sticks with
102 * default values. In order to change a property of a stick, the executeModifier() method
103 * should be called. Modification of length, curvedness and twist properties
104 * usually affects further sticks, so new sticks should have properties of
105 * parents (prop) modified with the prop.propagateAlong() method.
106 * "Biological" properties (assimilation, stamina, muscle strength and
107 * ingestion) can be normalized after modification with normalizeBiol4().
108 */
109struct GeneProps
110{
111public:
112        double length;            ///<incremented by L, decremented by l. Physical property, length of stick
113        double curvedness;        ///<incremented by C, decremented by c. Curvedness of sticks
114        double weight;            ///<incremented by W, decremented by w. Physical property, weight of stick (in water environment light sticks swim on the surface)
115        double friction;          ///<incremented by F, decremented by f. Physical property, friction of a stick (sticks will slide on the ground or stick to it)
116
117        double muscle_power;      ///<incremented by M, decremented by m. Biological property, muscle strength (muscle speed). Strong muscles act with bigger force, gain higher speed, can resist bigger stress, and use more energy
118        double assimilation;      ///<incremented by A, decremented by a. Biological property, assimilation, photosynthesis (a vertical stick can assimilate twice as much as horizontal one)
119        double stamina;           ///<incremented by S, decremented by s. Biological property, stamina (increases chance of survival during fights)
120        double ingestion;         ///<incremented by I, decremented by i. Biological property, ingestion (ability to gain energy from food)
121
122        double twist;             ///<incremented by Q, decremented by q. Twist of a stick
123        double energy;            ///<incremented by E, decremented by e. Energy of a creature
124
125        double muscle_bend_range; ///<Used only by conv_f1
126        bool muscle_reset_range;  ///<Used only by conv_f1
127
128        double cred;              ///<incremented by D, decremented by d. Part's red color proportion
129        double cgreen;            ///<incremented by B, decremented by b. Part's blue color proportion
130        double cblue;             ///<incremented by G, decremented by g. Part's green color proportion
131
132        static GeneProps standard_values;
133        static GenePropsOps* standard_ops;
134        static GenePropsOps* getStandardOps();
135
136        /**
137         * Constructor initializing all properties with default values.
138         */
139        GeneProps();
140
141        /**
142         * Normalizes biological properties (muscle_power, assimilation, stamina, and ingestion).
143         * This method is called in executeModifier() when any of the biological properties is modified
144         * and \a use_normalizebiol4 is true. All values of those properties sum up to 1.
145         */
146        void normalizeBiol4();
147
148        /**
149         * Checks whether the given character is property modifier. If yes, the property
150         * is modified and properties are normalized when needed.
151         * @param modif character that might be a property modifier
152         * @return 0 if the provided character was property modifier, -1 otherwise
153         */
154        int executeModifier(char modif, GenePropsOps* ops = NULL);
155        int executeModifier_Legacy(char modif);
156
157        /**
158         * Adjusts current properties for the next stick. In order to set
159         * new properties to the created stick, the copy of the previous stick should be created,
160         * and propagateAlong() should be used for that copy.
161         * @param use_reset_range true if this method should modify muscle_bend_range (used in f1 conversion).
162         */
163        void propagateAlong(bool use_f1_muscle_reset_range);
164};
165
166#endif // _GENEPROPS_H
Note: See TracBrowser for help on using the repository browser.