summaryrefslogblamecommitdiff
path: root/world/map/npc/functions/doomsday.txt
blob: bba08e75a402c8250a1687b8e8f5c784d541bd59 (plain) (tree)



















                                                                           










                                                                    
                                            
           
                 

                                                                                          
                                                                            

                 
                                                                            


                                                                            
                                                                      
                                        




                                                 
                                 
        





                                                               
                                                           


                                                                   
                                                     
                                            


                                               




                            
                         





                                                                          
                      




                                                                       



















                                                                              





                                                                                 













































                                                                                

                            
                                                                                     

           
                      
          









                              
                               
                     

                             

                                                                       


                                                                    
        


                                                                          
           
 





                                                                                 





                                                                              








                                                






                                                


                                                                      



                                   
                   





                                       
                                                                                   
                                                                                         

                         

                         

                         


                     
                                                                                



























                                                                                                    
                                                                      



















                                                                                                    






                                                                                




























                                                                                   





                              


                                       
                                
















                                                                   
                                                                                                                       
                           
                                                                                                                      
                           
                                                                                                                        
























                                                                        














                                                           
                                                           
                           
                                                           

 

                                                   
                                                                                                  
                           
                                                                                                 
                           
                                                                                                   








                                                      



                                                           




















                                                                







                                                                                   







                                                                            
                                                 







                             






                                          
 

                                                                                                        







                                                                                                                                  






                         
                        
                                                      


                                                                                       
                                                      




                                                                                       
                                                      



                                                                                       
                                                      



                                                                                        
                                                      



                                                                                       
                                                      



                                                                                       
                                                      



                                                                                       
                                                      









                                                                                       
                        
                                                      


                                                                                        
                                                      




                                                                                        
                                                      



                                                                                        
                                                      



                                                                                        
                                                      



                                                                                       
                                                      



                                                                                       
                                                      



                                                                                       
                                                      









                                                                                       
                        
                                                      
                                                                                       

                             
                                                      




                                                                                       
                                                      



                                                                                       
                                                      



                                                                                       
                                                      



                                                                                       
                                                      



                                                                                       
                                                      



                                                                                       
                                                      








                                                                                       






















                                                                                                                              

















                                                                                                                                  
                                             




                                                                                    





















                                                                                                                                  



        



















                                                                                                  
                                                      













                                                                                           
                                           
                                                                                                                     








                                                   

                               

        

                 
                                                                                                
                                          
 



                                               


                                               
                                                      
                                                                              
                                                      
                                                                               
                                                      
                                                                              
 
                                                      
                                                                                            










                                                                                     



                                              

                      

        
































                                                                                                        



                                      
























                                                                                          



                                                                                



                              
                                                                                
                            









                              


                                

                           








                                 
                           

                        
            





                             
            



                         






                              

               

                             


                              

                           
            





                             
            
                        
            



                         






                              
            

                             


                              
 





                              
                                                                                






                                           


            








                                                                                                      

 
 

 
// Evol script
// Controls Doomsday Event
//
// A really long event (months), controlling and being written by
// every event which happens since doomsday program officialy started
// in Halloween 2019 with Tormenta's release.
//
// This file history is written by GMs and players as the events happen
// and therefore it is not possible to predict or add code for things which
// are too far away from happening.
//
// Please keep Doomsday System simple.
// Revert it to anything to stage once it is over.
// It can be epic. But it doesn't needs to be.
// But above all, this should NOT affect the merge.
// The event purpose is to give players background history.

function|script|DoomsdayDebug
{
    mes "$DOOMSDAY: "+$DOOMSDAY; // Event Status
    mes "";
    mes "Act 2:";
    mes "Amount of slain Mana Guardians:";
    mes "$DOOMSDAY_CNT: "+$DOOMSDAY_CNT;
    mes "";
    mes "Act 3:";
    mes "Situation of the towns (0 - standing, n - fallen n times)";
    mes "$DOOMSDAY_TOWN[0] (Tulim): "+$DOOMSDAY_TOWN[0];
    mes "$DOOMSDAY_TOWN[1] (Hurns): "+$DOOMSDAY_TOWN[1];
    mes "$DOOMSDAY_TOWN[2] (Nival): "+$DOOMSDAY_TOWN[2];
    mes "$DOOMSDAY_SCORE: "+$DOOMSDAY_SCORE;
    mes "$DOOMSDAY_CLUES: "+$DOOMSDAY_CLUES;
    mes "";
    mes "Act 4:";
    mes "Can players summon Mana Guardians? "+if_then_else($DOOMSDAY_SUMMON, "Yes", "No");
    mes "Is TMW under Jande's control? "+if_then_else($DOOMSDAY_TAKENOVER, "Yes", "No");
    mes "Zealite Upgrade? "+if_then_else($DOOMSDAY_SUMMON > 1, "Yes", "No");
    mes "";
    mes "Act 5:";
    mes "Warp to fake Keshlam? "+if_then_else($DOOMSDAY_TWARP, "No", "Yes");
    mes "Jande was rescued? "+if_then_else($@HW2020_HOCUS > 2, "Yes", "No");
    mes "Jande has recovered? "+if_then_else($DOOMSDAY_TJANDE, "Yes", "No");
    mes "$DOOMSDAY_CNT2: "+$DOOMSDAY_CNT2;
    mes "Vanilla Mode? "+if_then_else($DOOMSDAY_VANILLA, "Yes", "No");
    //($DOOMSDAY_SUMMON ? "Yes" : "No");
    next;
    // Only GM 80 and above can modify Doomsday
    // ...Yes, G_ADMIN is 80 while G_SYSOP is 99.
    if (GM < G_ADMIN) goto L_Close;
    mes "Setting $DOOMSDAY event state";
    mes "[DOOMSDAY][ACT][STATE]";
    menu
        "[0][1][0] Tormenta's Seal",L_Seal,
        "[1][2][0] Jande's Army",L_Army,
        "[1][2][1] Toggle Mana Guardian Skill",L_Summon,
        "[1][2][2] Surrender TMW to Jande",L_Surrender,
        "[1][3][0] The Great War - First Wave",L_War,
        "[2][3][1] The Great War - Additional Wave",L_GreatWar,
        "[2][4][0] Wumpus Great Egg Hunt - DEBUG",L_Wumpus,
        "[2][4][1] Council - Tulimshar's Guild",L_TulimCouncil,
        "[2][4][2] Council - Celestia's Residence",L_HurnsCouncil,
        "[2][4][3] Council - Blue Sage's Residence",L_NivalCouncil,
        "[2][4][4] Toggle Zealite Upgrade",L_Zealite,
        "[3][5][0] Keshlam Warps",L_Keshlam,
        "[3][5][1] Rescuing Jande",L_Jande,
        "[3][5][2] Kage's Final Battle",L_Kage,
        "[3][5][3] Vanilla Mode",L_Vanilla,
        "[-] Close",L_Close;

L_Close:
    return;

// Act 1: Tormenta's Seal
L_Seal:
    set $DOOMSDAY, 0;
    donpcevent "Doomsday::OnJanitor";
    gmlog strcharinfo(0) + " changed doomsday to Act 1: Tormenta's Seal.";
    return;

// Act 2: Jande's Army
L_Army:
    set $DOOMSDAY, 1;
    donpcevent "Doomsday::OnJanitor";
    gmlog strcharinfo(0) + " changed doomsday to Act 2: Jande's Army.";
    return;

L_Summon:
    set $DOOMSDAY_SUMMON, (!$DOOMSDAY_SUMMON);
    gmlog strcharinfo(0) + " changed the availability of #jande spell.";
    return;

L_Surrender:
    set $DOOMSDAY_TAKENOVER, 1;
    donpcevent "Doomsday::OnDoomsday2Restart";
    gmlog strcharinfo(0) + " surrendered The Mana World to Jande.";
    return;


// Act 3: The Great War
L_War:
    set $@DOOMSDAY_SKIP, 1; // Skip the next scheduled siege
    donpcevent "Doomsday::OnDoomsday3First"; // Forces a doomsday to begin now
    gmlog strcharinfo(0) + " changed doomsday to Act 3: The Great War.";
    return;

L_Wumpus:
    set $@DOOMSDAY_SKIP, 0;
    donpcevent "Doomsday::OnClock1830"; // Forces a doomsday act 4 check
    gmlog strcharinfo(0) + " manually triggered debug function. Doomsday Act 4.";
    return;

// Act 4: The Great War Council
L_GreatWar:
    disablenpc "Wizard#1";
    disablenpc "Wizard#2";
    disablenpc "Wizard#3";
    disablenpc "Wizard#4";
    disablenpc "Wizard#5";
    disablenpc "Wizard#6";
    disablenpc "Wizard#7";
    disablenpc "Wizard#8";
    disablenpc "Arch-Wizard#9";
    set $DOOMSDAY, 2;
    set $@DOOMSDAY_SKIP, 0;
    donpcevent "Doomsday::OnJanitor";
    gmlog strcharinfo(0) + " changed doomsday to Act 4: The Great War Council.";
    return;

L_CouncilRefusal:
    mes "##1Cowardly refusing to meet in a town destroyed five times.";
    next;
    return;

L_TulimCouncil:
    if ($DOOMSDAY_TOWN[0] >= 5)
        goto L_CouncilRefusal;

    enablenpc "Arch-Wizard#_DT";
    gmlog strcharinfo(0) + " called the Council to Tulimshar.";
    return;

L_HurnsCouncil:
    if ($DOOMSDAY_TOWN[1] >= 5)
        goto L_CouncilRefusal;

    enablenpc "Arch-Wizard#_DH";
    gmlog strcharinfo(0) + " called the Council to Hurnscald.";
    return;

L_NivalCouncil:
    if ($DOOMSDAY_TOWN[2] >= 5)
        goto L_CouncilRefusal;

    enablenpc "Arch-Wizard#_DN";
    gmlog strcharinfo(0) + " called the Council to Nivalis.";
    return;

L_Zealite:
    set $DOOMSDAY_SUMMON, 2;
    gmlog strcharinfo(0) + " changed the availability of #manatez and Savior Armor.";
    return;

// Act 5: The Doomsday
L_Keshlam:
    mes "//-- TODO --//";
    enablenpc "Wizard#1";
    enablenpc "Wizard#2";
    enablenpc "Wizard#3";
    enablenpc "Wizard#4";
    enablenpc "Wizard#5";
    enablenpc "Wizard#6";
    enablenpc "Wizard#7";
    enablenpc "Wizard#8";
    enablenpc "Arch-Wizard#9";
    enablenpc "Chest#DarkRose";
    set $DOOMSDAY, 3;
    set $DOOMSDAY_TWARP, 0;
    set $DOOMSDAY_VANILLA, 0;
    donpcevent "Doomsday::OnJanitor"; // TODO
    gmlog strcharinfo(0) + " changed doomsday to Act 5: The Doomsday.";
    gmlog strcharinfo(0) + " changed doomsday warp to Keshlam Maze";
    return;

L_Jande:
    set $DOOMSDAY_TWARP, 1;
    donpcevent "Doomsday::OnJanitor"; // TODO
    gmlog strcharinfo(0) + " changed doomsday warp to Abandoned Building";
    return;

L_Kage:
    set $DOOMSDAY_TJANDE, 1;
    donpcevent "Doomsday::OnJanitor"; // TODO
    gmlog strcharinfo(0) + " changed Jande from MIA to ACT. Final battle begun.";
    return;

L_Vanilla:
    set $DOOMSDAY_VANILLA, 1;
    donpcevent "Doomsday::OnJanitor"; // TODO
    gmlog strcharinfo(0) + " disabled rewards from final showdown (VANILLA).";
    return;

}

// Doomsday script controller
-|script|Doomsday|32767
{
    close;

// Destroy any artifact as doomsday mode changes
OnJanitor:
    // TODO: Act 2: Kill monsters?
    // Act 3: Clean eventually on-going Doomsday
    set $@DOOMSDAY_SKIP, 0;
    set $@DD_NUMWAVES, 0;
    set $@DoomsdayLoc, 0;
    set $@DoomsdayMc, 0;
    set $@DD_LOC$, "";
    // Act 5: Cleanup
    if ($DOOMSDAY == 3 && !$DOOMSDAY_TWARP)
        donpcevent "Keshlam Maze::OnInit"; // Spawn monsters if needed
    if ($DOOMSDAY != 3)
        disablenpc "To Underworld";
    if ($DOOMSDAY == 3)
        enablenpc "To Underworld";
    // Clear timers
    setnpctimer 0;
    stopnpctimer;
    goto OnInit;

// Check for our current doomsday state
OnInit:
    setarray $@doomsday_mobs, 1140, 1141, 1143, 1140, 1141, 1143, 1140, 1141, 1143;
    setarray $@doomsday_boss, 1146, 1147, 1146, 1147, 1146, 1147, 1146, 1147, 1146, 1147;
    if ($DOOMSDAY == 1)
        goto L_Doomsday1;
    if ($DOOMSDAY == 2)
        goto L_Doomsday2;
    if ($DOOMSDAY == 3)
        goto L_Doomsday5;
    // goto L_Check2;
    end;

////////////////////////////////////////////////////////////////////////////////
L_Doomsday1:
    // 1138 - Mana Guardian
    // Argaes Invasion (1)
    areamonster "017-1", 169, 49, 198, 77, "", 1138, 1, "Doomsday::OnDeathMapname";
    // Argaes Invasion (2)
    areamonster "012-1", 20, 47, 74, 77, "", 1138, 3, "Doomsday::OnDeathMapname";
    // Argaes Invasion (3)
    areamonster "057-1", 115, 50, 140, 75, "", 1138, 4, "Doomsday::OnDeathMapname";
    // Kaizei Invasion (I)
    areamonster "046-1", 58, 49, 92, 70, "", 1138, 2, "Doomsday::OnDeathMapname";
    // Kaizei Invasion (II)
    areamonster "034-1", 83, 51, 121, 98, "", 1138, 6, "Doomsday::OnDeathMapname";
    // Tonori Invasion
    areamonster "003-4", 20, 20, 85, 60, "", 1138, 7, "Doomsday::OnDeathMapname";
    end;

L_Doomsday1Respawn:
    // Argaes Invasion (1)
    set $@DoomsdayMc, mobcount("017-1", "Doomsday::OnDeathMapname")+1;
    if ($@DoomsdayMc < 1)
        areamonster "017-1", 169, 49, 198, 77, "", 1138, 1-$@DoomsdayMc, "Doomsday::OnDeathMapname";

    // Argaes Invasion (2)
    set $@DoomsdayMc, mobcount("012-1", "Doomsday::OnDeathMapname")+1;
    if ($@DoomsdayMc < 3)
        areamonster "012-1", 20, 47, 74, 77, "", 1138, 3-$@DoomsdayMc, "Doomsday::OnDeathMapname";

    // Argaes Invasion (3)
    set $@DoomsdayMc, mobcount("057-1", "Doomsday::OnDeathMapname")+1;
    if ($@DoomsdayMc < 4)
        areamonster "057-1", 115, 50, 140, 75, "", 1138, 4-$@DoomsdayMc, "Doomsday::OnDeathMapname";

    // Kaizei Invasion (I)
    set $@DoomsdayMc, mobcount("046-1", "Doomsday::OnDeathMapname")+1;
    if ($@DoomsdayMc < 2)
        areamonster "046-1", 58, 49, 92, 70, "", 1138, 2-$@DoomsdayMc, "Doomsday::OnDeathMapname";

    // Kaizei Invasion (II)
    set $@DoomsdayMc, mobcount("034-1", "Doomsday::OnDeathMapname")+1;
    if ($@DoomsdayMc < 6)
        areamonster "034-1", 83, 51, 121, 98, "", 1138, 6-$@DoomsdayMc, "Doomsday::OnDeathMapname";

    // Tonori Invasion
    set $@DoomsdayMc, mobcount("003-4", "Doomsday::OnDeathMapname")+1;
    if ($@DoomsdayMc < 7)
        areamonster "003-4", 20, 20, 85, 60, "", 1138, 7-$@DoomsdayMc, "Doomsday::OnDeathMapname";
    // goto L_TimerCheck2;
    goto L_TimerFinish;

////////////////////////////////////////////////////////////////////////////////
// Disable Tulimshar Magic Council
L_Doomsday2:
    addnpctimer 1000, "Doomsday::OnDoomsday2Restart";
    end;

OnDoomsday2Restart:
    // TODO: Maybe the town was taken over?
    if (!$DOOMSDAY_TAKENOVER)
        end;

    fakenpcname "Constable Bob", "Constable Bob#_D", 421;
    fakenpcname "Inspector#Hurnscald", "Inspector#Hurnscald_D", 420;
    //fakenpcname "Richard", "Guardian Richard#_D", 420;
    fakenpcname "Selim", "Guardian Selim#_D", 420;
    fakenpcname "General Store#hurnscald", "Guardian Store#hurns_D", 420;
    fakenpcname "General Store#dimond", "Guardian Store#dimond_D", 420;
    fakenpcname "Sabine", "Mana Tourist#_D", 420;
    fakenpcname "Apprentice", "Apprentice#_D", 420;
    fakenpcname "Entertainer", "Entertainer#_D", 420;
    fakenpcname "Drinker#2", "Drinker#2_D", 420;
    fakenpcname "Bartender#Duels", "Bartender#Duels_D", 420;
    fakenpcname "Jerry", "Mana Singer#_D", 420;

    fakenpcname "Constable Perry Graf", "Constable Perry#_D", 420; // Name too long
    fakenpcname "Guard#school", "Guard#school_D", 420;
    fakenpcname "Guard#castle", "Guard#castle_D", 420;
    fakenpcname "Guard#east3", "Guard#east3_D", 420;
    fakenpcname "Guard#govt_out", "Guard#govtout_D", 420;
    fakenpcname "Guard#govt_in", "Guard#govtin_D", 420;
    fakenpcname "Guard#port1", "Guard#port1_D", 420;
    fakenpcname "Guard#port2", "Guard#port2_D", 420;
    fakenpcname "Guard#east1", "Guard#east1_D", 420;

    fakenpcname "Mede", "Mana Shopkeeper#_D", 420;
    fakenpcname "Bracco", "Mana Shopkeeper#2_D", 420;

    if ($DOOMSDAY_SUMMON == 2)
        goto L_MenhirUpdate;
    end;

L_MenhirUpdate:
    disablenpc "Soul Menhir#hurnscald";
    disablenpc "Soul Menhir#nivalis";
    disablenpc "Soul Menhir#tulimshar";
    //enablenpc "Chest#Zealite";
    end;

/////// Act 3 sieges
// Variables:
// $@DoomsdayLoc / 100 = Town Code (0: Tulim, 1: Hurns, 2: Nivalis)

// Fake label for the first Zax's movement
OnDoomsday3First:
    set $@DoomsdayLoc, 1;
    goto L_Doomsday3;

// Setup a siege
L_Doomsday3Init:
    set $@DoomsdayLoc, rand(300) / 100;

    // Announce based on location
    if ($@DoomsdayLoc == 0)
        announce "Jande : Zax De'Kagen's army is marching to ##BTULIMSHAR##b in 10 minutes! (Attack by south gate)", 0;
    if ($@DoomsdayLoc == 1)
        announce "Jande : Zax De'Kagen's army is marching to ##BHURNSCALD##b in 10 minutes! (Attack by the mines)", 0;
    if ($@DoomsdayLoc == 2)
        announce "Jande : Zax De'Kagen's army is marching to ##BNIVALIS##b in 10 minutes! (Attack by east entrance)", 0;
    end;

// This siege will be skipped
L_Doomsday3Skip:
    set $@DOOMSDAY_SKIP, 0;
    end;

// Operational label, handles sieges
L_Doomsday3:
    // At this point it is no longer possible to skip the event.
    // Based on $@DoomsdayLoc go to a town-specific label
    // One wave every 5 minutes, until 6 waves were called (~30 min)
    // Then stop the timer, and check for survivor mobs 45 minutes after
    // If survivors are found, the town will be overrun
    set $@DD_NUMWAVES, 0;

    // Set the map for other labels (could use an array but meh)
    if ($@DoomsdayLoc == 0)
        set $@DD_LOC$, "002-1";
    if ($@DoomsdayLoc == 1)
        set $@DD_LOC$, "018-1";
    if ($@DoomsdayLoc == 2)
        set $@DD_LOC$, "031-1";


    // Set the map coordinates for spawns
    // Tulimshar
    if ($@DoomsdayLoc == 0)
        setarray $@DD_XPOS, 98, 97, 91, 75, 56, 44, 76, 54;
    if ($@DoomsdayLoc == 0)
        setarray $@DD_YPOS, 75, 86, 99,104, 81, 63, 76, 96;

    // Hurnscald
    if ($@DoomsdayLoc == 1)
        setarray $@DD_XPOS,138,136,133,111, 95, 79, 67, 88;
    if ($@DoomsdayLoc == 1)
        setarray $@DD_YPOS, 63, 71, 79, 74, 75, 64, 82, 90;

    // Nivalis
    if ($@DoomsdayLoc == 2)
        setarray $@DD_XPOS, 90, 62, 63, 56, 70, 36, 62, 85;
    if ($@DoomsdayLoc == 2)
        setarray $@DD_YPOS, 47, 49, 61, 83, 41, 37, 26, 30;


    // Make an extra announce for those whom missed
    if ($@DoomsdayLoc == 0)
        announce "Jande : Zax De'Kagen's army reached ##BTULIMSHAR##b! (Attack by south gate)", 0;
    if ($@DoomsdayLoc == 1)
        announce "Jande : Zax De'Kagen's army reached ##BHURNSCALD##b! (Attack by the mines)", 0;
    if ($@DoomsdayLoc == 2)
        announce "Jande : Zax De'Kagen's army reached ##BNIVALIS##b! (Attack by east entrance)", 0;

    goto L_DDAdvanceWave;

// Advance wave (max. 10->6 waves)
L_DDAdvanceWave:
    set $@DD_NUMWAVES, $@DD_NUMWAVES+1;
    if ($@DD_NUMWAVES > 6)
        end; // TODO: Maybe a final wave announcement?

    // Variable initialization
    set $@DD_INT, 0;
    set $@DD_UNITS, getmapusers($@DD_LOC$)+$DOOMSDAY_SCORE;

    // Spawns
    if ($@DoomsdayLoc == 0)
        goto L_DD3Tulim;
    if ($@DoomsdayLoc == 1)
        goto L_DD3Hurns;
    if ($@DoomsdayLoc == 2)
        goto L_DD3Nival;

    // Fallback
    debugmes "DOOMSDAY/ACT3: Unrecognized town: "+$@DoomsdayLoc;
    goto L_DDAdvanceTimers;

// Restart timers and advance wave
L_DDAdvanceTimers:
    initnpctimer;
    if ($@DD_INT < $@DD_UNITS*2)
        goto L_DDAdvanceTimers2;
    goto L_DDAdvanceWavePost;

// If we have more users than possible, waves come faster
L_DDAdvanceTimers2:
    set $@ADD_TIME, (($@DD_UNITS*2-$@DD_INT)*500); // ±1 second per player/victory
    // Cap to 90s (to prevent skipping first third)
    if ($@ADD_TIME > 90000)
        set $@ADD_TIME, 90000;

    setnpctimer $@ADD_TIME;

    set $@ADD_TIME, 0;
    // If we have clues, we will cause a few extra spawns
    if ($DOOMSDAY_CLUES)
        goto L_DD3WaveReinforcements;
    goto L_DDAdvanceWavePost;

// Reinforcements on waves, to ensure Kage never really weaken their attacks
L_DD3WaveReinforcements:
    set $@DD_UNITS, $@DD_UNITS-$@DD_INT;
    set $@DD_UNITS, $@DD_UNITS*$DOOMSDAY_CLUES/3;
    set $@DD_INT, 0;

    if ($@DD_UNITS > 0)
        goto L_DD3WRCallsub;
    goto L_DDAdvanceWavePost;

L_DD3WRCallsub:
    callsub S_DD3ThirdSpawns;
    goto L_DDAdvanceWavePost;

// Clear temporary variables and broadcast
L_DDAdvanceWavePost:
    set $@DD_IDX, 0;
    set $@DD_INT, 0;
    set $@DD_UNITS, 0;

    // Tell users
    mapannounce $@DD_LOC$, "Jande : Watch out, another wave! Only "+(6-$@DD_NUMWAVES)+" waves left!", 0;

    // Prepare optional boss
    set $@DD_IDX1, rand(getarraysize($@DD_XPOS));
    set $@DD_IDX2, rand(getarraysize($@doomsday_boss));

    // Spawn optional boss if req. is met
    if ($@DD_NUMWAVES > 6-$DOOMSDAY_CLUES)
        monster $@DD_LOC$, $@DD_XPOS[$@DD_IDX1], $@DD_YPOS[$@DD_IDX1], "", $@doomsday_boss[$@DD_IDX2], 1, "Doomsday::OnDeathAct3";
    end;




// Tulimshar Siege points
L_DD3Tulim:
    // Compulsory spawns
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 98, 75, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 97, 86, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    // Non-compulsory spawns
    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 91, 99, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 75, 104, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 56, 81, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 44, 63, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 76, 76, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 54, 96, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    // No extra spawns possible
    goto L_DDAdvanceTimers;



// Hurnscald Siege points
L_DD3Hurns:
    // Compulsory spawns
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 138, 63, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 136, 71, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    // Non-compulsory spawns
    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 133, 79, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 111, 74, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 94, 75, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 79, 64, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 67, 82, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 88, 90, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    // No extra spawns possible
    goto L_DDAdvanceTimers;



// Nivalis Siege points
L_DD3Nival:
    // Compulsory spawns
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 90, 47, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 62, 49, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    // Non-compulsory spawns
    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 63, 61, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 56, 83, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 70, 41, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 36, 37, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 62, 26, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    if ($@DD_INT >= $@DD_UNITS*2) goto L_DDAdvanceTimers;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 85, 30, "", $@doomsday_mobs[$@DD_IDX], 1, "Doomsday::OnDeathAct3";
    set $@DD_INT, $@DD_INT+1;

    // No extra spawns possible
    goto L_DDAdvanceTimers;




// Extra wave control system [0]
S_DD3ThirdSpawns:
    set $@DD_IDX1, rand(getarraysize($@DD_XPOS));
    set $@DD_IDX2, rand(getarraysize($@doomsday_mobs));

    monster $@DD_LOC$, $@DD_XPOS[$@DD_IDX1], $@DD_YPOS[$@DD_IDX1], "", $@doomsday_mobs[$@DD_IDX2], 1, "Doomsday::OnDeathAct3";

    set $@DD_INT, $@DD_INT+1;
    if($@DD_INT < $@DD_UNITS) goto S_DD3ThirdSpawns;
    return;

// Extra wave control system [1]
L_DD3FirstThird:
    set $@DD_UNITS, getmapusers($@DD_LOC$)-mobcount($@DD_LOC$, "Doomsday::OnDeathAct3")+1;
    set $@DD_INT, 0;

    // Difficulty adjustment: Invoke -1 mob per player and +1 mob per 2 score points
    set $@DD_UNITS, $@DD_UNITS-getmapusers($@DD_LOC$)+($DOOMSDAY_SCORE/2);

    // Monsters already overpower players
    if ($@DD_UNITS < 0)
        goto L_DD3EndThird;

    // Prepare optional boss
    set $@DD_IDX1, rand(getarraysize($@DD_XPOS));
    set $@DD_IDX2, rand(getarraysize($@doomsday_boss));

    // Spawn optional boss
    if ($@DD_NUMWAVES == 5 && $DOOMSDAY_SCORE > 6)
        monster $@DD_LOC$, $@DD_XPOS[$@DD_IDX1], $@DD_YPOS[$@DD_IDX1], "", $@doomsday_boss[$@DD_IDX2], 1, "Doomsday::OnDeathAct3";

    // Spawn first third's wave
    callsub S_DD3ThirdSpawns;
    goto L_DD3EndThird;

// Extra wave control system [2]
L_DD3SecondThird:
    set $@DD_UNITS, getmapusers($@DD_LOC$)-mobcount($@DD_LOC$, "Doomsday::OnDeathAct3")+1;
    set $@DD_INT, 0;

    // Intensity control
    if ($DOOMSDAY_SCORE < 12-$DOOMSDAY_CLUES)
        goto L_DD3EndThird;

    // Difficulty adjustment: Invoke -1 mob per player and +1 mob per 3 score points
    set $@DD_UNITS, $@DD_UNITS-getmapusers($@DD_LOC$)+($DOOMSDAY_SCORE/3);

    // Prepare optional boss
    set $@DD_IDX1, rand(getarraysize($@DD_XPOS));
    set $@DD_IDX2, rand(getarraysize($@doomsday_boss));

    // Spawn optional boss
    if ($@DD_NUMWAVES == 5)
        monster $@DD_LOC$, $@DD_XPOS[$@DD_IDX1], $@DD_YPOS[$@DD_IDX1], "", $@doomsday_boss[$@DD_IDX2], 1, "Doomsday::OnDeathAct3";

    // Monsters already overpower players
    if ($@DD_UNITS < 0)
        goto L_DD3EndThird;

    // Spawn second third's wave
    callsub S_DD3ThirdSpawns;
    goto L_DD3EndThird;

// Extra wave control system [3]
L_DD3EndThird:
    set $@DD_UNITS, 0;
    set $@DD_IDX1, 0;
    set $@DD_IDX2, 0;
    set $@DD_INT, 0;
    end;



// Timer controls (5 minutes between waves);
// It only fires after first wave
L_TimerCheck2:
    if ($@DD_NUMWAVES > 0)
        goto L_DDAdvanceWave;
    end;

// Siege one hour condition fully elapsed
L_Doomsday3Check:
    set $@DoomsdayMc, mobcount($@DD_LOC$, "Doomsday::OnDeathAct3")+1;
    if ($@DoomsdayMc > 0)
        goto L_Doomsday3Defeat;
    goto L_Doomsday3Victory;

// Town was defeated
L_Doomsday3Defeat:
    // Warn players that town is in danger
    mapannounce $@DD_LOC$, "Jande : Oh noes, "+$@DoomsdayMc+" monsters passed the barricate!!", 0;

    // Move the monsters to town
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    if ($@DoomsdayLoc == 0)
        areamonster "001-1", 52, 35, 119, 113, "", $@doomsday_mobs[$@DD_IDX], $@DoomsdayMc;
    if ($@DoomsdayLoc == 1)
        areamonster "009-1", 25, 25, 96, 53, "", $@doomsday_mobs[$@DD_IDX], $@DoomsdayMc;
    if ($@DoomsdayLoc == 2)
        areamonster "020-1", 24, 32, 99, 96, "", $@doomsday_mobs[$@DD_IDX], $@DoomsdayMc;

    // Update defeat counter and advance
    set $DOOMSDAY_TOWN[$@DoomsdayLoc], $DOOMSDAY_TOWN[$@DoomsdayLoc]+1;
    set $@DD_IDX, 0;
    goto L_Doomsday3Cleanup;

// Siege was cleared up
L_Doomsday3Victory:
    set $DOOMSDAY_SCORE, $DOOMSDAY_SCORE+1;
    mapannounce $@DD_LOC$, "Jande : That was a close call, but we did it! We defended "+$DOOMSDAY_SCORE+" times.", 0;
    goto L_Doomsday3Cleanup;

// Clean up temporary variables (except skip)
L_Doomsday3Cleanup:
    killmonster $@DD_LOC$, "Doomsday::OnDeathAct3";
    set $@DD_NUMWAVES, 0;
    set $@DoomsdayLoc, 0;
    set $@DoomsdayMc, 0;
    set $@DD_LOC$, "";
    cleararray $@DD_XPOS, 0, 8;
    cleararray $@DD_YPOS, 0, 8;
    end;

// Bonus spawn
L_Doomsday3Bonus:
    announce "Jande : Stray minions from Zax De'Kagen army were sighted all over the world!", 0;
    set $@DD_UNITS, 2+($DOOMSDAY_SCORE/5);

    // Cap value (to prevent huge spikes)
    if ($@DD_UNITS > 5)
        set $@DD_UNITS, 3+($DOOMSDAY_SCORE/10);

    // Sum the permanent clues
    set $@DD_UNITS, $@DD_UNITS+$DOOMSDAY_CLUES;

    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "031-1", 62, 49, "", $@doomsday_mobs[$@DD_IDX], 1+$DOOMSDAY_CLUES;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "018-1", 136, 71, "", $@doomsday_mobs[$@DD_IDX], 1+$DOOMSDAY_CLUES;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    monster "002-1", 97, 86, "", $@doomsday_mobs[$@DD_IDX], 1+$DOOMSDAY_CLUES;

    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    areamonster "017-1", 169, 49, 198, 77, "", $@doomsday_mobs[$@DD_IDX], 1+$DOOMSDAY_CLUES;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    areamonster "012-1", 20, 47, 74, 77, "", $@doomsday_mobs[$@DD_IDX], $@DD_UNITS;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    areamonster "057-1", 115, 50, 140, 75, "", $@doomsday_mobs[$@DD_IDX], $@DD_UNITS;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    areamonster "046-1", 58, 49, 92, 70, "", $@doomsday_mobs[$@DD_IDX], $@DD_UNITS;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    areamonster "034-1", 83, 51, 121, 98, "", $@doomsday_mobs[$@DD_IDX], $@DD_UNITS;
    set $@DD_IDX, rand(getarraysize($@doomsday_mobs));
    areamonster "003-4", 20, 20, 85, 60, "", $@doomsday_mobs[$@DD_IDX], $@DD_UNITS;

    // Tormenta
    if (rand(10) <= $DOOMSDAY_CLUES)
        monster "057-1", 126, 64, "", 1137, 1;

    set $@DD_UNITS, 0;
    set $@DD_IDX, 0;
    end;

// Act 4 System
L_Doomsday4Check:
    // Magic number: 21
    if ($DOOMSDAY_SCORE >= 20-$DOOMSDAY_CLUES)
        goto L_DD4WarnSeq;
    end;

L_DD4WarnSeq:
    areatimer 0, $@DD_LOC$, 20, 20, 500, 500, 100, "Doomsday::OnDD4Warning1";
    announce "Jande : ##1##BWarning: ##bZax's Golem spawning! Defeat it!!", 0;
    addnpctimer 7500, "Doomsday::OnDD4Spawn";
    end;

OnDD4Warning1:
    mapmask 1 | 2;
    music "Dramatic.ogg";
    areatimer 0, $@DD_LOC$, 20, 20, 500, 500, 600, "Doomsday::OnDD4Warning2";
    end;

OnDD4Warning2:
    misceffect 51, strcharinfo(0);
    areatimer 0, $@DD_LOC$, 20, 20, 500, 500, 7000, "Doomsday::OnDD4Warning3";
    end;

OnDD4Warning3:
    mapmask 1;
    end;

OnDD4Spawn:
    set $@DD_IDX1, rand(getarraysize($@DD_XPOS));
    monster $@DD_LOC$, $@DD_XPOS[$@DD_IDX1], $@DD_YPOS[$@DD_IDX1], "", 1145, 1, "Doomsday::OnDeathAct4";
    //debugmes "Success "+$@DD_LOC$+" ("+$@DD_XPOS[$@DD_IDX1]+", "+$@DD_YPOS[$@DD_IDX1]+")";
    mapannounce $@DD_LOC$, "Golem : FRAIL SMALL PEOPLE, ME SMASH!!!", 0;
    // Spawn a few mobs
    set $@DD_INT, 0;
    set $@DD_UNITS, $DOOMSDAY_CLUES*4;
    callsub S_DD3ThirdSpawns;
    goto OnDD4Smash;

// Could use a new optional skill: FRAIL NOOBS, ZAX RULES! (causes new wave of 6 monsters)
OnDD4Smash:
    // Golem got itself smashed D:
    if ($@DD_LOC$ == "")
        end;
    if (!(mobcount($@DD_LOC$, "Doomsday::OnDeathAct4")+1))
        end;
    // TODO: Do not keep repeating the announce
    //mapannounce $@DD_LOC$, "Golem : FRAIL SMALL PEOPLE, ME SMASH!!!", 0;
    areatimer 0, $@DD_LOC$, 20, 20, 500, 500, 100, "Doomsday::OnDD4Smashed";
    addnpctimer rand(12000, 18000), "Doomsday::OnDD4Smash";
    end;

OnDD4Smashed:
    misceffect 52, strcharinfo(0);
    heal -70-BaseLevel, 0;
    end;

// For surviving
OnDD4SurvivorReward:
    getexp 10000, 0;
    end;


////////////////////////////////////////////////////////////////////////////////
// Act 5 utils
L_Doomsday5:
    if ($DOOMSDAY_SUMMON == 2)
        goto L_MenhirUpdate;
    end;

////////////////////////////////////////////////////////////////////////////////
// Respawn logic (5 minutes)
OnTimer100000:
    if ($DOOMSDAY == 2)
        goto L_DD3FirstThird;
    end;

OnTimer200000:
    if ($DOOMSDAY == 2)
        goto L_DD3SecondThird;
    end;

OnTimer300000:
    if ($DOOMSDAY == 1)
        goto L_Doomsday1Respawn;
    if ($DOOMSDAY == 2)
        goto L_TimerCheck2;
    goto L_TimerFinish;

// Once all timer checks are over
L_TimerFinish:
    set $@DoomsdayMc, 0;
    setnpctimer 0;
    stopnpctimer;
    end;

// Act 3 clock handlers [1]
OnClock1750:
    if ($@DOOMSDAY_SKIP)
        end;
    if ($DOOMSDAY == 2)
        goto L_Doomsday3Init;
    end;

OnClock1800:
    if ($@DOOMSDAY_SKIP)
        end;
    if ($DOOMSDAY == 2)
        goto L_Doomsday3;
    end;

OnClock1830:
    if ($@DOOMSDAY_SKIP)
        end;
    if ($DOOMSDAY == 2)
        goto L_Doomsday4Check;
    end;

// 19h -> 18h45
OnClock1845:
    if ($@DOOMSDAY_SKIP)
        goto L_Doomsday3Skip;
    if ($DOOMSDAY == 2)
        goto L_Doomsday3Check;
    end;

// Act 3 clock handlers [2]
OnClock2350:
    if ($@DOOMSDAY_SKIP)
        end;
    if ($DOOMSDAY == 2)
        goto L_Doomsday3Init;
    end;

OnClock0000:
    if ($@DOOMSDAY_SKIP)
        end;
    if ($DOOMSDAY == 2)
        goto L_Doomsday3;
    end;

OnClock0030:
    if ($@DOOMSDAY_SKIP)
        end;
    if ($DOOMSDAY == 2)
        goto L_Doomsday4Check;
    end;

OnClock0045:
    if ($@DOOMSDAY_SKIP)
        goto L_Doomsday3Skip;
    if ($DOOMSDAY == 2)
        goto L_Doomsday3Check;
    end;

// Act 3 clock handlers [3]
OnClock0900:
    if ($DOOMSDAY == 2)
        goto L_Doomsday3Bonus;
    end;

////////////////////////////////////////////////////////////////////////////////
// Puppet labels
OnDeathMapname:
    if ($DOOMSDAY == 1)
        set $DOOMSDAY_CNT, $DOOMSDAY_CNT+1;
    startnpctimer;
    end;

OnDeathAct3:
    end;

OnDeathAct4:
    set $DOOMSDAY_SCORE, 0;
    set $DOOMSDAY_CLUES, $DOOMSDAY_CLUES+1;
    announce "Jande : Golem destroyed, crisis averted. I'll be resetting the number of victories.", 0;
    if ($@DD_LOC$ == "")
        end;
    areatimer 0, $@DD_LOC$, 20, 20, 500, 500, 100, "Doomsday::OnDD4SurvivorReward";
    end;

}