]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/ladder.qc
Don't allow bots to make use of too large ladders
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / ladder.qc
1 #include "ladder.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_LADDER)
3
4 void func_ladder_touch(entity this, entity toucher)
5 {
6 #ifdef SVQC
7         if (!toucher.iscreature)
8                 return;
9         if(IS_VEHICLE(toucher))
10                 return;
11 #elif defined(CSQC)
12         if(!toucher.isplayermodel)
13                 return;
14 #endif
15
16         EXACTTRIGGER_TOUCH(this, toucher);
17
18         toucher.ladder_time = time + 0.1;
19         toucher.ladder_entity = this;
20 }
21
22 #ifdef SVQC
23 bool func_ladder_send(entity this, entity to, int sf)
24 {
25         WriteHeader(MSG_ENTITY, ENT_CLIENT_LADDER);
26
27         WriteString(MSG_ENTITY, this.classname);
28         WriteByte(MSG_ENTITY, this.skin);
29         WriteCoord(MSG_ENTITY, this.speed);
30
31         trigger_common_write(this, false);
32
33         return true;
34 }
35
36 void func_ladder_link(entity this)
37 {
38         trigger_link(this, func_ladder_send);
39         //this.model = "null";
40 }
41
42 void func_ladder_init(entity this)
43 {
44         settouch(this, func_ladder_touch);
45
46         trigger_init(this);
47         func_ladder_link(this);
48
49         if(min(this.absmax.x - this.absmin.x, this.absmax.y - this.absmin.y) > 100)
50                 return;
51         this.bot_pickup = true; // allow bots to make use of this ladder
52         vector top = (this.absmin + this.absmax) / 2;
53         top.z = this.absmax.z + 1 - PL_MIN_CONST.z;
54         float cost = waypoint_getdistancecost_simple(this.absmax.z - this.absmin.z);
55         waypoint_spawnforteleporter_boxes(this, WAYPOINTFLAG_LADDER, this.absmin, this.absmax, top, top, cost);
56 }
57
58 spawnfunc(func_ladder)
59 {
60         IL_PUSH(g_ladders, this); // TODO: also func_water? bots currently loop through func_ladder only
61
62         func_ladder_init(this);
63 }
64
65 spawnfunc(func_water)
66 {
67         func_ladder_init(this);
68 }
69
70 #elif defined(CSQC)
71 .float speed;
72
73 void func_ladder_remove(entity this)
74 {
75         if(this.classname) { strunzone(this.classname); }
76         this.classname = string_null;
77 }
78
79 NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
80 {
81         this.classname = strzone(ReadString());
82         this.skin = ReadByte();
83         this.speed = ReadCoord();
84
85         trigger_common_read(this, false);
86
87         this.solid = SOLID_TRIGGER;
88         settouch(this, func_ladder_touch);
89         this.drawmask = MASK_NORMAL;
90         this.move_time = time;
91         this.entremove = func_ladder_remove;
92
93         return true;
94 }
95 #endif