400 ar[i, 1]:= ar[i - 1, 1] + (getrandom * 0.7 + 0.3) * WaveFreqDelta; |
400 ar[i, 1]:= ar[i - 1, 1] + (getrandom * 0.7 + 0.3) * WaveFreqDelta; |
401 ar[i, 2]:= getrandom * pi * 2; |
401 ar[i, 2]:= getrandom * pi * 2; |
402 ar[i, 3]:= WaveAmplMin + getrandom * WaveAmplDelta; |
402 ar[i, 3]:= WaveAmplMin + getrandom * WaveAmplDelta; |
403 ar[i, 4]:= ar[i - 1, 4] + (getrandom * 0.7 + 0.3) * WaveFreqDelta; |
403 ar[i, 4]:= ar[i - 1, 4] + (getrandom * 0.7 + 0.3) * WaveFreqDelta; |
404 ar[i, 5]:= getrandom * pi * 2; |
404 ar[i, 5]:= getrandom * pi * 2; |
|
405 {$IFDEF DEBUGFILE} |
|
406 AddFileLog('Wave params ¹' + inttostr(i) + ':'); |
|
407 AddFileLog('X: ampl = ' + floattostr(ar[i, 0]) + '; freq = ' + floattostr(ar[i, 1]) + '; shift = ' + floattostr(ar[i, 2])); |
|
408 AddFileLog('Y: ampl = ' + floattostr(ar[i, 3]) + '; freq = ' + floattostr(ar[i, 4]) + '; shift = ' + floattostr(ar[i, 5])); |
|
409 {$ENDIF} |
405 end; |
410 end; |
406 end; |
411 end; |
407 |
412 |
408 for k:= 0 to Pred(pa.Count) do // apply transformation |
413 for k:= 0 to Pred(pa.Count) do // apply transformation |
409 begin |
414 begin |
462 |
467 |
463 procedure GenLandSurface; |
468 procedure GenLandSurface; |
464 var tmpsurf: PSDL_Surface; |
469 var tmpsurf: PSDL_Surface; |
465 i: Longword; |
470 i: Longword; |
466 begin |
471 begin |
|
472 WriteLnToConsole('Generating land...'); |
467 for i:= 0 to sizeof(Land) div 4 do |
473 for i:= 0 to sizeof(Land) div 4 do |
468 PLongword(Longword(@Land) + i * 4)^:= $FFFFFF; |
474 PLongword(Longword(@Land) + i * 4)^:= $FFFFFF; |
469 GenBlank(EdgeTemplates[8{getrandom(Succ(High(EdgeTemplates)))}]); |
475 GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]); |
470 |
476 |
471 AddProgress; |
477 AddProgress; |
472 with PixelFormat^ do |
478 with PixelFormat^ do |
473 tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
479 tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
474 ColorizeLand(tmpsurf); |
480 ColorizeLand(tmpsurf); |
491 |
497 |
492 procedure MakeFortsMap; |
498 procedure MakeFortsMap; |
493 var p: PTeam; |
499 var p: PTeam; |
494 tmpsurf: PSDL_Surface; |
500 tmpsurf: PSDL_Surface; |
495 begin |
501 begin |
|
502 WriteLnToConsole('Generating forts land...'); |
496 p:= TeamsList; |
503 p:= TeamsList; |
497 TryDo(p <> nil, 'No teams on map!', true); |
504 TryDo(p <> nil, 'No teams on map!', true); |
498 with PixelFormat^ do |
505 with PixelFormat^ do |
499 LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
506 LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0); |
500 SDL_FillRect(LandSurface, nil, 0); |
507 SDL_FillRect(LandSurface, nil, 0); |
501 tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'L.png', false); |
508 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p.FortName + 'L.png', false); |
502 BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface); |
509 BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface); |
503 SDL_FreeSurface(tmpsurf); |
510 SDL_FreeSurface(tmpsurf); |
504 LoadFortPoints(p.FortName, false, TeamSize(p)); |
511 LoadFortPoints(p.FortName, false, TeamSize(p)); |
505 p:= p.Next; |
512 p:= p.Next; |
506 TryDo(p <> nil, 'Only one team on map!', true); |
513 TryDo(p <> nil, 'Only one team on map!', true); |
507 tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'R.png', false); |
514 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p.FortName + 'R.png', false); |
508 BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface); |
515 BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface); |
509 SDL_FreeSurface(tmpsurf); |
516 SDL_FreeSurface(tmpsurf); |
510 LoadFortPoints(p.FortName, true, TeamSize(p)); |
517 LoadFortPoints(p.FortName, true, TeamSize(p)); |
511 p:= p.Next; |
518 p:= p.Next; |
512 TryDo(p = nil, 'More than 2 teams on map in forts mode!', true); |
519 TryDo(p = nil, 'More than 2 teams on map in forts mode!', true); |
513 end; |
520 end; |
514 |
521 |
|
522 procedure LoadMap; |
|
523 var p, x, y, i: Longword; |
|
524 begin |
|
525 WriteLnToConsole('Loading land from file...'); |
|
526 AddProgress; |
|
527 LandSurface:= LoadImage(Pathz[ptMapCurrent] + '/map.png', false); |
|
528 TryDo((LandSurface.w = 2048) and (LandSurface.h = 1024), 'Map dimensions should be 2048x1024!', true); |
|
529 |
|
530 if SDL_MustLock(LandSurface) then |
|
531 SDLTry(SDL_LockSurface(LandSurface) >= 0, true); |
|
532 |
|
533 p:= Longword(LandSurface.pixels); |
|
534 i:= Longword(@Land); |
|
535 case LandSurface.format.BytesPerPixel of |
|
536 1: OutError('We don''t work with 8 bit surfaces', true); |
|
537 2: for y:= 0 to 1023 do |
|
538 begin |
|
539 for x:= 0 to 2047 do |
|
540 if PWord(p + x * 2)^ <> 0 then PLongWord(i + x * 4)^:= $FFFFFF; |
|
541 inc(i, 2048 * 4); |
|
542 inc(p, LandSurface.pitch); |
|
543 end; |
|
544 3: for y:= 0 to 1023 do |
|
545 begin |
|
546 for x:= 0 to 2047 do |
|
547 if (PByte(p + x * 3 + 0)^ <> 0) |
|
548 or (PByte(p + x * 3 + 1)^ <> 0) |
|
549 or (PByte(p + x * 3 + 2)^ <> 0) then PLongWord(i + x * 4)^:= $FFFFFF; |
|
550 inc(i, 2048 * 4); |
|
551 inc(p, LandSurface.pitch); |
|
552 end; |
|
553 4: for y:= 0 to 1023 do |
|
554 begin |
|
555 for x:= 0 to 2047 do |
|
556 if PLongword(p + x * 4)^ <> 0 then PLongWord(i + x * 4)^:= $FFFFFF; |
|
557 inc(i, 2048 * 4); |
|
558 inc(p, LandSurface.pitch); |
|
559 end; |
|
560 end; |
|
561 if SDL_MustLock(LandSurface) then |
|
562 SDL_UnlockSurface(LandSurface); |
|
563 |
|
564 AddHHPoints; |
|
565 RandomizeHHPoints; |
|
566 end; |
|
567 |
515 procedure GenMap; |
568 procedure GenMap; |
516 begin |
569 begin |
517 if (GameFlags and gfForts) = 0 then GenLandSurface |
570 if (GameFlags and gfForts) = 0 then |
|
571 if Pathz[ptMapCurrent] <> '' then LoadMap |
|
572 else GenLandSurface |
518 else MakeFortsMap; |
573 else MakeFortsMap; |
519 AddProgress; |
574 AddProgress; |
520 {$IFDEF DEBUGFILE}LogLandDigest{$ENDIF} |
575 {$IFDEF DEBUGFILE}LogLandDigest{$ENDIF} |
521 end; |
576 end; |
522 |
577 |