aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/game/PlayerClientAdapters.java
blob: 198c1246367889bacf96219503ff20860712db98 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 1997-2001 Id Software, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.
 * 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */

// Created on 26.02.2004 by RST.
// $Id: PlayerClientAdapters.java,v 1.3 2004-09-22 19:22:05 salomo Exp $
package jake2.game;

import jake2.Defines;
import jake2.util.Lib;
import jake2.util.Math3D;

public class PlayerClientAdapters {

    //
    // Gross, ugly, disgustuing hack section
    //

    // this function is an ugly as hell hack to fix some map flaws
    //
    // the coop spawn spots on some maps are SNAFU. There are coop spots
    // with the wrong targetname as well as spots with no name at all
    //
    // we use carnal knowledge of the maps to fix the coop spot targetnames to
    // match
    // that of the nearest named single player spot

    static EntThinkAdapter SP_FixCoopSpots = new EntThinkAdapter() {
        public boolean think(edict_t self) {

            edict_t spot;
            float[] d = { 0, 0, 0 };

            spot = null;
            EdictIterator es = null;

            while (true) {
                es = GameBase.G_Find(es, GameBase.findByClass,
                        "info_player_start");
                spot = es.o;
                if (spot == null)
                    return true;
                if (spot.targetname == null)
                    continue;
                Math3D.VectorSubtract(self.s.origin, spot.s.origin, d);
                if (Math3D.VectorLength(d) < 384) {
                    if ((self.targetname == null)
                            || Lib.Q_stricmp(self.targetname, spot.targetname) != 0) {
                        //				gi.dprintf("FixCoopSpots changed %s at %s targetname
                        // from %s to %s\n", self.classname,
                        // vtos(self.s.origin), self.targetname,
                        // spot.targetname);
                        self.targetname = spot.targetname;
                    }
                    return true;
                }
            }
        }
    };

    // now if that one wasn't ugly enough for you then try this one on for size
    // some maps don't have any coop spots at all, so we need to create them
    // where they should have been

    static EntThinkAdapter SP_CreateCoopSpots = new EntThinkAdapter() {
        public boolean think(edict_t self) {

            edict_t spot;

            if (Lib.Q_stricmp(GameBase.level.mapname, "security") == 0) {
                spot = GameUtil.G_Spawn();
                spot.classname = "info_player_coop";
                spot.s.origin[0] = 188 - 64;
                spot.s.origin[1] = -164;
                spot.s.origin[2] = 80;
                spot.targetname = "jail3";
                spot.s.angles[1] = 90;

                spot = GameUtil.G_Spawn();
                spot.classname = "info_player_coop";
                spot.s.origin[0] = 188 + 64;
                spot.s.origin[1] = -164;
                spot.s.origin[2] = 80;
                spot.targetname = "jail3";
                spot.s.angles[1] = 90;

                spot = GameUtil.G_Spawn();
                spot.classname = "info_player_coop";
                spot.s.origin[0] = 188 + 128;
                spot.s.origin[1] = -164;
                spot.s.origin[2] = 80;
                spot.targetname = "jail3";
                spot.s.angles[1] = 90;
            }
            return true;
        }
    };

    //=======================================================================

    // player pain is handled at the end of the frame in P_DamageFeedback
    static EntPainAdapter player_pain = new EntPainAdapter() {
        public void pain(edict_t self, edict_t other, float kick, int damage) {
        }
    };

    static EntDieAdapter body_die = new EntDieAdapter() {
        public void die(edict_t self, edict_t inflictor, edict_t attacker,
                int damage, float[] point) {

            int n;

            if (self.health < -40) {
                GameBase.gi
                        .sound(self, Defines.CHAN_BODY, GameBase.gi
                                .soundindex("misc/udeath.wav"), 1,
                                Defines.ATTN_NORM, 0);
                for (n = 0; n < 4; n++)
                    GameAI.ThrowGib(self,
                            "models/objects/gibs/sm_meat/tris.md2", damage,
                            Defines.GIB_ORGANIC);
                self.s.origin[2] -= 48;
                GameAI.ThrowClientHead(self, damage);
                self.takedamage = Defines.DAMAGE_NO;
            }
        }
    };

    //==============================================================

    static edict_t pm_passent;

    // pmove doesn't need to know about passent and contentmask
    public static pmove_t.TraceAdapter PM_trace = new pmove_t.TraceAdapter() {

        public trace_t trace(float[] start, float[] mins, float[] maxs,
                float[] end) {
            if (pm_passent.health > 0)
                return GameBase.gi.trace(start, mins, maxs, end, pm_passent,
                        Defines.MASK_PLAYERSOLID);
            else
                return GameBase.gi.trace(start, mins, maxs, end, pm_passent,
                        Defines.MASK_DEADSOLID);
        }

    };
}