summaryrefslogblamecommitdiff
path: root/npc/functions/siege.txt
blob: af6198446d4769c1687b6c863c8d46d68e906c9b (plain) (tree)


















                                                                                                                                                      








                                                                                 
                                                 



                            
                                                                                         





                            
                                                                                 





                                         
                                                            
                                          








                                                                                   
                                                                                








                                                              
                                
                                                                       
                                                                     















































                                                        
// TMW2 scripts.
// Authors:
//    Jesusalva
// Description:
//    Town Siege utilities

// Siege Spawn
// Can be used anywhere to spawn on the whole map, margins respected.
// siege_spawn( map, mobID, Amount, eventID )
function	script	siege_spawn	{
    .@mp$=getarg(0);
    .@mid=getarg(1);
    .@qnt=getarg(2);
    .@ev$=getarg(3);

    areamonster(.@mp$, 20, 20, getmapinfo(MAPINFO_SIZE_X, .@mp$)-20, getmapinfo(MAPINFO_SIZE_Y, .@mp$)-20, strmobinfo(1, .@mid), .@mid, .@qnt, .@ev$);
    return;
}

// Calculate player average level
// if highest is set, it will return highest player level, with minimum the value
// passed. (A level "0" is clearly not valid, of course)
// siege_calcdiff ( map{, highest_lvl} )
function	script	siege_calcdiff	{
    .@bsum=0;
    .@highest=getarg(1, false);
    .@c = getunits(BL_PC, .@players, false, getarg(0));
    for (.@i = 0; .@i < .@c; .@i++) {
        .@b=readparam(BaseLevel, .@players[.@i]);
        .@bsum+=.@b;
        if (.@b > .@highest)
            .@highest=.@b;
    }
    debugmes "calcdiff: Total %d Average %d Highest %d", .@bsum, (.@bsum/.@c), .@highest;
    if (getarg(1,false))
        return .@highest;
    else
        return (.@bsum/.@c);
}

// push to $@SIEGE_TMPMOBS the <mobID> if their level is within a 15 levels range
// above or below <level>
// siege_push ( mobID, level )
function	script	siege_push	{
    .@mi=getarg(0);
    .@lv=getarg(1,0);

    if ( is_between(.@lv-15, .@lv+15, strmobinfo(3, .@mi)) )
        array_push($@SIEGE_TMPMOBS, .@mi);
    return;
}

// Selects a monster based on player average strength and base difficulty
// It'll select monsters from 20 levels below to 20 levels above
// tp_mask is the same as TP_* constants and changes mobs present. Only TP_TULIM,
// TP_HURNS and TP_NIVAL are supported. You can use them with the "|" operand, eg.,
// TP_TULIM | TP_HURNS.
//
// It currently only creates $@SIEGE_TMPMOBS, you need to use any_of() manually.
// siege_selectmob ( blvl, difficulty{, tp_mask} )
function	script	siege_selectmob	{
    .@blv=getarg(0);
    .@dif=getarg(1);
    .@tp=getarg(2, 0);

    // We don't need .@dif, so we convert difficulty to levels
    .@blv+=.@dif*3;

    deletearray $@SIEGE_TMPMOBS;
    setarray $@SIEGE_TMPMOBS, ManaGhost, CandiedSlime, Bif, SlimeBlast;
    // Now we must select mobs, using array_push() to $@SIEGE_TMPMOBS
    // First, mobs on all envs
    siege_push(BlackScorpion, .@blv);
    siege_push(GreenSlime, .@blv);
    siege_push(CaveMaggot, .@blv);
    siege_push(MagicGoblin, .@blv);
    siege_push(AngryBat, .@blv);
    siege_push(BlackSlime, .@blv);
    siege_push(BlackScorpion, .@blv);
    siege_push(Forain, .@blv);
    siege_push(GreenDragon, .@blv);
    siege_push(Terranite, .@blv);
    siege_push(JackO, .@blv);
    siege_push(BlackMamba, .@blv);
    siege_push(TerraniteProtector, .@blv);

    // Now, mobs on only certain envs
    if (.@tp & TP_TULIM) {
        siege_push(AngryScorpion, .@blv);
        siege_push(AngryRedScorpion, .@blv);
        siege_push(DesertBandit, .@blv);
        siege_push(LavaSlime, .@blv);
        siege_push(OldSnake, .@blv);
        siege_push(Snake, .@blv);
    }
    if (.@tp & TP_HURNS) {
        siege_push(RedSlime, .@blv);
        siege_push(Bandit, .@blv);
        siege_push(RedMushroom, .@blv);
        siege_push(RobinBandit, .@blv);
        siege_push(AngryYellowSlime, .@blv);
        siege_push(GrassSnake, .@blv);
        siege_push(WickedMushroom, .@blv);
    }
    if (.@tp & TP_NIVAL) {
        siege_push(Bluepar, .@blv);
        siege_push(Wolvern, .@blv);
        siege_push(Yeti, .@blv);
        siege_push(Moggun, .@blv); // PS. Not aggressive
    }

    // Removed
    //siege_push(DarkLizard, .@blv);
    //siege_push(Crafty, .@blv);

    return;
}