1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <tankai/TankAISniperGuesser.h>
22 #include <tank/Tank.h>
23 #include <tank/TankLib.h>
24 #include <tank/TankPosition.h>
25 #include <server/ScorchedServer.h>
26 #include <common/Logger.h>
27 #include <common/RandomGenerator.h>
29 TankAISniperGuesser::TankAISniperGuesser()
33 TankAISniperGuesser::~TankAISniperGuesser()
37 bool TankAISniperGuesser::guess(Tank
*tank
, Vector
&target
,
38 float distForSniper
, bool checkIntersection
, float offset
)
40 fixed angleXYDegs
, angleYZDegs
, power
;
41 RandomGenerator generator
;
42 generator
.seed(rand());
44 FixedVector shotPosition
= tank
->getPosition().getTankPosition();
45 if (TankLib::getSniperShotTowardsPosition(
46 ScorchedServer::instance()->getContext(),
48 FixedVector::fromVector(target
),
49 fixed::fromFloat(distForSniper
),
50 angleXYDegs
, angleYZDegs
, power
,
53 fixed xyOffset
= generator
.getRandFixed() * fixed::fromFloat(offset
);
54 fixed yzOffset
= fixed::fromFloat(offset
) - xyOffset
;
56 tank
->getPosition().rotateGunXY(angleXYDegs
+ xyOffset
, false);
57 tank
->getPosition().rotateGunYZ(angleYZDegs
+ yzOffset
, false);
58 tank
->getPosition().changePower(power
, false);