summaryrefslogtreecommitdiff
path: root/npc/functions/npcmove.txt
blob: 783539a9d71c52ba5bbd352c07113110939b4bbd (plain) (blame)
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
// Evol functions.
// Authors:
//    4144
// Description:
//    Moving npc utility functions
// Variables:
//    none

function	script	initpath	{
    deletearray getvariableofnpc(.movepathcmd$, strnpcinfo(3));
    deletearray getvariableofnpc(.movepathy, strnpcinfo(3));
    deletearray getvariableofnpc(.movepathx, strnpcinfo(3));
    .@cnt = 0;

    for (.@f = 0; .@f < getargcount(); .@f = .@f + 3)
    {
        set getvariableofnpc(.movepathcmd$[.@cnt], strnpcinfo(3)), getarg(.@f);
        set getvariableofnpc(.movepathx[.@cnt], strnpcinfo(3)), getarg(.@f + 1);
        set getvariableofnpc(.movepathy[.@cnt], strnpcinfo(3)), getarg(.@f + 2);
        .@cnt ++;
    }
    //debugmes "array size: " + str(getarraysize(getvariableofnpc(.movepath, strnpcinfo(3))));
    return;
}

function	script	domoveaction	{
    //debugmes "domoveaction: " + str(getvariableofnpc(.movepos, strnpcinfo(3)));
    .@pos = getvariableofnpc(.movepos, strnpcinfo(3));
    if (.@pos >= getarraysize(getvariableofnpc(.movepathx, strnpcinfo(3))) || .@pos < 0)
        return;
    //debugmes "walking";
    .@cmd$ = getvariableofnpc(.movepathcmd$[.@pos], strnpcinfo(3));
    //debugmes "cmd: " + .@cmd$;

    if (.@cmd$ == "move")
    {
        npcwalkto getvariableofnpc(.movepathx[.@pos], strnpcinfo(3)), getvariableofnpc(.movepathy[.@pos], strnpcinfo(3));
    }
    else if (.@cmd$ == "dir")
    {
        setnpcdir getvariableofnpc(.movepathx[.@pos], strnpcinfo(3));
    }
    else if (.@cmd$ == "wait")
    {
        set getvariableofnpc(.waitticks, strnpcinfo(3)), getvariableofnpc(.movepathx[.@pos], strnpcinfo(3));
    }
    return 1;
}

function	script	movetonextpos	{
    .@pos = getvariableofnpc(.movepos, strnpcinfo(3));
    //debugmes "movetonextpos: " + str(.@pos);
    .@wait = getvariableofnpc(.waitticks, strnpcinfo(3));
    if (.@wait > 0)
    {
        .@wait --;
        //debugmes "wait";
        set getvariableofnpc(.waitticks, strnpcinfo(3)), .@wait;
        return;
    }
    .@res = domoveaction(.@pos);
    if (.@res)
    {
        .@pos++;
        if (.@pos >= getarraysize(getvariableofnpc(.movepathx, strnpcinfo(3))))
            .@pos = 0;
        set getvariableofnpc(.movepos, strnpcinfo(3)), .@pos;
    }
    return;
}

function	script	initialmove	{
    set getvariableofnpc(.movepos, strnpcinfo(3)), 0;
    set getvariableofnpc(.waitticks, strnpcinfo(3)), -1;
    movetonextpos;
    return;
}

function	script	getmovecmd	{
    .@pos = getvariableofnpc(.movepos, strnpcinfo(3));
    if (.@pos >= getarraysize(getvariableofnpc(.movepathx, strnpcinfo(3))) || .@pos < 0)
        return "";
    return getvariableofnpc(.movepathcmd$[.@pos], strnpcinfo(3));
}