Ticket #2189: rallypointCleaning.diff
File rallypointCleaning.diff, 7.7 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
185 185 if (!entState) 186 186 return {"possible": false}; 187 187 188 // If the selection isn't friendly units, no action189 var playerID = Engine.GetPlayerID();190 var allOwnedByPlayer = selection.every(function(ent) {191 var entState = GetEntityState(ent);192 return entState && entState.player == playerID;193 });194 195 if (!g_DevSettings.controlAll && !allOwnedByPlayer)196 return {"possible": false};197 198 // Work out whether the selection can have rally points199 var haveRallyPoints = selection.every(function(ent) {200 var entState = GetEntityState(ent);201 return entState && entState.rallyPoint;202 });203 204 // Work out whether at least part of the selection have UnitAI205 var haveUnitAI = selection.some(function(ent) {206 var entState = GetEntityState(ent);207 return entState && entState.unitAI;208 });209 210 188 if (!target) 211 189 { 212 if (action == "set-rallypoint" && haveRallyPoints)190 if (action == "set-rallypoint") 213 191 { 214 192 var cursor = ""; 215 193 var data = {command: "walk"}; … … 220 198 } 221 199 return {"possible": true, "data": data, "cursor": cursor}; 222 200 } 223 else if ( haveUnitAI && (action == "move" || action == "attack-move"))201 else if (action == "move" || action == "attack-move") 224 202 return {"possible": true}; 225 203 else 226 204 return {"possible": false}; 227 205 } 228 206 229 if ( haveRallyPoints && selection.indexOf(target) != -1 && action == "unset-rallypoint")207 if (action == "unset-rallypoint" && selection.indexOf(target) != -1) 230 208 return {"possible": true}; 231 209 232 210 // Look at the first targeted entity … … 235 213 var targetState = GetEntityState(target); 236 214 237 215 // Look to see what type of command units going to the rally point should use 238 if ( haveRallyPoints &&action == "set-rallypoint")216 if (action == "set-rallypoint") 239 217 { 240 // haveRallyPoints ensures all selected entities can have rally points.241 218 // We assume that all entities are owned by the same player. 242 219 var entState = GetEntityState(selection[0]); 243 220 … … 248 225 var enemyOwned = playerState.isEnemy[targetState.player]; 249 226 var gaiaOwned = (targetState.player == 0); 250 227 251 var cursor = "";252 228 var tooltip; 253 254 // default to walking there 229 // default to walking there (or attack-walking if hotkey pressed) 255 230 var data = {command: "walk"}; 231 var cursor = ""; 256 232 if (Engine.HotkeyIsPressed("session.attackmove")) 257 233 { 258 234 data = {command: "attack-walk"}; … … 273 249 { 274 250 var resourceType = targetState.resourceSupply.type; 275 251 if (resourceType.generic == "treasure") 276 {277 252 cursor = "action-gather-" + resourceType.generic; 278 }279 253 else 280 {281 254 cursor = "action-gather-" + resourceType.specific; 282 }283 255 data.command = "gather"; 284 256 data.resourceType = resourceType; 285 257 data.resourceTemplate = targetState.template; … … 414 386 for each (var unitClass in targetState.identity.classes) 415 387 { 416 388 if (unhealableClasses.indexOf(unitClass) != -1) 417 {418 389 return {"possible": false}; 419 }420 390 } 421 391 422 392 var healableClasses = entState.Healer.healableClasses; 423 393 for each (var unitClass in targetState.identity.classes) 424 394 { 425 395 if (healableClasses.indexOf(unitClass) != -1) 426 {427 396 return {"possible": true}; 428 }429 397 } 430 398 } 431 399 break; … … 455 423 break; 456 424 } 457 425 } 458 if ( haveUnitAI && (action == "move" || action == "attack-move"))426 if (action == "move" || action == "attack-move") 459 427 return {"possible": true}; 460 428 else 461 429 return {"possible": false}; … … 490 458 if (!g_DevSettings.controlAll && !allOwnedByPlayer) 491 459 return undefined; 492 460 493 // Work out whether the selection can have rally points494 var have RallyPoints = selection.every(function(ent) {461 // Work out whether at least part of the selection have UnitAI 462 var haveUnitAI = selection.some(function(ent) { 495 463 var entState = GetEntityState(ent); 464 return entState && entState.unitAI; 465 }); 466 467 // Work out whether at least part the selection have rally points 468 // while none have UnitAI 469 var haveRallyPoints = !haveUnitAI && selection.some(function(ent) { 470 var entState = GetEntityState(ent); 496 471 return entState && entState.rallyPoint; 497 472 }); 498 473 499 474 var targets = []; 500 475 var target = undefined; 501 var type = "none";502 476 var cursor = ""; 503 477 var targetState = undefined; 504 478 if (!fromMinimap) 505 479 targets = Engine.PickEntitiesAtPoint(x, y); 506 480 507 481 if (targets.length) 508 {509 482 target = targets[0]; 510 }511 483 512 484 var actionInfo = undefined; 513 485 if (preSelectedAction != ACTION_NONE) … … 536 508 { 537 509 return {"type": "garrison", "cursor": "action-garrison", "tooltip": actionInfo.tooltip, "target": target}; 538 510 } 539 else if ( Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible)511 else if (haveUnitAI && Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible) 540 512 { 541 513 return {"type": "attack-move", "cursor": "action-attack-move"}; 542 514 } … … 552 524 return {"type": "build", "cursor": "action-build", "target": target}; 553 525 else if (getActionInfo("repair", target).possible) 554 526 return {"type": "build", "cursor": "action-repair", "target": target}; 555 else if ( (actionInfo = getActionInfo("set-rallypoint", target)).possible)527 else if (haveRallyPoints && (actionInfo = getActionInfo("set-rallypoint", target)).possible) 556 528 return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position}; 557 529 else if (getActionInfo("heal", target).possible) 558 530 return {"type": "heal", "cursor": "action-heal", "target": target}; 559 531 else if (getActionInfo("attack", target).possible) 560 532 return {"type": "attack", "cursor": "action-attack", "target": target}; 561 else if ( getActionInfo("unset-rallypoint", target).possible)533 else if (haveRallyPoints && getActionInfo("unset-rallypoint", target).possible) 562 534 return {"type": "unset-rallypoint"}; 563 else if ( getActionInfo("move", target).possible)535 else if (haveUnitAI && getActionInfo("move", target).possible) 564 536 return {"type": "move"}; 565 537 } 566 return {"type": type, "cursor": cursor, "target": target};538 return {"type": "none", "cursor": cursor, "target": target}; 567 539 } 568 540 569 541 … … 577 549 return false; 578 550 } 579 551 580 var selection = g_Selection.toList();581 582 552 // Use the preview to check it's a valid build location 583 553 if (!updateBuildingPlacementPreview()) 584 554 { … … 587 557 return false; 588 558 } 589 559 560 var selection = g_Selection.toList(); 561 590 562 // Start the construction 591 563 Engine.PostNetworkCommand({ 592 564 "type": "construct", … … 879 851 case "mousebuttonup": 880 852 if (ev.button === SDL_BUTTON_LEFT) 881 853 { 882 883 854 inputState = INPUT_BUILDING_WALL_PATHING; 855 return true; 884 856 } 885 857 break; 886 858 … … 1323 1295 else 1324 1296 { 1325 1297 placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); 1326 1327 1298 dragStart = [ ev.x, ev.y ]; 1299 inputState = INPUT_BUILDING_CLICK; 1328 1300 } 1329 1301 return true; 1330 1302 } -
binaries/data/mods/public/gui/session/unit_commands.js
1092 1092 var gates = []; 1093 1093 for (var i in selection) 1094 1094 { 1095 state = GetEntityState(selection[i]);1095 var state = GetEntityState(selection[i]); 1096 1096 if (hasClass(state, "LongWall") && !state.gate && !longWallTypes[state.template]) 1097 1097 { 1098 1098 var gateTemplate = getWallGateTemplate(state.id);