detail::Configuration *Mechanoid::getConfiguration() { if (configuration) return configuration; // create new working configuration from the initial one // do not create new configuration while in db tool mode if (getSettings().flags[gfDbTool]) return initial_configuration; configuration = getStorage()->configurations.createAtEnd(*initial_configuration); configuration->deepCopyFrom(*initial_configuration); // to differ from initial configurations in DB Tool configuration->text_id += L" - " + getName(); // replace pointers auto c = replace<Configuration>(configuration.get()); for (auto &w : c->weapons) replace<ConfigurationWeapon>(w); // setup c->setMechanoid(this); c->armor = c->getMaxArmor(); c->energy = c->getMaxEnergy(); c->energy_shield = c->getMaxEnergyShield(); return configuration; }
// if you pass in -1's for x and y, we'll figure out where it can go, and return where it went int LogisticsVariant::canAddComponent( LogisticsComponent* pComponent, long& x, long& y ) const { /* weight no longer matters int weight = getWeight(); if ( weight + pComponent->getWeight() > chassis->maxWeight ) return COMPONENT_TOO_HEAVY;*/ if ( getHeat() + pComponent->getHeat() > getMaxHeat() ) return COMPONENT_TOO_HOT; if ( pComponent->getType() == COMPONENT_FORM_JUMPJET ) { if ( !chassis->canHaveJumpJets ) return JUMPJETS_NOT_ALLOWED; else if ( hasJumpJets() ) return ONLY_ONE_JUMPJET_ALLOWED; else if ( ( x!= -1 && x != -2) || ( y != -1 && y != -2 ) ) return COMPONENT_SLOT_FULL; return 0; } else if ( x == -2 && y == -2 ) // trying to put something illegal in jump jet slot return COMPONENT_SLOT_FULL; if ( x!= -1 && y != -1 ) { for ( int i = 0; i < pComponent->getComponentWidth(); i++ ) { for ( int j = 0; j < pComponent->getComponentHeight(); j++ ) { if ( getComponentAtLocation( x + i, y + j) || x + i >= chassis->componentAreaWidth || j + y >= chassis->componentAreaHeight ) return COMPONENT_SLOT_FULL; } } } else { for ( int j = 0; j < chassis->componentAreaHeight && x == -1; j++ ) { for ( int i = 0; i < chassis->componentAreaWidth && x == -1; i++ ) { if ( !getComponentAtLocation( i, j ) ) { bool bAdd = true; for ( int l = 0; l < pComponent->getComponentHeight(); ++l ) { for ( int k =0; k < pComponent->getComponentWidth(); ++k ) { if ( getComponentAtLocation( i +k, j + l ) || ( i + k >= chassis->componentAreaWidth ) || ( j +l >= chassis->componentAreaHeight ) ) { bAdd = false; break; break; } } } if ( bAdd ) { x = i; y = j; } } } } if ( x == -1 || y == -1 ) { return ADD_COMPONENT_FAILED; } } if ( pComponent->getType() == COMPONENT_FORM_BULK ) { if ( getArmor() + 32 > getMaxArmor() ) return NO_MORE_ARMOR; } if ( pComponent->getType() == COMPONENT_FORM_SENSOR ) { if ( !chassis->canHaveAdvSensor ) return SENSORS_NOT_ALLOWED; else if ( hasSensor() ) return ONLY_ONE_SENSOR_ALLOWED; } if ( pComponent->getType() == COMPONENT_FORM_ECM ) { if ( !chassis->canHaveECM ) return ECM_NOT_ALLOWED; else if ( hasECM() ) return ONLY_ONE_ECM_ALLOWED; } return 0; }