bool GeneticSpawnBodypartAction::execute() { Bodypart* bp = new Bodypart(childBodypartType,parentBodypart->getGeneticCode()->copy(),parentBodypart->getParentOrganism(),parentBodypart); if(parentBodypart->spawnBodypart(bp)) { return true; } else { bp->destroy(); delete bp; return false; } };
bool GeneticSpawnParentAction::execute() { Bodypart* parent = bp->getParentBodypart(); if(parent != 0) { SpawnpointInformation* spawnpoint = bp->getSpawnpointInformationForBodypart(parent); SpawnpointInformation* parentSpawnpoint = parent->getSpawnpointInformationForBodypart(bp); parent->unregisterChildBodypart(bp); RuntimeManager* runtime = 0; Organism* org = bp->getParentOrganism(); if(org != 0) { //remove storage link, but not the processor org->unregisterBodypart(bp); runtime = org->getRuntimeManager(); runtime->unregisterBodypart(bp); } Bodypart* newParent = new Bodypart(typeToSpawn,parent->getGeneticCode()->copy()); if(newParent->spawnPointAvailable(bp->getBodypartType()) && parent->spawnBodypart(newParent,parentSpawnpoint)) { newParent->spawnBodypart(bp,0,spawnpoint); //prevent spawn from registering processor at organism, but register new storage links return true; } else { newParent->destroy(); if(runtime) { runtime->addDelete(newParent); } else { delete newParent; } parent->spawnBodypart(bp,parentSpawnpoint,spawnpoint); //prevent spawn from registering processor return false; } } else { return false; } };