Index: cpp/frams/model/model.cpp
===================================================================
--- cpp/frams/model/model.cpp	(revision 815)
+++ cpp/frams/model/model.cpp	(revision 896)
@@ -1,4 +1,4 @@
 // This file is a part of Framsticks SDK.  http://www.framsticks.com/
-// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
+// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
 // See LICENSE.txt for details.
 
@@ -83,9 +83,9 @@
 	updateRefno();
 	if (using_checkpoints)
-		for (vector<Model*>::const_iterator it = mod.checkpoints.begin(); it != mod.checkpoints.end(); it++)
-		{
-		Model *m = *it;
-		Model *n = new Model(*m, m->autobuildmaps, false, true);
-		checkpoints.push_back(n);
+		for (vector<Model *>::const_iterator it = mod.checkpoints.begin(); it != mod.checkpoints.end(); it++)
+		{
+			Model *m = *it;
+			Model *n = new Model(*m, m->autobuildmaps, false, true);
+			checkpoints.push_back(n);
 		}
 }
@@ -152,9 +152,9 @@
 void Model::clear()
 {
-	FOREACH(Part*, p, parts)
+	FOREACH(Part *, p, parts)
 		delete p;
-	FOREACH(Joint*, j, joints)
+	FOREACH(Joint *, j, joints)
 		delete j;
-	FOREACH(Neuro*, n, neurons)
+	FOREACH(Neuro *, n, neurons)
 		delete n;
 	parts.clear(); joints.clear(); neurons.clear();
@@ -164,5 +164,5 @@
 	geno = Geno();
 	f0geno = Geno();
-	for (vector<Model*>::iterator it = checkpoints.begin(); it != checkpoints.end(); it++)
+	for (vector<Model *>::iterator it = checkpoints.begin(); it != checkpoints.end(); it++)
 		delete *it;
 	checkpoints.clear();
@@ -195,5 +195,5 @@
 void Model::removeNeuros(SList &nlist)
 {
-	FOREACH(Neuro*, nu, nlist)
+	FOREACH(Neuro *, nu, nlist)
 	{
 		int i = findNeuro(nu);
@@ -209,5 +209,5 @@
 		SList jlist;
 		findJoints(jlist, p);
-		FOREACH(Joint*, j, jlist)
+		FOREACH(Joint *, j, jlist)
 		{
 			int i = findJoint(j);
@@ -240,11 +240,11 @@
 void Model::removeNeuro(int neuroindex, bool removereferences)
 {
-	Neuro* thisN = getNeuro(neuroindex);
+	Neuro *thisN = getNeuro(neuroindex);
 
 	if (removereferences)
 	{
-		Neuro* n;
+		Neuro *n;
 		// remove all references to thisN
-		for (int i = 0; n = (Neuro*)neurons(i); i++)
+		for (int i = 0; n = (Neuro *)neurons(i); i++)
 		{
 			Neuro *inp;
@@ -252,6 +252,6 @@
 				if (inp == thisN)
 				{
-				n->removeInput(j);
-				j--;
+					n->removeInput(j);
+					j--;
 				}
 		}
@@ -262,5 +262,5 @@
 }
 
-MultiMap& Model::getMap()
+MultiMap &Model::getMap()
 {
 	if (!map) map = new MultiMap();
@@ -277,5 +277,5 @@
 }
 
-void Model::makeGenToGenMap(MultiMap& result, const MultiMap& gen1tomodel, const MultiMap& gen2tomodel)
+void Model::makeGenToGenMap(MultiMap &result, const MultiMap &gen1tomodel, const MultiMap &gen2tomodel)
 {
 	result.clear();
@@ -285,9 +285,9 @@
 }
 
-void Model::getCurrentToF0Map(MultiMap& result)
+void Model::getCurrentToF0Map(MultiMap &result)
 {
 	result.clear();
 	if (!map) return;
-	const MultiMap& f0m = getF0Map();
+	const MultiMap &f0m = getF0Map();
 	makeGenToGenMap(result, *map, f0m);
 }
@@ -312,12 +312,12 @@
 }
 
-Model::ItemType Model::itemTypeFromLinePrefix(const char* line)
-{
-	struct PrefixAndItem { const char* prefix; ItemType type; };
+Model::ItemType Model::itemTypeFromLinePrefix(const char *line)
+{
+	struct PrefixAndItem { const char *prefix; ItemType type; };
 	static const PrefixAndItem types[] = { { "m:", ModelType }, { "p:", PartType }, { "j:", JointType }, { "n:", NeuronType }, { "c:", NeuronConnectionType }, { F0_CHECKPOINT_LINE, CheckpointType }, { NULL } };
 	for (const PrefixAndItem *t = types; t->prefix != NULL; t++)
 	{
-		const char* in = line;
-		const char* pattern = t->prefix;
+		const char *in = line;
+		const char *pattern = t->prefix;
 		for (; *in == *pattern; in++, pattern++)
 			if (*pattern == ':')
@@ -355,5 +355,5 @@
 	for (; f0txt.getNextToken(pos, line, '\n'); lnum++)
 	{
-		const char* line_ptr = line.c_str();
+		const char *line_ptr = line.c_str();
 		for (; *line_ptr; line_ptr++)
 			if (!strchr(" \r\t", *line_ptr)) break;
@@ -361,5 +361,5 @@
 		if (!*line_ptr) continue;
 
-		const char* colon = strchr(line_ptr, ':');
+		const char *colon = strchr(line_ptr, ':');
 		ItemType type = UnknownType;
 		SString excluding_prefix;
@@ -414,5 +414,5 @@
 }
 
-const MultiMap& Model::getF0Map()
+const MultiMap &Model::getF0Map()
 {
 	if (!f0map)
@@ -472,5 +472,5 @@
 	}
 
-	for (i = 0; p = (Part*)parts(i); i++)
+	for (i = 0; p = (Part *)parts(i); i++)
 	{
 		partparam.select(p);
@@ -481,5 +481,5 @@
 			map->add(len, gen.len() - 1, partToMap(i));
 	}
-	for (i = 0; j = (Joint*)joints(i); i++)
+	for (i = 0; j = (Joint *)joints(i); i++)
 	{
 		jointparam.select(j);
@@ -491,5 +491,5 @@
 			map->add(len, gen.len() - 1, jointToMap(i));
 	}
-	for (i = 0; n = (Neuro*)neurons(i); i++)
+	for (i = 0; n = (Neuro *)neurons(i); i++)
 	{
 		neuroparam.select(n);
@@ -502,5 +502,5 @@
 	for (a = 0; a < neurons.size(); a++)
 	{ // inputs
-		n = (Neuro*)neurons(a);
+		n = (Neuro *)neurons(a);
 		//	if ((n->getInputCount()==1)&&(n->getInput(0).refno <= n->refno))
 		//		continue; // already done with Neuro::conn_refno
@@ -510,5 +510,5 @@
 			double w;
 			NeuroConn nc;
-			Neuro* n2 = n->getInput(b, w);
+			Neuro *n2 = n->getInput(b, w);
 			//		if (((n2.parentcount==1)&&(n2.parent)&&(n2.parent->refno < n2.refno)) ^ 
 			//		    (n2.neuro_refno>=0))
@@ -533,5 +533,5 @@
 	}
 
-	for (vector<Model*>::const_iterator it = checkpoints.begin(); it != checkpoints.end(); it++)
+	for (vector<Model *>::const_iterator it = checkpoints.begin(); it != checkpoints.end(); it++)
 	{
 		Geno g = (*it)->getF0Geno();
@@ -562,5 +562,5 @@
 }
 
-Model* Model::getCheckpoint(int i)
+Model *Model::getCheckpoint(int i)
 {
 	return checkpoints[i];
@@ -575,5 +575,5 @@
 }
 
-void Model::setGeno(const Geno& newgeno)
+void Model::setGeno(const Geno &newgeno)
 {
 	geno = newgeno;
@@ -586,9 +586,9 @@
 	delMap();
 	delF0Map();
-	for (i = 0; p = (Part*)parts(i); i++)
+	for (i = 0; p = (Part *)parts(i); i++)
 		p->clearMapping();
-	for (i = 0; j = (Joint*)joints(i); i++)
+	for (i = 0; j = (Joint *)joints(i); i++)
 		j->clearMapping();
-	for (i = 0; n = (Neuro*)neurons(i); i++)
+	for (i = 0; n = (Neuro *)neurons(i); i++)
 		n->clearMapping();
 }
@@ -607,11 +607,11 @@
 			Part *p; Joint *j; Neuro *n;
 			int i;
-			for (i = 0; p = (Part*)parts(i); i++)
+			for (i = 0; p = (Part *)parts(i); i++)
 				if (p->getMapping())
 					map->add(*p->getMapping(), partToMap(i));
-			for (i = 0; j = (Joint*)joints(i); i++)
+			for (i = 0; j = (Joint *)joints(i); i++)
 				if (j->getMapping())
 					map->add(*j->getMapping(), jointToMap(i));
-			for (i = 0; n = (Neuro*)neurons(i); i++)
+			for (i = 0; n = (Neuro *)neurons(i); i++)
 				if (n->getMapping())
 					map->add(*n->getMapping(), neuroToMap(i));
@@ -629,5 +629,5 @@
 }
 
-Pt3D Model::whereDelta(const Part& start, const Pt3D& rot, const Pt3D& delta)
+Pt3D Model::whereDelta(const Part &start, const Pt3D &rot, const Pt3D &delta)
 {
 	Orient roto;
@@ -641,10 +641,10 @@
 }
 
-int Model::addFromString(ItemType item_type, const SString &singleline, const MultiRange* srcrange)
+int Model::addFromString(ItemType item_type, const SString &singleline, const MultiRange *srcrange)
 {
 	return addFromString(item_type, singleline, 0, srcrange);
 }
 
-int Model::addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange* srcrange)
+int Model::addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange *srcrange)
 {
 	SString error_message;
@@ -654,5 +654,5 @@
 		if (error_message.len() == 0) // generic error when no detailed message is available
 			error_message = "Invalid f0 code";
-		if (line_num>0)
+		if (line_num > 0)
 			error_message += SString::sprintf(", line #%d", line_num);
 		error_message += nameForErrors();
@@ -662,5 +662,5 @@
 }
 
-int Model::addFromStringNoLog(ItemType item_type, const SString &line, SString& error_message, const MultiRange* srcrange)
+int Model::addFromStringNoLog(ItemType item_type, const SString &line, SString &error_message, const MultiRange *srcrange)
 {
 	error_message = SString::empty();
@@ -831,5 +831,5 @@
 SString Model::nameForErrors() const
 {
-	if (geno.getName().len()>0)
+	if (geno.getName().len() > 0)
 		return SString::sprintf(" in '%s'", geno.getName().c_str());
 	return SString::empty();
@@ -850,8 +850,8 @@
 	else
 	{
-		Pt3D bbmin = ((Part*)parts(0))->p, bbmax = bbmin;
+		Pt3D bbmin = ((Part *)parts(0))->p, bbmax = bbmin;
 		for (i = 0; i < parts.size(); i++)
 		{
-			p = (Part*)parts(i);
+			p = (Part *)parts(i);
 			p->owner = this;
 			if (checklevel > 0)
@@ -894,5 +894,5 @@
 		for (i = 0; i < joints.size(); i++)
 		{
-			j = (Joint*)joints(i);
+			j = (Joint *)joints(i);
 			// VALIDMINMAX are managed manually when adding joint properties in f0-def!
 			// (could be made dynamic but not really worth the effort)
@@ -979,5 +979,5 @@
 	for (i = 0; i < neurons.size(); i++)
 	{
-		n = (Neuro*)neurons(i);
+		n = (Neuro *)neurons(i);
 		n->part_refno = (n->part) ? n->part->refno : -1;
 		n->joint_refno = (n->joint) ? n->joint->refno : -1;
@@ -991,5 +991,5 @@
 			for (i = 0; i < parts.size(); i++)
 			{
-				p = (Part*)parts(i);
+				p = (Part *)parts(i);
 				if (p->mass <= 0.001)
 					p->mass = 1.0;
@@ -1003,8 +1003,8 @@
 				for (i = 0; i < joints.size(); i++)
 				{
-					j = (Joint*)joints(i);
-					if (j->part1->flags&LINKFLAG)
+					j = (Joint *)joints(i);
+					if (j->part1->flags & LINKFLAG)
 					{
-						if (!(j->part2->flags&LINKFLAG))
+						if (!(j->part2->flags & LINKFLAG))
 						{
 							change = 1;
@@ -1013,11 +1013,11 @@
 					}
 					else
-						if (j->part2->flags&LINKFLAG)
+						if (j->part2->flags & LINKFLAG)
 						{
-						if (!(j->part1->flags&LINKFLAG))
-						{
-							change = 1;
-							j->part1->flags |= LINKFLAG;
-						}
+							if (!(j->part1->flags & LINKFLAG))
+							{
+								change = 1;
+								j->part1->flags |= LINKFLAG;
+							}
 						}
 				}
@@ -1025,6 +1025,6 @@
 			for (i = 0; i < parts.size(); i++)
 			{
-				p = (Part*)parts(i);
-				if (!(p->flags&LINKFLAG))
+				p = (Part *)parts(i);
+				if (!(p->flags & LINKFLAG))
 				{
 					logPrintf("Model", "internalCheck", LOG_ERROR, "Not all parts connected (eg. Part #0 and Part #%d)%s", i, nameForErrors().c_str());
@@ -1037,5 +1037,5 @@
 		for (i = 0; i < joints.size(); i++)
 		{
-			j = (Joint*)joints(i);
+			j = (Joint *)joints(i);
 			if (j->p1_refno == j->p2_refno)
 			{
@@ -1046,5 +1046,5 @@
 			for (k = i + 1; k < joints.size(); k++)
 			{
-				Joint* j2 = (Joint*)joints(k);
+				Joint *j2 = (Joint *)joints(k);
 				if (((j->p1_refno == j2->p1_refno) && (j->p2_refno == j2->p2_refno))
 					|| ((j->p1_refno == j2->p2_refno) && (j->p2_refno == j2->p1_refno)))
@@ -1073,5 +1073,5 @@
 }
 
-const Geno& Model::getGeno() const
+const Geno &Model::getGeno() const
 {
 	return geno;
@@ -1106,7 +1106,7 @@
 }
 
-Part* Model::getPart(int i) const
-{
-	return ((Part*)parts(i));
+Part *Model::getPart(int i) const
+{
+	return ((Part *)parts(i));
 }
 
@@ -1116,30 +1116,30 @@
 }
 
-Joint* Model::getJoint(int i) const
-{
-	return ((Joint*)joints(i));
-}
-
-int Model::findJoints(SList& result, const Part* part)
+Joint *Model::getJoint(int i) const
+{
+	return ((Joint *)joints(i));
+}
+
+int Model::findJoints(SList &result, const Part *part)
 {
 	Joint *j;
 	int n0 = result.size();
 	if (part)
-		for (int i = 0; j = (Joint*)joints(i); i++)
-			if ((j->part1 == part) || (j->part2 == part)) result += (void*)j;
+		for (int i = 0; j = (Joint *)joints(i); i++)
+			if ((j->part1 == part) || (j->part2 == part)) result += (void *)j;
 	return result.size() - n0;
 }
 
-int Model::findNeuro(Neuro* n)
+int Model::findNeuro(Neuro *n)
 {
 	return neurons.find(n);
 }
 
-int Model::findPart(Part* p)
+int Model::findPart(Part *p)
 {
 	return parts.find(p);
 }
 
-int Model::findJoint(Joint* j)
+int Model::findJoint(Joint *j)
 {
 	return joints.find(j);
@@ -1148,5 +1148,5 @@
 int Model::findJoint(Part *p1, Part *p2)
 {
-	Joint* j;
+	Joint *j;
 	for (int i = 0; j = getJoint(i); i++)
 		if ((j->part1 == p1) && (j->part2 == p2)) return i;
@@ -1161,7 +1161,7 @@
 }
 
-Neuro* Model::getNeuro(int i) const
-{
-	return (Neuro*)neurons(i);
+Neuro *Model::getNeuro(int i) const
+{
+	return (Neuro *)neurons(i);
 }
 
@@ -1174,11 +1174,11 @@
 }
 
-int Model::findNeuros(SList& result,
-	const char* classname, const Part* part, const Joint* joint)
+int Model::findNeuros(SList &result,
+	const char *classname, const Part *part, const Joint *joint)
 {
 	Neuro *nu;
 	SString cn(classname);
 	int n0 = result.size();
-	for (int i = 0; nu = (Neuro*)neurons(i); i++)
+	for (int i = 0; nu = (Neuro *)neurons(i); i++)
 	{
 		if (part)
@@ -1188,5 +1188,5 @@
 		if (classname)
 			if (nu->getClassName() != cn) continue;
-		result += (void*)nu;
+		result += (void *)nu;
 	}
 	return result.size() - n0;
@@ -1202,7 +1202,7 @@
 	{
 		Part *p = getPart(i);
-		p->p.x += (rnd01 - 0.5)*amount;
-		p->p.y += (rnd01 - 0.5)*amount;
-		p->p.z += (rnd01 - 0.5)*amount;
+		p->p.x += (rndDouble(1) - 0.5) * amount;
+		p->p.y += (rndDouble(1) - 0.5) * amount;
+		p->p.z += (rndDouble(1) - 0.5) * amount;
 	}
 	for (i = 0; i < joints.size(); i++)
@@ -1215,13 +1215,13 @@
 }
 
-void Model::move(const Pt3D& shift)
-{
-	FOREACH(Part*, p, parts)
+void Model::move(const Pt3D &shift)
+{
+	FOREACH(Part *, p, parts)
 		p->p += shift;
 }
 
-void Model::rotate(const Orient& rotation)
-{
-	FOREACH(Part*, p, parts)
+void Model::rotate(const Orient &rotation)
+{
+	FOREACH(Part *, p, parts)
 	{
 		p->p = rotation.transform(p->p);
@@ -1230,5 +1230,5 @@
 }
 
-void Model::buildUsingSolidShapeTypes(const Model& src_ballandstick_shapes, Part::Shape use_shape, double thickness)
+void Model::buildUsingSolidShapeTypes(const Model &src_ballandstick_shapes, Part::Shape use_shape, double thickness)
 {
 	for (int i = 0; i < src_ballandstick_shapes.getJointCount(); i++)
@@ -1247,9 +1247,9 @@
 		for (int i = 0; i < src_ballandstick_shapes.getPartCount(); i++)
 		{
-		Part *op = src_ballandstick_shapes.getPart(i);
-		Part *p = addNewPart(Part::SHAPE_ELLIPSOID); //always using spherical shape regardless of the 'use_shape' parameter - 'use shape' is meant for sticks!
-		p->p = op->p;
-		p->rot = op->rot;
-		p->scale.x = p->scale.y = p->scale.z = thickness;
+			Part *op = src_ballandstick_shapes.getPart(i);
+			Part *p = addNewPart(Part::SHAPE_ELLIPSOID); //always using spherical shape regardless of the 'use_shape' parameter - 'use shape' is meant for sticks!
+			p->p = op->p;
+			p->rot = op->rot;
+			p->scale.x = p->scale.y = p->scale.z = thickness;
 		}
 	for (int i = 0; i < src_ballandstick_shapes.getPartCount(); i++)
@@ -1275,5 +1275,5 @@
 }
 
-SolidsShapeTypeModel::SolidsShapeTypeModel(Model& m, Part::Shape use_shape, double thickness)
+SolidsShapeTypeModel::SolidsShapeTypeModel(Model &m, Part::Shape use_shape, double thickness)
 {
 	using_model = converted_model = NULL;
@@ -1334,11 +1334,11 @@
 class MaxNeuro : public Neuro { public: MaxNeuro() { Param par(f0_neuro_paramtab, this); par.setMax(); } };
 
-Part& Model::getMinPart() { static MinPart part; return part; }
-Part& Model::getMaxPart() { static MaxPart part; return part; }
-Part& Model::getDefPart() { static Part part; return part; }
-Joint& Model::getMinJoint() { static MinJoint joint; return joint; }
-Joint& Model::getMaxJoint() { static MaxJoint joint; return joint; }
-Joint& Model::getDefJoint() { static Joint joint; return joint; }
-Neuro& Model::getMinNeuro() { static MinNeuro neuro; return neuro; }
-Neuro& Model::getMaxNeuro() { static MaxNeuro neuro; return neuro; }
-Neuro& Model::getDefNeuro() { static Neuro neuro; return neuro; }
+Part &Model::getMinPart() { static MinPart part; return part; }
+Part &Model::getMaxPart() { static MaxPart part; return part; }
+Part &Model::getDefPart() { static Part part; return part; }
+Joint &Model::getMinJoint() { static MinJoint joint; return joint; }
+Joint &Model::getMaxJoint() { static MaxJoint joint; return joint; }
+Joint &Model::getDefJoint() { static Joint joint; return joint; }
+Neuro &Model::getMinNeuro() { static MinNeuro neuro; return neuro; }
+Neuro &Model::getMaxNeuro() { static MaxNeuro neuro; return neuro; }
+Neuro &Model::getDefNeuro() { static Neuro neuro; return neuro; }
