+ else if (!strcmp("light", key))
+ ambientlight = atof(value);
+ else if (!strcmp("sunlight", key))
+ {
+ sunlight = atof(value);
+ tyrlite = true;
+ }
+ else if (!strcmp("sun_color", key))
+ {
+ if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3)
+ VectorCopy(v, sunlightcolor);
+ tyrlite = true;
+ }
+ else if (!strcmp("sun_mangle", key))
+ {
+ if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3)
+ AngleVectors(v, sunlightdirection, NULL, NULL);
+ tyrlite = true;
+ }
+ else if (!strcmp("origin", key))
+ {
+ if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3)
+ {
+ VectorCopy(v, targetnametemporigin);
+ VectorCopy(v, light_origin);
+ }
+ }
+ else if (!strcmp("targetname", key))
+ {
+ if ((targetnames < 8192) && (strlen(value) + 1 + targetnamebufferpos <= 65536))
+ {
+ targetname[targetnames] = targetnamebuffer + targetnamebufferpos;
+ strcpy(targetnamebuffer + targetnamebufferpos, value);
+ targetnamebufferpos += strlen(value) + 1;
+ targetnameorigintofillin = targetnames++;
+ }
+ }
+ }
+ if (targetnameorigintofillin >= 0)
+ VectorCopy(targetnametemporigin, targetnameorigin[targetnameorigintofillin]);
+
+ if (sunlight)
+ {
+ r_sunlightenabled = true;
+ VectorScale(sunlightcolor, sunlight, r_sunlightcolor);
+ VectorCopy(sunlightdirection, r_sunlightdirection);
+ }
+ VectorScale(ambientcolor, ambientlight, r_light_ambientcolor);
+
+ while(1)
+ {
+ data = COM_Parse(data);
+ if (!data)
+ break; // done
+ if (com_token[0] != '{')
+ break; // error
+ light_light = 0;
+ light_lightcolor[0] = light_lightcolor[1] = light_lightcolor[2] = 1.0f;
+ light_color[0] = light_color[1] = light_color[2] = 1.0f;
+ light_direction[0] = light_direction[1] = light_direction[2] = 0.0f;
+ light_cone = -cos(20*M_PI/180);
+ light_distancescale = 1.0f;
+ light_fadetype = LIGHTFADE_DEFAULT; // replaced later when light util is identified
+ light_style = 0;
+ light_lightradius = 0;
+ light_enable = false;
+ targetnameorigintofillin = -1;
+ targetnametemporigin[0] = 0;
+ targetnametemporigin[1] = 0;
+ targetnametemporigin[2] = 0;
+ while (1)
+ {
+ data = COM_Parse(data);
+ if (!data)
+ return; // error
+ if (com_token[0] == '}')
+ break;
+ if (com_token[0] == '_')
+ strcpy(key, com_token + 1);
+ else
+ strcpy(key, com_token);
+ while (key[strlen(key)-1] == ' ') // remove trailing spaces
+ key[strlen(key)-1] = 0;
+ data = COM_Parse(data);
+ if (!data)
+ return; // error
+ strcpy(value, com_token);
+ if (!strcmp("light", key))
+ {
+ n = scanf(value, "%f %f %f %f", &f1, &f2, &f3, &f4);
+ switch(n)
+ {
+ case 1:
+ // id light, arghlite, tyrlite, others
+ light_light = f1;
+ light_lightcolor[0] = light_lightcolor[1] = light_lightcolor[2] = 1.0f;
+ break;
+ case 3:
+ // hlight specific (supports all 3 light formats, but this one is unique to it)
+ hlight = true;
+ light_light = max(f1, max(f2, f3));
+ light_lightcolor[0] = f1 / light_light;
+ light_lightcolor[1] = f2 / light_light;
+ light_lightcolor[2] = f3 / light_light;
+ break;
+ case 4:
+ // halflife
+ hlight = true; // unless this is a halflife map, probably hlight
+ light_light = f4;
+ light_lightcolor[0] = f1 * (1.0f / 255.0f);
+ light_lightcolor[1] = f1 * (1.0f / 255.0f);
+ light_lightcolor[2] = f1 * (1.0f / 255.0f);
+ break;
+ default:
+ // error
+ break;
+ }
+ }
+ else if (!strcmp("color", key))
+ {
+ n = scanf(value, "%f %f %f", &f1, &f2, &f3);
+ if (n == 3)
+ {
+ light_color[0] = f1;
+ light_color[1] = f2;
+ light_color[2] = f3;
+ }
+ // n != 3 is an error
+ }
+ else if (!strcmp("wait", key))
+ light_distancescale = atof(value);
+ else if (!strcmp("delay", key))
+ {
+ light_fadetype = atoi(value);
+ tyrlite = true;
+ }
+ else if (!strcmp("angle", key))
+ light_cone = -cos(atof(value) * M_PI / 360);
+ else if (!strcmp("mangle", key))
+ {
+ n = scanf(value, "%f %f %f", &v[0], &v[1], &v[2]);
+ if (n == 3)
+ AngleVectors(v, light_direction, NULL, NULL);
+ // n != 3 is an error
+ tyrlite = true;
+ }
+ else if (!strcmp("style", key))
+ {
+ n = atoi(value);
+ if (n >= 0 && n < MAX_LIGHTSTYLES)
+ light_style = n;
+ }
+ else if (!strcmp("lightradius", key))
+ {
+ hlight = true;
+ light_lightradius = atof(value);
+ }
+ else if (!strcmp("classname", key))
+ if (!strncmp(value, "light", 5))
+ light_enable = true;
+ else if (!strcmp("origin", key))
+ {
+ if (scanf(value, "%f %f %f", &v[0], &v[1], &v[2]) == 3)
+ VectorCopy(v, targetnametemporigin);
+ }
+ else if (!strcmp("targetname", key))
+ {
+ if ((targetnames < 8192) && (strlen(value) + 1 + targetnamebufferpos <= 65536))
+ {
+ targetname[targetnames] = targetnamebuffer + targetnamebufferpos;
+ strcpy(targetnamebuffer + targetnamebufferpos, value);
+ targetnamebufferpos += strlen(value) + 1;
+ targetnameorigintofillin = targetnames++;
+ }
+ }
+ else if (!strcmp("target", key))
+ if (strlen(value) < sizeof(light_target))
+ strcpy(light_target, value);
+ }
+ if (targetnameorigintofillin >= 0)
+ VectorCopy(targetnametemporigin, targetnameorigin[targetnameorigintofillin]);
+ if (light_enable && staticlights < MAX_STATICLIGHTS && light_light != 0)
+ {
+ VectorCopy(light_origin, staticlight[staticlights].origin);
+ staticlight[staticlights].color[0] = light_light * light_lightcolor[0] * light_color[0];
+ staticlight[staticlights].color[1] = light_light * light_lightcolor[1] * light_color[1];
+ staticlight[staticlights].color[2] = light_light * light_lightcolor[2] * light_color[2];
+ VectorCopy(light_direction, staticlight[staticlights].direction);
+ staticlight[staticlights].cone = light_cone;
+ staticlight[staticlights].distancescale = light_distancescale;
+ staticlight[staticlights].fadetype = light_fadetype;
+ staticlight[staticlights].style = light_style;
+ if (light_target && (targets < 8192) && (strlen(value) + 1 + targetnamebufferpos <= 65536))
+ {
+ target[staticlights] = targetnamebuffer + targetnamebufferpos;
+ strcpy(targetnamebuffer + targetnamebufferpos, value);
+ targetnamebufferpos += strlen(value) + 1;
+ }
+ else
+ target[staticlights] = NULL;
+ staticlight[staticlights].lightsubtract = 0;
+ if (light_lightradius)
+ {
+ staticlight[staticlights].fadetype = LIGHTFADE_LDIVX2;
+ staticlight[staticlights].lightsubtract = max(staticlight[staticlights].color[0], max(staticlight[staticlights].color[1], staticlight[staticlights].color[2])) * 0.5f / (light_lightradius * light_distancescale * light_lightradius * light_distancescale * (1.0f / 65536.0f) + 1.0f);
+ }
+ staticlights++;
+ }
+ }
+ if (cl.worldmodel->ishlbsp)
+ n = LIGHTFADE_LDIVX2;
+ else if (tyrlite)
+ n = LIGHTFADE_LMINUSX;
+ else if (hlight)
+ n = LIGHTFADE_LDIVX2;
+ else
+ n = LIGHTFADE_LMINUSX;
+ for (i = 0;i < staticlights;i++)
+ {
+ if (staticlight[i].fadetype == LIGHTFADE_DEFAULT)
+ staticlight[i].fadetype = n;
+ if (target[i])