2 REGISTER_NET_LINKED(ENT_CLIENT_LADDER)
4 void func_ladder_think(entity this)
7 // TODO: check if this is what is causing the glitchiness when switching between them
8 float dt = time - this.move_time;
10 if(dt <= 0) { return; }
13 // set myself as current ladders where possible
14 IL_EACH(g_ladderents, it.ladder_entity == this,
16 it.ladder_entity = NULL;
17 IL_REMOVE(g_ladderents, it);
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),
22 if (WarpZoneLib_ExactTrigger_Touch(this, it, false))
25 IL_PUSH(g_ladderents, it);
26 it.ladder_entity = this;
31 this.nextthink = time;
36 bool func_ladder_send(entity this, entity to, int sf)
38 WriteHeader(MSG_ENTITY, ENT_CLIENT_LADDER);
40 WriteString(MSG_ENTITY, this.classname);
41 WriteByte(MSG_ENTITY, this.skin);
42 WriteCoord(MSG_ENTITY, this.speed);
44 trigger_common_write(this, false);
49 void func_ladder_link(entity this)
51 trigger_link(this, func_ladder_send);
52 //this.model = "null";
55 void func_ladder_init(entity this)
57 WarpZoneLib_ExactTrigger_Init(this, false);
58 BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
59 func_ladder_link(this);
60 setthink(this, func_ladder_think);
61 this.nextthink = time;
63 if(min(this.absmax.x - this.absmin.x, this.absmax.y - this.absmin.y) > 100)
66 entity tracetest_ent = spawn();
67 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
68 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
70 vector top_min = (this.absmin + this.absmax) / 2;
71 top_min.z = this.absmax.z;
72 vector top_max = top_min;
73 top_max.z += PL_MAX_CONST.z - PL_MIN_CONST.z;
74 tracebox(top_max + jumpstepheightvec, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
77 tracebox(top_max + stepheightvec, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
80 tracebox(top_max, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
83 if(this.absmax.x - this.absmin.x > PL_MAX_CONST.x - PL_MIN_CONST.x
84 && this.absmax.y - this.absmin.y < this.absmax.x - this.absmin.x)
86 // move top on one side
87 top_max.y = top_min.y = this.absmin.y + (PL_MAX_CONST.y - PL_MIN_CONST.y) * 0.75;
89 else if(this.absmax.y - this.absmin.y > PL_MAX_CONST.y - PL_MIN_CONST.y
90 && this.absmax.x - this.absmin.x < this.absmax.y - this.absmin.y)
92 // move top on one side
93 top_max.x = top_min.x = this.absmin.x + (PL_MAX_CONST.x - PL_MIN_CONST.x) * 0.75;
95 tracebox(top_max, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
98 if(this.absmax.x - this.absmin.x > PL_MAX_CONST.x - PL_MIN_CONST.x
99 && this.absmax.y - this.absmin.y < this.absmax.x - this.absmin.x)
101 // alternatively on the other side
102 top_max.y = top_min.y = this.absmax.y - (PL_MAX_CONST.y - PL_MIN_CONST.y) * 0.75;
104 else if(this.absmax.y - this.absmin.y > PL_MAX_CONST.y - PL_MIN_CONST.y
105 && this.absmax.x - this.absmin.x < this.absmax.y - this.absmin.y)
107 // alternatively on the other side
108 top_max.x = top_min.x = this.absmax.x - (PL_MAX_CONST.x - PL_MIN_CONST.x) * 0.75;
110 tracebox(top_max, PL_MIN_CONST, PL_MAX_CONST, top_min, MOVE_NOMONSTERS, tracetest_ent);
115 delete(tracetest_ent);
116 if(trace_startsolid || trace_endpos.z < this.absmax.z)
121 this.bot_pickup = true; // allow bots to make use of this ladder
122 float cost = waypoint_getlinearcost(trace_endpos.z - this.absmin.z);
123 top_min = trace_endpos;
124 waypoint_spawnforteleporter_boxes(this, WAYPOINTFLAG_LADDER, this.absmin, this.absmax, top_min, top_min, cost);
127 spawnfunc(func_ladder)
129 IL_PUSH(g_ladders, this); // TODO: also func_water? bots currently loop through func_ladder only
131 func_ladder_init(this);
134 spawnfunc(func_water)
136 func_ladder_init(this);
142 void func_ladder_draw(entity this) { func_ladder_think(this); }
144 void func_ladder_remove(entity this)
146 IL_EACH(g_ladderents, it.ladder_entity == this,
148 it.ladder_entity = NULL;
149 IL_REMOVE(g_ladderents, it);
151 strfree(this.classname);
154 NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
156 this.classname = strzone(ReadString());
157 this.skin = ReadByte();
158 this.speed = ReadCoord();
159 this.solid = SOLID_TRIGGER;
161 trigger_common_read(this, false);
164 IL_PUSH(g_drawables, this);
165 this.draw = func_ladder_draw;
166 this.drawmask = MASK_NORMAL;
168 this.move_time = time;
169 this.entremove = func_ladder_remove;