~ubuntu-branches/debian/stretch/assaultcube-data/stretch

« back to all changes in this revision

Viewing changes to source/src/serverevents.h

  • Committer: Bazaar Package Importer
  • Author(s): Gonéri Le Bouder, Ansgar Burchardt, Gonéri Le Bouder
  • Date: 2010-04-02 23:37:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100402233755-kf74fxwlu634o6vg
Tags: 1.0.4+repack1-1
[ Ansgar Burchardt ]
* debian/control: fix typo in short description

[ Gonéri Le Bouder ]
* Upgrade to 1.0.4
* bump standards-version to 3.8.4
* Add Depends: ${misc:Depends} just to avoid a lintian warning
* Add a debian/source/format file for the same reason

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// processing of server events
 
2
 
 
3
void processevent(client *c, explodeevent &e)
 
4
{
 
5
    clientstate &gs = c->state;
 
6
    switch(e.gun)
 
7
    {
 
8
        case GUN_GRENADE:
 
9
            if(!gs.grenades.remove(e.id)) return;
 
10
            break;
 
11
 
 
12
        default:
 
13
            return;
 
14
    }
 
15
    for(int i = 1; i<c->events.length() && c->events[i].type==GE_HIT; i++)
 
16
    {
 
17
        hitevent &h = c->events[i].hit;
 
18
        if(!clients.inrange(h.target)) continue;
 
19
        client *target = clients[h.target];
 
20
        if(target->type==ST_EMPTY || target->state.state!=CS_ALIVE || h.lifesequence!=target->state.lifesequence || h.dist<0 || h.dist>EXPDAMRAD) continue;
 
21
 
 
22
        int j = 1;
 
23
        for(j = 1; j<i; j++) if(c->events[j].hit.target==h.target) break;
 
24
        if(j<i) continue;
 
25
 
 
26
        int damage = int(guns[e.gun].damage*(1-h.dist/EXPDAMRAD));
 
27
        serverdamage(target, c, damage, e.gun, true, h.dir);
 
28
    }
 
29
}
 
30
 
 
31
void processevent(client *c, shotevent &e)
 
32
{
 
33
    clientstate &gs = c->state;
 
34
    int wait = e.millis - gs.lastshot;
 
35
    if(!gs.isalive(gamemillis) ||
 
36
       e.gun<GUN_KNIFE || e.gun>=NUMGUNS ||
 
37
       wait<gs.gunwait[e.gun] ||
 
38
       gs.mag[e.gun]<=0)
 
39
        return;
 
40
    if(e.gun!=GUN_KNIFE) gs.mag[e.gun]--;
 
41
    loopi(NUMGUNS) if(gs.gunwait[i]) gs.gunwait[i] = max(gs.gunwait[i] - (e.millis-gs.lastshot), 0);
 
42
    gs.lastshot = e.millis;
 
43
    gs.gunwait[e.gun] = attackdelay(e.gun);
 
44
    if(e.gun==GUN_PISTOL && gs.akimbomillis>gamemillis) gs.gunwait[e.gun] /= 2;
 
45
    sendf(-1, 1, "ri9x", SV_SHOTFX, c->clientnum, e.gun,
 
46
        int(e.from[0]*DMF), int(e.from[1]*DMF), int(e.from[2]*DMF),
 
47
        int(e.to[0]*DMF), int(e.to[1]*DMF), int(e.to[2]*DMF),
 
48
        c->clientnum);
 
49
    gs.shotdamage += guns[e.gun].damage*(e.gun==GUN_SHOTGUN ? SGRAYS : 1);
 
50
    switch(e.gun)
 
51
    {
 
52
        case GUN_GRENADE: gs.grenades.add(e.id); break;
 
53
        default:
 
54
        {
 
55
            int totalrays = 0, maxrays = e.gun==GUN_SHOTGUN ? SGRAYS : 1;
 
56
            for(int i = 1; i<c->events.length() && c->events[i].type==GE_HIT; i++)
 
57
            {
 
58
                hitevent &h = c->events[i].hit;
 
59
                if(!clients.inrange(h.target)) continue;
 
60
                client *target = clients[h.target];
 
61
                if(target->type==ST_EMPTY || target->state.state!=CS_ALIVE || h.lifesequence!=target->state.lifesequence) continue;
 
62
 
 
63
                int rays = e.gun==GUN_SHOTGUN ? h.info : 1;
 
64
                if(rays<1) continue;
 
65
                totalrays += rays;
 
66
                if(totalrays>maxrays) continue;
 
67
 
 
68
                bool gib = false;
 
69
                if(e.gun==GUN_KNIFE) gib = true;
 
70
                else if(e.gun==GUN_SNIPER) gib = h.info!=0;
 
71
                int damage = rays*guns[e.gun].damage;
 
72
                if(e.gun==GUN_SNIPER && gib) damage *= 3;
 
73
                serverdamage(target, c, damage, e.gun, gib, h.dir);
 
74
            }
 
75
            break;
 
76
        }
 
77
    }
 
78
}
 
79
 
 
80
void processevent(client *c, suicideevent &e)
 
81
{
 
82
    serverdamage(c, c, 1000, GUN_KNIFE, false);
 
83
}
 
84
 
 
85
void processevent(client *c, pickupevent &e)
 
86
{
 
87
    clientstate &gs = c->state;
 
88
    if(m_mp(gamemode) && !gs.isalive(gamemillis)) return;
 
89
    serverpickup(e.ent, c->clientnum);
 
90
}
 
91
 
 
92
void processevent(client *c, reloadevent &e)
 
93
{
 
94
    clientstate &gs = c->state;
 
95
    if(!gs.isalive(gamemillis) ||
 
96
       e.gun<GUN_KNIFE || e.gun>=NUMGUNS ||
 
97
       !reloadable_gun(e.gun) ||
 
98
       gs.ammo[e.gun]<=0)
 
99
        return;
 
100
 
 
101
    bool akimbo = e.gun==GUN_PISTOL && gs.akimbomillis>e.millis;
 
102
    int mag = (akimbo ? 2 : 1) * magsize(e.gun), numbullets = min(gs.ammo[e.gun], mag - gs.mag[e.gun]);
 
103
    if(numbullets<=0) return;
 
104
 
 
105
    gs.mag[e.gun] += numbullets;
 
106
    gs.ammo[e.gun] -= numbullets;
 
107
 
 
108
    int wait = e.millis - gs.lastshot;
 
109
    sendf(-1, 1, "ri3", SV_RELOAD, c->clientnum, e.gun);
 
110
    if(gs.gunwait[e.gun] && wait<gs.gunwait[e.gun]) gs.gunwait[e.gun] += reloadtime(e.gun);
 
111
    else
 
112
    {
 
113
        loopi(NUMGUNS) if(gs.gunwait[i]) gs.gunwait[i] = max(gs.gunwait[i] - (e.millis-gs.lastshot), 0);
 
114
        gs.lastshot = e.millis;
 
115
        gs.gunwait[e.gun] += reloadtime(e.gun);
 
116
    }
 
117
}
 
118
 
 
119
void processevent(client *c, akimboevent &e)
 
120
{
 
121
    clientstate &gs = c->state;
 
122
    if(!gs.isalive(gamemillis) || gs.akimbos<=0) return;
 
123
    gs.akimbos--;
 
124
    gs.akimbomillis = e.millis+30000;
 
125
}
 
126
 
 
127
void clearevent(client *c)
 
128
{
 
129
    int n = 1;
 
130
    while(n<c->events.length() && c->events[n].type==GE_HIT) n++;
 
131
    c->events.remove(0, n);
 
132
}
 
133
 
 
134
void processevents()
 
135
{
 
136
    loopv(clients)
 
137
    {
 
138
        client *c = clients[i];
 
139
        if(c->type==ST_EMPTY) continue;
 
140
        while(c->events.length())
 
141
        {
 
142
            gameevent &e = c->events[0];
 
143
            if(e.type<GE_SUICIDE)
 
144
            {
 
145
                if(e.shot.millis>gamemillis) break;
 
146
                if(e.shot.millis<c->lastevent) { clearevent(c); continue; }
 
147
                c->lastevent = e.shot.millis;
 
148
            }
 
149
            switch(e.type)
 
150
            {
 
151
                case GE_SHOT: processevent(c, e.shot); break;
 
152
                case GE_EXPLODE: processevent(c, e.explode); break;
 
153
                case GE_AKIMBO: processevent(c, e.akimbo); break;
 
154
                case GE_RELOAD: processevent(c, e.reload); break;
 
155
                // untimed events
 
156
                case GE_SUICIDE: processevent(c, e.suicide); break;
 
157
                case GE_PICKUP: processevent(c, e.pickup); break;
 
158
            }
 
159
            clearevent(c);
 
160
        }
 
161
    }
 
162
}
 
163