home *** CD-ROM | disk | FTP | other *** search
- //DocWilco's DeathMatch Camera patch version 1.1
-
- //Some of this code is not used but I left it here because I sometimes use
- //it when I test stuff, and for some people maybe to learn from.
-
-
- //FindNextIntermission looks for the next Intermission view in the level
- //It is a modified FindIntermission from client.qc
-
- entity() FindNextIntermission =
- {
- local entity spot;
-
- spot = find (CurrentCamPos, classname, "info_intermission");
- if (!spot)
- spot = find (spot, classname, "info_intermission");
- return spot;
- };
-
- // Not used. But if used instead of CheckCams in InitCamClient
- // the camera will cycle through all the views in the level.
-
- void() NextCamPosition =
- {
- local entity spot;
-
- spot = FindNextIntermission();
- CurrentCamPos = spot;
-
- setorigin(self, spot.origin);
- self.angles = self.v_angle = spot.mangle;
- msg_entity = self;
- if (self.flags & FL_CLIENT) //Is it really a client?
- WriteByte (MSG_ONE, SVC_INTERMISSION); //This is a hack to update the screen.
- self.think = NextCamPosition;
- self.nextthink = time + 3;
- };
-
- // inview returns TRUE if the angle between the line from the camera to the
- // target makes an angle of 60 degrees or less with the camera's direction
- // of view.
- // Heavily modified infront from ai.qc
- // I could not have done this without the stuff I learned at maths years ago
- // If you don't understand this, looking up normalize in builtin.c might
- // help. Normalize makes the vector exactly 1 unit long. And read some stuff
- // about vectors.
-
- float(entity cam, entity targ) inview =
- {
- local vector vec1;
- local vector vec2;
- local float dot;
-
- makevectors (cam.mangle);
- vec1 = normalize (targ.origin - cam.origin);
- vec2 = normalize (v_forward);
- dot = vlen(vec1 - vec2);
- // bprint(vtos(vec1));
- // bprint("\n");
- // bprint(vtos(vec2));
- // bprint("\n");
- // bprint(ftos(dot));
- // bprint(" ");
-
- if ((dot <= 1) && (dot >= -1))
- {
- // bprint ("In view ");
- return TRUE;
- }
- return FALSE;
- };
-
- // VisibleToCam
- // Checks whether there are any walls between the camera and the player.
- // So even if the player is not in view, but is visible from the point where
- // the camera is, this function returns true.
- // Modified visible from ai.qc
-
- float (entity cam, entity targ) VisibleToCam =
- {
- local vector spot1, spot2;
-
- spot1 = cam.origin;
- spot2 = targ.origin + targ.view_ofs;
- traceline (spot1, spot2, TRUE, self); // see through other monsters
-
- if (trace_inopen && trace_inwater)
- return FALSE; // sight line crossed contents
-
- if (trace_fraction == 1)
- return TRUE;
- return FALSE;
- };
-
-
- // CheckView
- // Checks the given view for players, and returns the amount of players in view
-
- float(entity cam) CheckView =
- {
- local float NumOfPlayers;
- local entity client;
- local float DistToCam;
-
- NumOfPlayers = 0;
- DistToCam = 0;
- client = find (world, classname, "player");
- while (client != world)
- {
- if (inview(cam, client) && VisibleToCam(cam, client))
- {
- NumOfPlayers = NumOfPlayers + 1;
- DistToCam = DistToCam + vlen(client.origin - cam.origin);
- }
- // bprint("Checked ");
- // bprint(client.netname);
- // bprint(" ");
- // bprint(ftos(client.team));
- // bprint("\n");
- client = find (client, classname, "player");
- }
- // bprint(ftos(NumOfPlayers));
- // bprint(" ");
- AvgDist = DistToCam / NumOfPlayers;
- return NumOfPlayers;
- };
-
- // CheckCams
- // Checks every intermission view for the amount of players in view. The view
- // with the most players in view and the lowest average distance to the players
- // in view is made the next view.
- // I am thinking of changing this the most.
-
- void() CheckCams =
- {
- local entity cam;
- local entity bestcam;
- local float highnum;
- local float camnum;
- local float lowdist;
- local float foundany;
-
- bestcam = CurrentCamPos; //If no view is found the current view is kept.
- highnum = 0;
- foundany = FALSE;
- lowdist = 100000;
- cam = find (world, classname, "info_intermission");
- while (cam != world)
- {
- camnum = CheckView(cam);
- // bprint(ftos(camnum));
- // bprint(" ");
- // bprint(ftos(AvgDist));
- // bprint(" ");
- // bprint(ftos(highnum));
- // bprint(" ");
- if ((highnum < camnum) && (camnum > 0))
- {
- bestcam = cam;
- highnum = camnum;
- lowdist = AvgDist;
- foundany = TRUE;
- // bprint("more ");
- }
- if ((camnum = highnum) && (camnum > 0) && (AvgDist <= lowdist))
- {
- bestcam = cam;
- lowdist = AvgDist;
- foundany = TRUE;
- }
- cam = find (cam, classname, "info_intermission");
- }
- // bprint("\n");
- // bprint(ftos(highnum));
- // bprint(" players in view\n");
- if (foundany == FALSE)
- {
- if (time >= nextviewtime)
- {
- bestcam = FindNextIntermission();
- nextviewtime = time + 3;
- }
- // bprint("Nothing in view\n");
- }
- CurrentCamPos = bestcam;
- setorigin(self, bestcam.origin);
- self.angles = self.v_angle = bestcam.mangle;
- msg_entity = self;
- if (self.flags & FL_CLIENT)
- WriteByte (MSG_ONE, SVC_INTERMISSION);
- self.think = CheckCams;
- self.nextthink = time + 0.5;
-
- };
-
- // InitCamClient
- // Turns the client from a player into the camera.
-
- void() InitCamClient =
- {
- local entity spot;
-
- bprint("Camera initialised\n");
- self.classname = "CameraClient";
- setmodel (self, string_null);
- setsize (self, '0 0 0', '0 0 0');
- self.view_ofs = '0 0 0';
- self.movetype = MOVETYPE_NONE;
- self.solid = SOLID_NOT;
- self.takedamage = DAMAGE_NO;
- nextviewtime = time;
-
- spot = FindIntermission() ; //pick a random view to start from
- CurrentCamPos = spot;
-
- setorigin(self, spot.origin);
- self.angles = self.v_angle = spot.mangle;
- msg_entity = self;
- if (self.flags & FL_CLIENT)
- WriteByte (MSG_ONE, SVC_INTERMISSION);
- self.think = CheckCams;
- self.nextthink = time + 3;
- };
-
-