From: Stefan G. <sgl...@us...> - 2000-09-20 18:08:53
|
Update of /cvsroot/pythianproject/PythianProject/Source/GameEngine In directory slayer.i.sourceforge.net:/tmp/cvs-serv27804 Modified Files: Commands.pas DynObjsState.pas Log Message: Movement commands due to pathfinding have now data New stop command added Index: Commands.pas =================================================================== RCS file: /cvsroot/pythianproject/PythianProject/Source/GameEngine/Commands.pas,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** Commands.pas 2000/09/10 16:47:17 1.15 --- Commands.pas 2000/09/20 18:08:50 1.16 *************** *** 6,9 **** --- 6,15 ---- type + TMotionData= record (* for turn and move commands *) + Speed:integer; (* speed of turn/movement *) + MaxMotion:single; (* max turn or movement *) + end; + PMotionData=^TMotionData; + TCommandData = record Target :TObject; // can be used to point to the object to enact the command on *************** *** 64,72 **** // define ranges here for optimization purposes ! cmdRANGE_MovementLow = 1; cmdRANGE_MovementHigh = 11; cmdMoveForward = 1; cmdMoveBackward = 2; cmdMoveUp = 3; cmdMoveDown = 4; cmdTurnLeft = 5; cmdTurnRight = 6; cmdLookUp = 7; cmdLookDown = 8; ! cmdStrafeRight = 9; cmdStrafeLeft = 10; cmdMoveTo = 11; --- 70,78 ---- // define ranges here for optimization purposes ! cmdRANGE_MovementLow = 1; cmdRANGE_MovementHigh = 12; cmdMoveForward = 1; cmdMoveBackward = 2; cmdMoveUp = 3; cmdMoveDown = 4; cmdTurnLeft = 5; cmdTurnRight = 6; cmdLookUp = 7; cmdLookDown = 8; ! cmdStrafeRight = 9; cmdStrafeLeft = 10; cmdMoveTo = 11; cmdStop = 12; Index: DynObjsState.pas =================================================================== RCS file: /cvsroot/pythianproject/PythianProject/Source/GameEngine/DynObjsState.pas,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** DynObjsState.pas 2000/09/10 16:47:17 1.15 --- DynObjsState.pas 2000/09/20 18:08:50 1.16 *************** *** 38,45 **** VA: TAngle3D; MoveData: PPoint3D; ! Step, Turn: Single; Command: PCommandData; Ind :integer; ! BaseTurn :integer; begin for ind := 0 to Commands.Count-1 do --- 38,45 ---- VA: TAngle3D; MoveData: PPoint3D; ! Step, Turn, Move, MaxTurn, MaxMove : Single; Command: PCommandData; Ind :integer; ! BaseTurn, BaseMove :integer; begin for ind := 0 to Commands.Count-1 do *************** *** 57,76 **** VA := AngleVector; BaseTurn := 20; // default // check if baseTurn is overridden if (CommandType = cmdTurnLeft) or (CommandType = cmdTurnRight) then if assigned(data) then begin ! BaseTurn := Integer(Data^); Dispose(Data); end; ! // Normalize the step time to 33 ms ! Step := BaseStep * CurrentTime; Turn := BaseTurn * Step; case CommandType of ! cmdMoveForward: MoveA(+VA.X * Step, 0, +VA.Z * Step); ! cmdMoveBackward: MoveA(-VA.X * Step, 0, -VA.Z * Step); cmdStrafeLeft: MoveA(+VA.Z * Step, 0, -VA.X * Step); cmdStrafeRight: MoveA(-VA.Z * Step, 0, +VA.X * Step); --- 57,101 ---- VA := AngleVector; BaseTurn := 20; // default + BaseMove := 1; // default + MaxTurn := 360; + MaxMove := 20; + // Normalize the step time to 33 ms + Step := BaseStep * CurrentTime; + // check if baseTurn is overridden if (CommandType = cmdTurnLeft) or (CommandType = cmdTurnRight) then if assigned(data) then begin ! BaseTurn := TMotionData(Data^).Speed; ! MaxTurn := TMotionData(Data^).MaxMotion; ! tracestring('Angle to target '+IntToStr(round(MaxTurn))+ ! ', intended turn '+IntToStr(round(BaseTurn*Step))); Dispose(Data); + Data:=nil; end; ! // check if baseStep is overridden ! if (CommandType = cmdMoveForward) or (CommandType = cmdMoveBackward) then ! if assigned(data) then ! begin ! BaseMove := TMotionData(Data^).Speed; ! MaxMove := TMotionData(Data^).MaxMotion; ! tracestring('Distance to target '+IntToStr(round(MaxMove))+ ! ', intended motion '+IntToStr(round(BaseMove*Step))); ! Dispose(Data); ! Data:=nil; ! end; + Move := BaseMove * Step; + if Move>MaxMove then + Move:=MaxMove; Turn := BaseTurn * Step; + if Turn>MaxTurn then + Turn:=MaxTurn; + case CommandType of ! cmdMoveForward: MoveA(+VA.X * Move, 0, +VA.Z * Move); ! cmdMoveBackward: MoveA(-VA.X * Move, 0, -VA.Z * Move); cmdStrafeLeft: MoveA(+VA.Z * Step, 0, -VA.X * Step); cmdStrafeRight: MoveA(-VA.Z * Step, 0, +VA.X * Step); *************** *** 82,85 **** --- 107,111 ---- MoveTo(MoveData^); end; + cmdStop: Animation:=0; end; end; *************** *** 94,97 **** --- 120,125 ---- end; // now check if it is to be thrown away + if TTL>0 then // mike, is this correct here ??? + dec(TTl); end; end; *************** *** 103,106 **** --- 131,135 ---- Obj: TMovingItem; tmpPtEqual :boolean; + C:PCommandData; begin FMovementAI.Map := Map; *************** *** 121,126 **** tmpPtEqual := (Abs(Obj.FinalTarget.X - Obj.Position.X) <= 1) and (Abs(Obj.FinalTarget.Z - Obj.Position.Z) <= 1); ! if (Obj.FullPath.Count = 0) ! and not tmpPtEqual then begin FMovementAI.Destination := Obj.FinalTarget; --- 150,154 ---- tmpPtEqual := (Abs(Obj.FinalTarget.X - Obj.Position.X) <= 1) and (Abs(Obj.FinalTarget.Z - Obj.Position.Z) <= 1); ! if (Obj.FullPath.Count = 0) and not tmpPtEqual then begin FMovementAI.Destination := Obj.FinalTarget; *************** *** 128,131 **** --- 156,163 ---- TraceString('Fullpath at zero and position '+Point3DToString(Obj.Position)+' not equal to final target = '+Point3DToString(Obj.FinalTarget)); if not FMovementAI.FindPath(Obj.FullPath, 2.0) then begin end; + C := Commands.MakeNewCommand; + C.Target := Obj; + C.CommandType := cmdStop; + Commands.AddCommand(C); end; if (Obj.FullPath.Count = 0) and (tmpPtEqual) then *************** *** 133,136 **** --- 165,172 ---- Obj.NeedsPath := false; TraceString('needspath := false'); + C := Commands.MakeNewCommand; + C.Target := Obj; + C.CommandType := cmdStop; + Commands.AddCommand(C); end; end; *************** *** 198,201 **** --- 234,238 ---- ActiveTarget := Player; + (* remove this again !!! *) Hueteutl := TNPC.Create; with Hueteutl do *************** *** 215,218 **** --- 252,256 ---- Cmd := Commands.MakeNewCommand; Cmd^.CommandType := cmdAddAI; Cmd^.Data := HueyAI; Commands.AddCommand(Cmd); + (**) // this guy has no brain to start out with. he's used for testing *************** *** 249,262 **** BaseStep = 0.1 / 33;} var ! {## VA: TAngle3D; ! Step: Single; } C:PCommandData; begin ! // todo: replace with commands system - mike C := Commands.MakeNewCommand; - C.CommandType := cmdMoveForward; C.Target := Obj; - Commands.AddCommand(C); { VA := Obj.AngleVector; --- 287,319 ---- BaseStep = 0.1 / 33;} var ! D: Single; ! P: TPoint3D; ! {## Step: Single; } ! MoveData :PMotionData; C:PCommandData; begin ! P:=SubPoint(Obj.Target, Obj.Position); ! P.Y:=0; ! D:=VectorLength(P); // distance to target ! ! C := Commands.MakeNewCommand; C.Target := Obj; + if D<0.1 then + C.CommandType := cmdStop + else begin + C.CommandType := cmdMoveForward; + new(MoveData); + MoveData^.Speed:=1; // default + {if D>1 then + MoveData^.Speed:=round(sqrt(D)) + else + MoveData^.Speed:=round(D);} + MoveData^.MaxMotion:=D; + C.Data:=MoveData; + end; + + Commands.AddCommand(C); { VA := Obj.AngleVector; *************** *** 291,295 **** DA: TSingle3D; C:PCommandData; ! TurnData :PInteger; begin VA := SubPoint(Obj.Target, Obj.Position); --- 348,352 ---- DA: TSingle3D; C:PCommandData; ! TurnData :PMotionData; begin VA := SubPoint(Obj.Target, Obj.Position); *************** *** 303,306 **** --- 360,366 ---- if DP<-180 then DP:=DP+360; + C := Commands.MakeNewCommand; + C.Target := Obj; + if (Abs(DP) > 5) then begin *************** *** 315,320 **** Obj.RotateA(0, Step, 0);} - C := Commands.MakeNewCommand; - C.Target := Obj; if Dir = 1 then C.CommandType := cmdTurnRight --- 375,378 ---- *************** *** 322,336 **** C.CommandType := cmdTurnLeft; New(TurnData); ! // hi stefan, here's the mod we need :) you can assign an integer ! // to the data field of a command to change the turn rate. ! // the integer will be freed when the command is executed -mike ! TurnData^ := 20; // 20 is the default turn rate, see above for ! // calculations ! Commands.AddCommand(C); Result := False; end ! else Result := True; end; --- 380,398 ---- C.CommandType := cmdTurnLeft; New(TurnData); ! // hi mike, the turn data / move data have now a record. ! TurnData^.Speed := 20; // 20 is the default turn rate, see above for ! // calculations ! TurnData^.Speed := round(arctan(abs(DP)/180*pi)*180/pi/5); ! TurnData^.MaxMotion := abs(DP); + C.Data:=TurnData; + Result := False; end ! else begin ! C.CommandType := cmdStop; Result := True; + end; + Commands.AddCommand(C); end; |