//similar to Ship.createSpaceStation(), but not easily generalizable public bool build2(int shipTemplateId, int _userId, int _colonyId, bool fastBuild, ref int newShipId, ref ShipBuildErrorCode errorCode, ref int errorValue) { Core core = Core.Instance; GalaxyMap galaxyMap = null; // lock colony and field Colony colony = core.colonies[_colonyId]; if (colony == null) { return(false); } if (colony.userId != _userId) { return(false); } Field field = colony.field; ShipTemplate template = core.shipTemplate[shipTemplateId]; if (!(this.checkFreeOrbit(field, _userId, colony.systemXY(), ref errorCode, ref errorValue) && this.checkGoodsAvailability(colony, template, fastBuild, ref errorCode, ref errorValue) && this.checkSpaceport(colony, ref errorCode, ref errorValue) && this.checkTechnology(template, _userId, fastBuild, ref errorCode, ref errorValue) && this.checkUniqueness(field, template, colony.systemXY(), ref errorCode, ref errorValue))) { return(false); } //Lock List <Lockable> elementsToLock = new List <Lockable>(3); elementsToLock.Add(colony); elementsToLock.Add(field); //check for transcendence //ToDo: replace 220 with a sql data field if (template.hullid == 220 && core.GalaxyMap.transcendenceRequirement == 0) { galaxyMap = core.GalaxyMap; elementsToLock.Add(galaxyMap); } if (!LockingManager.lockAllOrSleep(elementsToLock)) { return(false); } newShipId = (int)Core.Instance.identities.shipLock.getNext(); try { //all checks again inside of lock if (!(this.checkFreeOrbit(field, _userId, colony.systemXY(), ref errorCode, ref errorValue) && this.checkGoodsAvailability(colony, template, fastBuild, ref errorCode, ref errorValue) && this.checkSpaceport(colony, ref errorCode, ref errorValue) && this.checkTechnology(template, _userId, fastBuild, ref errorCode, ref errorValue) && this.checkUniqueness(field, template, colony.systemXY(), ref errorCode, ref errorValue))) { return(false); } //everything checked and locked //now do the work Ship newShip = buildShip(newShipId, template, field, _userId, colony, fastBuild); newShip.SetTranscension(galaxyMap); //write SQL Core.Instance.dataConnection.insertShip(newShip); Core.Instance.dataConnection.saveColonyGoods(colony); } catch (Exception ex) { SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex); } finally { //release the ressources LockingManager.unlockAll(elementsToLock); } return(true); }