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

« back to all changes in this revision

Viewing changes to source/src/hudgun.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
VARP(nosway, 0, 0, 1);
 
2
VARP(swayspeeddiv, 1, 105, 1000);
 
3
VARP(swaymovediv, 1, 200, 1000); 
 
4
VARP(swayupspeeddiv, 1, 105, 1000);
 
5
VARP(swayupmovediv, 1, 200, 1000); 
 
6
 
 
7
struct weaponmove
 
8
{
 
9
    static vec swaydir;
 
10
    static int swaymillis, lastsway;
 
11
 
 
12
    float k_rot, kick;
 
13
    vec pos;
 
14
    int anim, basetime;
 
15
    
 
16
        weaponmove() : k_rot(0), kick(0), anim(0), basetime(0) { pos.x = pos.y = pos.z = 0.0f; }
 
17
 
 
18
    void calcmove(vec aimdir, int lastaction)
 
19
    {
 
20
        kick = k_rot = 0.0f;
 
21
        pos = player1->o;
 
22
        
 
23
        if(!nosway)
 
24
        {
 
25
            float k = pow(0.7f, (lastmillis-lastsway)/10.0f);
 
26
            swaydir.mul(k);
 
27
            vec dv(player1->vel);
 
28
            dv.mul((1-k)/max(player1->vel.magnitude(), player1->maxspeed));
 
29
            dv.x *= 1.5f;
 
30
            dv.y *= 1.5f;
 
31
            dv.z *= 0.4f;
 
32
            swaydir.add(dv);
 
33
            pos.add(swaydir);
 
34
        }
 
35
 
 
36
        if(player1->onfloor || player1->onladder || player1->inwater) swaymillis += lastmillis-lastsway;
 
37
        lastsway = lastmillis;
 
38
 
 
39
        if(player1->weaponchanging)
 
40
        {
 
41
            anim = ANIM_GUN_RELOAD;
 
42
            basetime = player1->weaponchanging;
 
43
            float progress = clamp((lastmillis - player1->weaponchanging)/(float)weapon::weaponchangetime, 0.0f, 1.0f);
 
44
            k_rot = -90*sinf(progress*M_PI);
 
45
        }
 
46
        else if(player1->weaponsel->reloading)
 
47
        {
 
48
            anim = ANIM_GUN_RELOAD;
 
49
            basetime = player1->weaponsel->reloading;
 
50
            float reloadtime = (float)player1->weaponsel->info.reloadtime,
 
51
                  progress = clamp((lastmillis - player1->weaponsel->reloading)/reloadtime, 0.0f, clamp(1.0f - (player1->lastaction + player1->weaponsel->gunwait - lastmillis)/reloadtime, 0.5f, 1.0f));
 
52
            k_rot = -90*sinf(progress*M_PI);
 
53
        }
 
54
        else
 
55
        {
 
56
            anim = ANIM_GUN_IDLE;
 
57
            basetime = lastaction;
 
58
 
 
59
            int timediff = lastmillis-lastaction, 
 
60
                animtime = min(player1->weaponsel->gunwait, (int)player1->weaponsel->info.attackdelay);
 
61
            vec sway = aimdir;
 
62
            float progress = 0.0f;
 
63
            float k_back = 0.0f;
 
64
            
 
65
            if(player1->weaponsel==player1->lastattackweapon)
 
66
            {
 
67
                progress = max(0.0f, min(1.0f, timediff/(float)animtime));
 
68
                // f(x) = -sin(x-1.5)^3
 
69
                kick = -sinf(pow((1.5f*progress)-1.5f,3));
 
70
                if(player1->crouching) kick *= 0.75f;
 
71
                if(player1->lastaction) anim = player1->weaponsel->modelanim();
 
72
            }
 
73
            
 
74
            if(player1->weaponsel->info.mdl_kick_rot || player1->weaponsel->info.mdl_kick_back)
 
75
            {
 
76
                k_rot = player1->weaponsel->info.mdl_kick_rot*kick;
 
77
                k_back = player1->weaponsel->info.mdl_kick_back*kick/10;
 
78
            }
 
79
            
 
80
            if(nosway) sway.x = sway.y = sway.z = 0;
 
81
            else
 
82
            {
 
83
                float swayspeed = sinf((float)swaymillis/swayspeeddiv)/(swaymovediv/10.0f);
 
84
                float swayupspeed = cosf((float)swaymillis/swayupspeeddiv)/(swayupmovediv/10.0f);
 
85
 
 
86
                float plspeed = min(1.0f, sqrtf(player1->vel.x*player1->vel.x + player1->vel.y*player1->vel.y));
 
87
                
 
88
                swayspeed *= plspeed/2;
 
89
                swayupspeed *= plspeed/2;
 
90
 
 
91
                swap(sway.x, sway.y);
 
92
                sway.y = -sway.y;
 
93
                
 
94
                swayupspeed = fabs(swayupspeed); // sway a semicirle only
 
95
                sway.z = 1.0f;
 
96
                
 
97
                sway.x *= swayspeed;
 
98
                sway.y *= swayspeed;
 
99
                sway.z *= swayupspeed;
 
100
 
 
101
                if(player1->crouching) sway.mul(0.75f);
 
102
            }
 
103
            
 
104
            pos.x -= aimdir.x*k_back+sway.x;
 
105
            pos.y -= aimdir.y*k_back+sway.y;
 
106
            pos.z -= aimdir.z*k_back+sway.z;
 
107
        }
 
108
    }
 
109
};
 
110
 
 
111
vec weaponmove::swaydir(0, 0, 0);
 
112
int weaponmove::lastsway = 0, weaponmove::swaymillis = 0;
 
113
 
 
114
void preload_hudguns()
 
115
{
 
116
    loopi(NUMGUNS)
 
117
    {
 
118
        s_sprintfd(path)("weapons/%s", guns[i].modelname);
 
119
        loadmodel(path);
 
120
    }
 
121
}
 
122