]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/ladder.qc
Remove trigger_init(), it's in the way and is mostly duplicating WarpZoneLib_ExactTri...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / func / ladder.qc
1 #include "ladder.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_LADDER)
3
4 void func_ladder_think(entity this)
5 {
6 #ifdef CSQC
7         // TODO: check if this is what is causing the glitchiness when switching between them
8         float dt = time - this.move_time;
9         this.move_time = time;
10         if(dt <= 0) { return; }
11 #endif
12
13         // set myself as current ladders where possible
14         IL_EACH(g_ladderents, it.ladder_entity == this,
15         {
16                 it.ladder_entity = NULL;
17                 IL_REMOVE(g_ladderents, it);
18         });
19
20         FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.ladder_entity && IS_PLAYER(it) && it.move_movetype != MOVETYPE_NOCLIP && !IS_DEAD(it),
21         {
22                 vector emin = it.absmin;
23                 vector emax = it.absmax;
24                 if(this.solid == SOLID_BSP || (IS_CSQC && this.solid == SOLID_TRIGGER)) // CSQC doesn't expand properly
25                 {
26                         emin -= '1 1 1';
27                         emax += '1 1 1';
28                 }
29                 if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
30                 {
31                         if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate
32                         {
33                                 if(!it.ladder_entity)
34                                         IL_PUSH(g_ladderents, it);
35                                 it.ladder_entity = this;
36                         }
37                 }
38         });
39
40 #ifdef SVQC
41         this.nextthink = time;
42 #endif
43 }
44
45 #ifdef SVQC
46 bool func_ladder_send(entity this, entity to, int sf)
47 {
48         WriteHeader(MSG_ENTITY, ENT_CLIENT_LADDER);
49
50         WriteString(MSG_ENTITY, this.classname);
51         WriteByte(MSG_ENTITY, this.skin);
52         WriteCoord(MSG_ENTITY, this.speed);
53
54         trigger_common_write(this, false);
55
56         return true;
57 }
58
59 void func_ladder_link(entity this)
60 {
61         trigger_link(this, func_ladder_send);
62         //this.model = "null";
63 }
64
65 void func_ladder_init(entity this)
66 {
67         EXACTTRIGGER_INIT;
68         BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
69         func_ladder_link(this);
70         setthink(this, func_ladder_think);
71         this.nextthink = time;
72
73         if(min(this.absmax.x - this.absmin.x, this.absmax.y - this.absmin.y) > 100)
74                 return;
75
76         entity tracetest_ent = spawn();
77         setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
78         tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
79
80         vector top_min = (this.absmin + this.absmax) / 2;
81         top_min.z = this.absmax.z;
82         vector top_max = top_min;
83         top_max.z += PL_MAX_CONST.z - PL_MIN_CONST.z;
84         tracebox(top_max + jumpstepheightvec, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
85         if(trace_startsolid)
86         {
87                 tracebox(top_max + stepheightvec, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
88                 if(trace_startsolid)
89                 {
90                         tracebox(top_max, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
91                         if(trace_startsolid)
92                         {
93                                 if(this.absmax.x - this.absmin.x > PL_MAX_CONST.x - PL_MIN_CONST.x
94                                         && this.absmax.y - this.absmin.y < this.absmax.x - this.absmin.x)
95                                 {
96                                         // move top on one side
97                                         top_max.y = top_min.y = this.absmin.y + (PL_MAX_CONST.y - PL_MIN_CONST.y) * 0.75;
98                                 }
99                                 else if(this.absmax.y - this.absmin.y > PL_MAX_CONST.y - PL_MIN_CONST.y
100                                         && this.absmax.x - this.absmin.x < this.absmax.y - this.absmin.y)
101                                 {
102                                         // move top on one side
103                                         top_max.x = top_min.x = this.absmin.x + (PL_MAX_CONST.x - PL_MIN_CONST.x) * 0.75;
104                                 }
105                                 tracebox(top_max, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
106                                 if(trace_startsolid)
107                                 {
108                                         if(this.absmax.x - this.absmin.x > PL_MAX_CONST.x - PL_MIN_CONST.x
109                                                 && this.absmax.y - this.absmin.y < this.absmax.x - this.absmin.x)
110                                         {
111                                                 // alternatively on the other side
112                                                 top_max.y = top_min.y = this.absmax.y - (PL_MAX_CONST.y - PL_MIN_CONST.y) * 0.75;
113                                         }
114                                         else if(this.absmax.y - this.absmin.y > PL_MAX_CONST.y - PL_MIN_CONST.y
115                                                 && this.absmax.x - this.absmin.x < this.absmax.y - this.absmin.y)
116                                         {
117                                                 // alternatively on the other side
118                                                 top_max.x = top_min.x = this.absmax.x - (PL_MAX_CONST.x - PL_MIN_CONST.x) * 0.75;
119                                         }
120                                         tracebox(top_max, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
121                                 }
122                         }
123                 }
124         }
125         delete(tracetest_ent);
126         if(trace_startsolid || trace_endpos.z < this.absmax.z)
127         {
128                 return;
129         }
130
131         this.bot_pickup = true; // allow bots to make use of this ladder
132         float cost = waypoint_getlinearcost(trace_endpos.z - this.absmin.z);
133         top_min = trace_endpos;
134         waypoint_spawnforteleporter_boxes(this, WAYPOINTFLAG_LADDER, this.absmin, this.absmax, top_min, top_min, cost);
135 }
136
137 spawnfunc(func_ladder)
138 {
139         IL_PUSH(g_ladders, this); // TODO: also func_water? bots currently loop through func_ladder only
140
141         func_ladder_init(this);
142 }
143
144 spawnfunc(func_water)
145 {
146         func_ladder_init(this);
147 }
148
149 #elif defined(CSQC)
150 .float speed;
151
152 void func_ladder_draw(entity this) { func_ladder_think(this); }
153
154 void func_ladder_remove(entity this)
155 {
156         IL_EACH(g_ladderents, it.ladder_entity == this,
157         {
158                 it.ladder_entity = NULL;
159                 IL_REMOVE(g_ladderents, it);
160         });
161         strfree(this.classname);
162 }
163
164 NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
165 {
166         this.classname = strzone(ReadString());
167         this.skin = ReadByte();
168         this.speed = ReadCoord();
169         this.solid = SOLID_TRIGGER;
170
171         trigger_common_read(this, false);
172
173         if(isnew)
174                 IL_PUSH(g_drawables, this);
175         this.draw = func_ladder_draw;
176         this.drawmask = MASK_NORMAL;
177
178         this.move_time = time;
179         this.entremove = func_ladder_remove;
180
181         // NOTE: CSQC's version of setorigin doesn't expand
182         this.absmin -= '1 1 1';
183         this.absmax += '1 1 1';
184
185         return true;
186 }
187 #endif