MCPcopy Create free account
hub / github.com/DFHack/dfhack / diggingInvadersCommand

Function diggingInvadersCommand

plugins/diggingInvaders/diggingInvaders.cpp:210–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210command_result diggingInvadersCommand(color_ostream& out, std::vector<std::string>& parameters) {
211 for ( size_t a = 0; a < parameters.size(); a++ ) {
212 if ( parameters[a] == "1" || parameters[a] == "enable" ) {
213 plugin_enable(out,true);
214 } else if ( parameters[a] == "0" || parameters[a] == "disable" ) {
215 plugin_enable(out,false);
216 } else if ( parameters[a] == "add" || parameters[a] == "remove" ) {
217 if ( a+1 >= parameters.size() )
218 return CR_WRONG_USAGE;
219 string race = parameters[a+1];
220 if ( parameters[a] == "add" ) {
221 diggingRaces.insert(race);
222 DigAbilities& abilities = digAbilities[race];
223 memcpy(abilities.costWeight, costWeightDefault, costDim*sizeof(cost_t));
224 memcpy(abilities.jobDelay, jobDelayDefault, costDim*sizeof(int32_t));
225 } else {
226 diggingRaces.erase(race);
227 digAbilities.erase(race);
228 }
229 a++;
230
231 } else if ( parameters[a] == "setCost" || parameters[a] == "setDelay" ) {
232 if ( a+3 >= parameters.size() )
233 return CR_WRONG_USAGE;
234
235 string raceString = parameters[a+1];
236 if ( digAbilities.find(raceString) == digAbilities.end() ) {
237 DigAbilities bob;
238 memset(&bob, 0xFF, sizeof(bob));
239 digAbilities[raceString] = bob;
240 }
241 DigAbilities& abilities = digAbilities[raceString];
242
243 string costStr = parameters[a+2];
244 int32_t costDim = -1;
245 if ( costStr == "walk" ) {
246 costDim = CostDimension::Walk;
247 if ( parameters[a] == "setDelay" )
248 return CR_WRONG_USAGE;
249 } else if ( costStr == "destroyBuilding" ) {
250 costDim = CostDimension::DestroyBuilding;
251 } else if ( costStr == "dig" ) {
252 costDim = CostDimension::Dig;
253 } else if ( costStr == "destroyRoughConstruction" ) {
254 costDim = CostDimension::DestroyRoughConstruction;
255 } else if ( costStr == "destroySmoothConstruction" ) {
256 costDim = CostDimension::DestroySmoothConstruction;
257 } else {
258 return CR_WRONG_USAGE;
259 }
260
261 cost_t value;
262 stringstream asdf(parameters[a+3]);
263 asdf >> value;
264 //if ( parameters[a] == "setCost" && value <= 0 )
265 // return CR_WRONG_USAGE;
266 if ( parameters[a] == "setCost" ) {
267 abilities.costWeight[costDim] = value;

Callers

nothing calls this directly

Calls 9

getEdgeCostFunction · 0.85
findAndAssignInvasionJobFunction · 0.85
sizeMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
findMethod · 0.45
endMethod · 0.45
printMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected