1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include "autoname.h" |
---|
6 | #include "common/nonstd_stl.h" |
---|
7 | #include <ctype.h> |
---|
8 | |
---|
9 | SString AutoName::makeName(Model &model) |
---|
10 | { |
---|
11 | SString t; |
---|
12 | t=firstName(model); |
---|
13 | t+=' '; |
---|
14 | t+=lastName(model); |
---|
15 | return t; |
---|
16 | } |
---|
17 | |
---|
18 | /////////////////////////// |
---|
19 | |
---|
20 | static char* cat_syl(char* str,unsigned int x) |
---|
21 | { |
---|
22 | static char sp[]="bcdfghklmnprstwz",sa[]="aeiouy"; |
---|
23 | x%=6*16; |
---|
24 | str[0]=sa[x%6]; |
---|
25 | if (x>5) |
---|
26 | {str[1]=sp[x/6]; str[2]=0; return str+2;} |
---|
27 | else |
---|
28 | {str[1]=0; return str+1;} |
---|
29 | } |
---|
30 | |
---|
31 | SString AutoName::firstName(Model& model) |
---|
32 | { |
---|
33 | char buf[8]; |
---|
34 | unsigned int s1=0,s2=0,s3=0; |
---|
35 | const char *x=model.getGeno().getGene(); |
---|
36 | for (;*x;x++) { s1+=*x; s2=s2**x+*x; s3=(s3^*x)+*x; } |
---|
37 | char* t=buf; |
---|
38 | t=cat_syl(t,s1); |
---|
39 | t=cat_syl(t,s2); |
---|
40 | t=cat_syl(t,s3); |
---|
41 | buf[0]=(char)toupper(buf[0]); |
---|
42 | return SString(buf); |
---|
43 | } |
---|
44 | |
---|
45 | static void przeplatanka(char *out,char *in1,char *in2) |
---|
46 | { |
---|
47 | int d1=strlen(in1),d2=strlen(in2); |
---|
48 | int p1=0,p2=0; |
---|
49 | int pp=d1+d2; |
---|
50 | int i,p; |
---|
51 | if (d2<d1) |
---|
52 | { |
---|
53 | int t=d2; d2=d1; d1=t; |
---|
54 | char *c=in1; in1=in2; in2=c; |
---|
55 | } |
---|
56 | if (pp) |
---|
57 | for (i=0;i<=pp;i++) |
---|
58 | { |
---|
59 | p=(i*d1)/pp-1; for (;p1<=p;p1++) *(out++)=*(in1++); |
---|
60 | p=(i*d2)/pp-1; for (;p2<=p;p2++) *(out++)=*(in2++); |
---|
61 | } |
---|
62 | *out=0; |
---|
63 | } |
---|
64 | |
---|
65 | SString AutoName::lastName(Model& model) |
---|
66 | { |
---|
67 | char Sam[]="yeaou"; |
---|
68 | char Sp[]="shtkdgmr"; |
---|
69 | |
---|
70 | #define NAME_MAXLENBODY 5 |
---|
71 | #define NAME_MAXLENBRAIN 5 |
---|
72 | #define NAME_BODYLEN 0.8 |
---|
73 | #define NAME_BRAINLEN 0.8 |
---|
74 | #define NAME_BODYMASS 1.0 |
---|
75 | #define NAME_BRAININP 1.0 |
---|
76 | |
---|
77 | char naz[NAME_MAXLENBODY+NAME_MAXLENBRAIN+1]; |
---|
78 | int poz,nextpoz,i; |
---|
79 | |
---|
80 | double w; |
---|
81 | int cialo=-1; |
---|
82 | int mozg=-1; |
---|
83 | |
---|
84 | char tmpc[NAME_MAXLENBODY+1],tmpm[NAME_MAXLENBRAIN+1]; |
---|
85 | |
---|
86 | if (model.getPartCount()>0) |
---|
87 | { |
---|
88 | cialo=min((int)(sqrt(double(model.getPartCount())-1)*NAME_BODYLEN),NAME_MAXLENBODY-1); |
---|
89 | poz=0; |
---|
90 | for (i=0;i<=cialo;i++) // budowanie "opisu" ciala |
---|
91 | { |
---|
92 | nextpoz=((model.getPartCount())*(i+1))/(cialo+1)-1; |
---|
93 | w=1.0; |
---|
94 | for (;poz<=nextpoz;poz++) w=max(w,model.getPart(poz)->mass); |
---|
95 | tmpc[i]=Sp[min(int((w-1.0)*NAME_BODYMASS),int(sizeof(Sp))-2)]; |
---|
96 | } |
---|
97 | tmpc[i]=0; |
---|
98 | } |
---|
99 | else tmpc[0]=0; |
---|
100 | |
---|
101 | int wint; |
---|
102 | |
---|
103 | if (model.getNeuroCount()>0) |
---|
104 | { |
---|
105 | mozg=min((int)(sqrt((double)model.getNeuroCount())*NAME_BRAINLEN),NAME_MAXLENBRAIN-1); |
---|
106 | poz=0; |
---|
107 | for (i=0;i<=mozg;i++) // budowanie "opisu" mozgu |
---|
108 | { |
---|
109 | nextpoz=(model.getNeuroCount()*(i+1))/(mozg+1)-1; |
---|
110 | wint=0; |
---|
111 | for (;poz<=nextpoz;poz++) wint=max(wint,model.getNeuro(poz)->getInputCount()); |
---|
112 | tmpm[i]=Sam[min(int(wint*NAME_BRAININP),int(sizeof(Sam))-2)]; |
---|
113 | } |
---|
114 | tmpm[i]=0; |
---|
115 | } |
---|
116 | else tmpm[0]=0; |
---|
117 | |
---|
118 | if ((mozg+1) < ((cialo+2)/2)) |
---|
119 | { |
---|
120 | for (i=mozg+1;i<=cialo/2;i++) tmpm[i]='i'; |
---|
121 | tmpm[i]=0; |
---|
122 | } |
---|
123 | |
---|
124 | przeplatanka(naz,tmpc,tmpm); |
---|
125 | |
---|
126 | naz[0]=(char)toupper(naz[0]); |
---|
127 | return SString(naz); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | |
---|