1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 /*
14  * ShotStrategy:
15  *  Interface for all shot flight path strategies.  A
16  *  strategy encapsulates the algorithm for computing
17  *  the path taken by a shot.
18  */
19 
20 #ifndef __SHOTSTRATEGY_H__
21 #define __SHOTSTRATEGY_H__
22 
23 #include "common.h"
24 
25 /* common interface headers */
26 #include "Ray.h"
27 #include "Obstacle.h"
28 #include "Teleporter.h"
29 #include "SceneDatabase.h"
30 
31 /* local interface headers */
32 #include "BaseLocalPlayer.h"
33 #include "ShotPath.h"
34 
35 class ShotPath;
36 
37 class ShotStrategy
38 {
39 public:
40     ShotStrategy(ShotPath*);
41     virtual     ~ShotStrategy();
42 
43     virtual void    update(float dt) = 0;
44     virtual float   checkHit(const BaseLocalPlayer*, float pos[3]) const = 0;
45     virtual bool    isStoppedByHit() const;
46     virtual void    addShot(SceneDatabase*, bool colorblind) = 0;
47     virtual void    expire();
48     virtual void    radarRender() const = 0;
49 
50     // first part of message must be the
51     // ShotUpdate portion of FiringInfo.
52     virtual void    sendUpdate(const FiringInfo&) const;
53 
54     // update shot based on message.  code is the message code.  msg
55     // points to the part of the message after the ShotUpdate portion.
56     virtual void    readUpdate(uint16_t code, const void* msg);
57 
58     static const Obstacle*  getFirstBuilding(const Ray&, float min, float& t);
59     static void     reflect(float* v, const float* n); // const
60 
61 protected:
62     const ShotPath& getPath() const;
63     FiringInfo&     getFiringInfo(ShotPath*) const;
64     void        setReloadTime(float) const;
65     void        setPosition(const float*) const;
66     void        setVelocity(const float*) const;
67     void        setExpiring() const;
68     void        setExpired() const;
69 
70     const Teleporter*   getFirstTeleporter(const Ray&, float min,
71                                            float& t, int& f) const;
72     bool        getGround(const Ray&, float min, float &t) const;
73 
74 private:
75     ShotPath*       path;
76 };
77 
getPath()78 inline const ShotPath&  ShotStrategy::getPath() const
79 {
80     return *path;
81 }
82 
83 
84 #endif /* __SHOTSTRATEGY_H__ */
85 
86 // Local Variables: ***
87 // mode: C++ ***
88 // tab-width: 4 ***
89 // c-basic-offset: 4 ***
90 // indent-tabs-mode: nil ***
91 // End: ***
92 // ex: shiftwidth=4 tabstop=4
93