Wake of Gods Forum | Форум Во Имя Богов

Full Version: Ваши вопросы по ERM-скриптам
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
Этот код нужно в тему готовых решений. С головы его не выдумать быстро, рабочий вариант.
igrik, просто супер! Работает идеально.

По ходу дела возник еще один вопрос. Эра позволяет блокировать регенерацию существ, но вот элексир продолжает работать. Как его можно отключить?
igrik, awesome!

I wonder if customising Necromancy is still a thing? I wish the code can help someone if it has not yet been revealed.

GitHub

Edit: Fixed a typo thanks to daemon_n
Archer30,
!!FU|(side)=-1/i^battle_hero_%(side)^=(NO_HERO):E
Looking for help with a function for getting a random position for summoning with BU:S

Input: Side for summoning, is Double Wide (monster Flag)
Output: random available position for BU:S summoning (both hex must not be unoccupied if doubled wide)

It looks like I have achieved undesirable outcome with it...I would like to know what could possibly be wrong.
I understand that the code must be optimised a lot more

Seems like code is valid.

But I would generate single array of valid positions first and then generate single random value in 0..array_size - 1 range. Value under generated index will be the result.
---------------------------------
Another variant is to fill "positions" array of 186 items with 0..185 values correspondingly.
Also define variable numCandidates = 186 (array size).

Repeat until free position is found or numCandidates = 0.
Generate random value in 0..numCandidates - 1 range.

Battle pos = positions[generated random index]
If position is not free or invalid, then

positions[generated random index] = numCandidates - 1; we make array index to actually point to another position, thus virtually removing tested hex from further check attempts
numCandidates = numCandidates - 1; decrease positions array size, because the last position is not referrered by "generated random index".

------------------------

For instance, imagine there are max 8 positions on battle: 0..7.

Define positions array = (0, 1, 2, 3, 4, 5, 6, 7).
numCandidates = 8

generated random value 0..(8 - 1) = 3
Look at positions array at index 3. positions[3] = 3.
Check battle hex #3, it's occupied.

positions[3] = numCandidates - 1 = 7
numCandidates = numCandidates - 1 = 7
Thus we have updated positions array: (0, 1, 2, 7, 4, 5, 6)

As you see, new array does not have hex #3 anymore.

Both approaches guarantee to find free positions. Your variant with 100 generations may fail for unlucky generated sequences.
Berserker, great approaches! Well, I had a hard time using the function I wrote. For some reason, I can't get the second IF:M shown on my screen from time to time. This is so weird as there is no FU:E in the function, it is technically not possible...

At the moment I need some advice on writing. Is there a convenient way to bypass invalid positions (0, 17, 34, those hex out of the battlefield)? Both BU:E/BU:D returns -1, making it not possible to
distinguish them with empty hex.

Alternatively, is there a way to remove mutual elements from both arrays? You know what I am thinking about Rolleyes
(14.03.2022 19:58)Archer30 Wrote: [ -> ]Is there a convenient way to filter invalid positions (0, 17, 34, those hex out of the battlefield)?
I think something like this:
Archer30, here is the complete function. It has not yet been fully tested, but at first glance it works.

wessonsm, thanks. I forgot that it can be solved by math lol.

Umm. Usually, I would use &(variable) for booleans. My (isDoubleWide) and (isAvailPos) are either 0 or 1. I believe we were introduced &(variable) some versions around ERA 3.5, it equals to &(variable)>(FALSE). Is that a bad practice though?
Quote:Umm. Usually, I would use &(variable) for booleans. My (isDoubleWide) and (isAvailPos) are either 0 or 1. I believe we were introduced &(variable) some versions around ERA 3.5, it equals to &(variable)>(FALSE). Is that a bad practice though?
No, it's a good practice. wessonsm just was not aware of this improvement.

P.S. Чуток дооформил код выше.
Archer30, Berserker. I really missed this moment in the changelog, apparently I didn’t read well.
Sorry for the misinformation and thanks for the clarification.
I'll edit my post to avoid misleading others.
wessonsm, no need to worry about it Sm

Well, I come up with another question with BU:S summoning, I want to write a function with the following requirements, and I'd like to know the best approach to it.

The task of the function: Find a random but closest position to the given position for BU:S summoning. The monster for summoning is known for whether it is double wide, and the side for summoning.
Input: a known Position, Is Double Wide, Side.
Output: Closest position to the known position for BU:S


I have two approaches in mind, first one:
- loop through all the hex on the battlefield
- Check the distance between the looped hex and the known hex
- Collect the hex with the smallest distance and put to the array
- Get a random position from this array

Second one:
- Check for the closet positions around the given position. The first batch would be the six hex around the target
- If none is available, check for a larger hex around the target, repeat this if nothing is found again

Basically, the first approach is easier to code, but I am worried about its efficiency. The second approach should be faster, but it is a bit tricky to code. If I can't combine the steps, I might end up checking for every single position manually.

Any thoughts?
Archer30,
It seems that the first method will be quite effective if we have a simple and fast function for calculating the distance between two hexes.
The second way can be implemented if you come up with a fairly simple algorithm for bypassing hexes along a spiral path.
I think this can be done by converting the hex numbers to pairs of coordinates (row, column).
The second way seems more interesting to me, and I will think about it.
We already had distance calculating function (based on row and column) on this forum in ERM 1, probably. I have old code in Pascal.

BATTLEFIELD_LINE_SIZE = 17;

Code:
FUNCTION CalculateDistance (SrcPos, DstPos: INTEGER): INTEGER;
VAR
  DistanceX:  INTEGER;
  DistanceY:  INTEGER;
  x1, x2:     INTEGER;
  y1, y2:     INTEGER;

BEGIN
  x1  :=  SrcPos MOD BATTLEFIELD_LINE_SIZE;
  y1  :=  SrcPos DIV BATTLEFIELD_LINE_SIZE;
  x2  :=  DstPos MOD BATTLEFIELD_LINE_SIZE;
  y2  :=  DstPos DIV BATTLEFIELD_LINE_SIZE;

  DistanceY :=  ABS(y1 - y2);
  DistanceX :=  ABS(x1 * 2 - (y1 AND 1) - x2 * 2 + (y2 AND 1)) - DistanceY;
  
  RESULT  :=  (DistanceY * 2 + Math.Max(DistanceX, 0)) DIV 2;
END; // .FUNCTION CalculateDistance
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
Reference URL's