Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/gui/session/input.js
r9991 r10007 564 564 }); 565 565 if (snapData) 566 { 566 567 placementAngle = snapData.angle; 568 placementPosition.x = snapData.x; 569 placementPosition.z = snapData.z; 570 } 567 571 568 572 updateBuildingPlacementPreview(); … … 826 830 }); 827 831 if (snapData) 832 { 828 833 placementAngle = snapData.angle; 834 placementPosition.x = snapData.x; 835 placementPosition.z = snapData.z; 836 } 829 837 830 838 updateBuildingPlacementPreview(); -
ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js
r9991 r10007 526 526 } 527 527 528 // Find direction of most open water, algorithm: 529 // 1. Pick points in a circle around dock 530 // 2. If point is in water, add to array 531 // 3. Scan array looking for consective points 532 // 4. Find longest sequence of conseuctive points 533 // 5. Calculate angle using average of sequence 528 /* Find direction of most open water, algorithm: 529 * 1. Pick points in a circle around dock 530 * 2. If point is in water, add to array 531 * 3. Scan array looking for consective points 532 * 4. Find longest sequence of conseuctive points 533 * 5. If sequence equals all points, no direction can be determined, 534 * expand search outward and try (1) again 535 * 6. Calculate angle using average of sequence 536 */ 534 537 const numPoints = 16; 535 var waterPoints = []; 536 for (var i = 0; i < numPoints; ++i) 537 { 538 var angle = (i/numPoints)*2*Math.PI; 539 var nx = data.x - halfSize*Math.sin(angle); 540 var nz = data.z + halfSize*Math.cos(angle); 541 542 if (cmpTerrain.GetGroundLevel(nx, nz) < cmpWaterManager.GetWaterLevel(nx, nz)) 538 for (var dist = 0; dist < 4; ++dist) 539 { 540 var waterPoints = []; 541 for (var i = 0; i < numPoints; ++i) 543 542 { 544 waterPoints.push(i); 545 } 546 } 547 var consec = []; 548 var length = waterPoints.length; 549 for (var i = 0; i < length; ++i) 550 { 551 var count = 0; 552 for (var j = 0; j < (length-1); ++j) 553 { 554 if (((waterPoints[(i + j) % length]+1) % numPoints) == waterPoints[(i + j + 1) % length]) 543 var angle = (i/numPoints)*2*Math.PI; 544 var d = halfSize*(dist+1); 545 var nx = data.x - d*Math.sin(angle); 546 var nz = data.z + d*Math.cos(angle); 547 548 if (cmpTerrain.GetGroundLevel(nx, nz) < cmpWaterManager.GetWaterLevel(nx, nz)) 555 549 { 556 ++count; 557 } 558 else 559 { 560 break; 550 waterPoints.push(i); 561 551 } 562 552 } 563 consec[i] = count; 564 } 565 var start = 0; 566 var count = 0; 567 for (var c in consec) 568 { 569 if (consec[c] > count) 553 var consec = []; 554 var length = waterPoints.length; 555 for (var i = 0; i < length; ++i) 570 556 { 571 start = c; 572 count = consec[c]; 557 var count = 0; 558 for (var j = 0; j < (length-1); ++j) 559 { 560 if (((waterPoints[(i + j) % length]+1) % numPoints) == waterPoints[(i + j + 1) % length]) 561 { 562 ++count; 563 } 564 else 565 { 566 break; 567 } 568 } 569 consec[i] = count; 573 570 } 574 } 575 576 return {"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI) }; 571 var start = 0; 572 var count = 0; 573 for (var c in consec) 574 { 575 if (consec[c] > count) 576 { 577 start = c; 578 count = consec[c]; 579 } 580 } 581 582 // If we've found a shoreline, stop searching 583 if (count != numPoints-1) 584 { 585 return {"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI)}; 586 } 587 } 577 588 } 578 589 -
ps/trunk/binaries/data/mods/public/simulation/data/pathfinder.xml
r9970 r10007 24 24 <building-land> 25 25 <MaxWaterDepth>0</MaxWaterDepth> 26 <MinShoreDistance> 2.0</MinShoreDistance>26 <MinShoreDistance>1.0</MinShoreDistance> 27 27 <MaxTerrainSlope>1.0</MaxTerrainSlope> 28 28 </building-land> 29 29 <building-shore> 30 <MaxShoreDistance> 3.0</MaxShoreDistance>31 <MaxTerrainSlope>1. 5</MaxTerrainSlope>30 <MaxShoreDistance>2.0</MaxShoreDistance> 31 <MaxTerrainSlope>1.25</MaxTerrainSlope> 32 32 </building-shore> 33 33 -
ps/trunk/source/simulation2/components/CCmpPathfinder.cpp
r9970 r10007 400 400 { 401 401 // Find a land tile 402 if (!waterGrid.get(i, j) && ( 403 (i > 0 && waterGrid.get(i-1, j)) || (i > 0 && j < m_MapSize-1 && waterGrid.get(i-1, j+1)) || (i > 0 && j > 0 && waterGrid.get(i-1, j-1)) || 404 (i < m_MapSize-1 && waterGrid.get(i+1, j)) || (i < m_MapSize-1 && j < m_MapSize-1 && waterGrid.get(i+1, j+1)) || (i < m_MapSize-1 && j > 0 && waterGrid.get(i+1, j-1)) || 405 (j > 0 && waterGrid.get(i, j-1)) || (j < m_MapSize-1 && waterGrid.get(i, j+1)) 406 )) 402 if (!waterGrid.get(i, j)) 407 403 { 408 shoreGrid.set(i, j, 0); 404 if ((i > 0 && waterGrid.get(i-1, j)) || (i > 0 && j < m_MapSize-1 && waterGrid.get(i-1, j+1)) || (i > 0 && j > 0 && waterGrid.get(i-1, j-1)) 405 || (i < m_MapSize-1 && waterGrid.get(i+1, j)) || (i < m_MapSize-1 && j < m_MapSize-1 && waterGrid.get(i+1, j+1)) || (i < m_MapSize-1 && j > 0 && waterGrid.get(i+1, j-1)) 406 || (j > 0 && waterGrid.get(i, j-1)) || (j < m_MapSize-1 && waterGrid.get(i, j+1)) 407 ) 408 { // If it's bordered by water, it's a shore tile 409 shoreGrid.set(i, j, 0); 410 } 411 else 412 { 413 shoreGrid.set(i, j, shoreMax); 414 } 409 415 } 410 else 411 { 412 shoreGrid.set(i, j, shoreMax); 413 } 414 } 415 } 416 417 // Expand influences to find shore distance 416 } 417 } 418 419 // Expand influences on land to find shore distance 418 420 for (size_t y = 0; y < m_MapSize; ++y) 419 421 { … … 421 423 for (size_t x = 0; x < m_MapSize; ++x) 422 424 { 423 u16 g = shoreGrid.get(x, y); 424 if (g > min) 425 shoreGrid.set(x, y, min); 426 else if (g < min) 427 min = g; 428 429 ++min; 425 if (!waterGrid.get(x, y)) 426 { 427 u16 g = shoreGrid.get(x, y); 428 if (g > min) 429 shoreGrid.set(x, y, min); 430 else if (g < min) 431 min = g; 432 433 ++min; 434 } 430 435 } 431 436 for (size_t x = m_MapSize; x > 0; --x) 432 437 { 433 u16 g = shoreGrid.get(x-1, y); 434 if (g > min) 435 shoreGrid.set(x-1, y, min); 436 else if (g < min) 437 min = g; 438 439 ++min; 438 if (!waterGrid.get(x-1, y)) 439 { 440 u16 g = shoreGrid.get(x-1, y); 441 if (g > min) 442 shoreGrid.set(x-1, y, min); 443 else if (g < min) 444 min = g; 445 446 ++min; 447 } 440 448 } 441 449 } … … 445 453 for (size_t y = 0; y < m_MapSize; ++y) 446 454 { 447 u16 g = shoreGrid.get(x, y); 448 if (g > min) 449 shoreGrid.set(x, y, min); 450 else if (g < min) 451 min = g; 452 453 ++min; 455 if (!waterGrid.get(x, y)) 456 { 457 u16 g = shoreGrid.get(x, y); 458 if (g > min) 459 shoreGrid.set(x, y, min); 460 else if (g < min) 461 min = g; 462 463 ++min; 464 } 454 465 } 455 466 for (size_t y = m_MapSize; y > 0; --y) 456 467 { 457 u16 g = shoreGrid.get(x, y-1); 458 if (g > min) 459 shoreGrid.set(x, y-1, min); 460 else if (g < min) 461 min = g; 462 463 ++min; 468 if (!waterGrid.get(x, y-1)) 469 { 470 u16 g = shoreGrid.get(x, y-1); 471 if (g > min) 472 shoreGrid.set(x, y-1, min); 473 else if (g < min) 474 min = g; 475 476 ++min; 477 } 464 478 } 465 479 } … … 699 713 return false; 700 714 701 CFixedVector2D halfSize(square.hw, square.hh); 702 halfSize = halfSize * 1.41421f; 715 // Expand bounds by 1/sqrt(2) tile (multiply by CELL_SIZE since we want world coordinates) 716 entity_pos_t expand = entity_pos_t::FromInt(2).Sqrt().Multiply(entity_pos_t::FromInt(CELL_SIZE / 2)); 717 CFixedVector2D halfSize(square.hw + expand, square.hh + expand); 703 718 CFixedVector2D halfBound = Geometry::GetHalfBoundingBox(square.u, square.v, halfSize); 704 719
Note:
See TracChangeset
for help on using the changeset viewer.
