]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/csqcmodel_hooks.qc
code attachment support (not used yet)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / csqcmodel_hooks.qc
1 .vector glowmod;
2 .float lodmodelindex0;
3 .float lodmodelindex1;
4 .float lodmodelindex2;
5
6 .entity tag_entity;
7 .float tag_index;
8
9 void CSQCModel_Hook_PreDraw(float isplayer)
10 {
11         // auto glowmod from colormap
12         self.glowmod = colormapPaletteColor(((self.colormap >= 1024) ? (self.colormap & 0xFF) : stof(getplayerkeyvalue(self.entnum - 1, "colors"))), TRUE) * 2;
13
14         if(self.modelindex != 0)
15         {
16                 // LOD
17                 if(self.lodmodelindex0 != self.modelindex)
18                 {
19                         string modelname = self.model;
20                         string s;
21
22                         // set modelindex
23                         self.lodmodelindex0 = self.modelindex;
24                         self.lodmodelindex1 = self.modelindex;
25                         self.lodmodelindex2 = self.modelindex;
26
27                         // FIXME: this only supports 3-letter extensions
28                         s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
29                         if(fexists(s))
30                         {
31                                 precache_model(s);
32                                 setmodel(self, s);
33                                 if(self.modelindex > 0)
34                                         self.lodmodelindex1 = self.modelindex;
35                         }
36
37                         s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
38                         if(fexists(s))
39                         {
40                                 precache_model(s);
41                                 setmodel(self, s);
42                                 if(self.modelindex > 0)
43                                         self.lodmodelindex2 = self.modelindex;
44                         }
45
46                         setmodel(self, modelname); // make everything normal again
47                 }
48
49                 if(autocvar_cl_playerdetailreduction <= 0)
50                 {
51                         if(autocvar_cl_playerdetailreduction <= -2)
52                                 self.modelindex = self.lodmodelindex2;
53                         else if(autocvar_cl_playerdetailreduction <= -1)
54                                 self.modelindex = self.lodmodelindex1;
55                         else
56                                 self.modelindex = self.lodmodelindex0;
57                 }
58                 else
59                 {
60                         float distance = vlen(self.origin - other.origin);
61                         float f = (distance + 100.0) * autocvar_cl_playerdetailreduction;
62                         f *= 1.0 / bound(0.01, view_quality, 1);
63                         if(f > autocvar_cl_loddistance2)
64                                 self.modelindex = self.lodmodelindex2;
65                         else if(f > autocvar_cl_loddistance1)
66                                 self.modelindex = self.lodmodelindex1;
67                         else
68                                 self.modelindex = self.lodmodelindex0;
69                 }
70         }
71
72         if(!isplayer)
73         {
74                 if(self.tag_entity && wasfreed(self.tag_entity))
75                         self.tag_entity = world;
76
77                 if(self.tag_networkentity)
78                 {
79                         // we are ATTACHED!
80                         if(self.tag_entity.entnum == self.tag_networkentity)
81                         {
82                                 // already good
83                                 self.drawmask = MASK_NORMAL;
84                         }
85                         else
86                         {
87                                 // to something NEW NEW NEW NEW!
88                                 self.tag_entity = findfloat(world, entnum, self.tag_networkentity);
89                                 if(self.tag_entity)
90                                 {
91                                         // the best part is: IT EXISTS
92                                         self.drawmask = MASK_NORMAL;
93
94                                         if(substring(self.model, 0, 17) == "models/weapons/v_")
95                                                 if(substring(self.tag_entity.model, 0, 17) == "models/weapons/h_")
96                                                 {
97                                                         self.tag_index = gettagindex(self.tag_entity, "weapon");
98                                                         if(!self.tag_index)
99                                                                 self.tag_index = gettagindex(self.tag_entity, "tag_weapon");
100                                                         if(!self.tag_index)
101                                                         {
102                                                                 // we need to prevent this from 'appening
103                                                                 self.tag_entity = world;
104                                                                 self.drawmask = 0;
105                                                                 dprint("h_ model lacks weapon attachment, but v_ model is attached to it\n");
106                                                         }
107                                                 }
108
109                                         if(substring(self.model, 0, 17) == "models/weapons/v_")
110                                                 if(substring(self.tag_entity.model, 0, 14) == "models/player/")
111                                                 {
112                                                         self.tag_index = gettagindex(self.tag_entity, "tag_weapon");
113                                                         if(!self.tag_index)
114                                                                 self.tag_index = gettagindex(self.tag_entity, "bip01 r hand");
115                                                 }
116
117                                         if(substring(self.tag_entity.model, 0, 17) == "models/weapons/v_")
118                                         {
119                                                 self.tag_index = gettagindex(self.tag_entity, "shot");
120                                                 if(!self.tag_index)
121                                                         self.tag_index = gettagindex(self.tag_entity, "tag_shot");
122                                         }
123                                 }
124                                 else
125                                 {
126                                         // damn, see you next frame
127                                         self.drawmask = 0;
128                                 }
129                         }
130                 }
131                 else
132                 {
133                         // no brain no pain
134                         self.drawmask = MASK_NORMAL;
135                 }
136         }
137 }