1 /*
2     etc.h - Contains everything which is not somewhere else
3     Copyright (C) 2006 Mark boyd
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be fun to play,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef ETC_H
21 #define ETC_H
22 
23 #include <cmath>
24 #include <string>
25 
26 #include <SDL_inc.h>
27 
28 
29 //constant constants
30 const double pi=4.0*std::atan(1.0);
31 const int TILE_SIZE=32;
32 
33 //ship constants
34 const float d_angle=0.1;
35 const int ship_empty_mass=8;
36 const float ship_base_battery=10;
37 const float ship_base_generate=0.05;
38 const int system_slots=20;
39 
40 const float MAX_INVULNERABILITY=5; //seconds
41 
42 const int ball_mass=15;
43 
44 //laws of physics :)
45 const float tractor_force   = 1875;
46 const float tractor_elastic = 128;
47 const float default_gravity         = 43.75;    //in pixels/second^2
48 const float default_air_resistance  = 1.0;
49 
50 const int MAX_SHIELD=10;
51 
52 
53 
54 
55 
56 Uint32 getpixel(SDL_Surface *surface, int x, int y);
57 void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
58 
59 float dist(float x, float y);
60 
61 enum alphanity
62 {
63   alpha_channel,
64   no_alpha_channel
65 };
66 
67 SDL_Surface *create_surface(int w, int h, alphanity a = alpha_channel);
68 void rotate(SDL_Surface *from, SDL_Surface *to, double angle);
69 
70 //Returns the closest point to mid in the range [min,max]
minmax(T min,T mid,T max)71 template<class T> T minmax(T min, T mid, T max) {return std::max(min, std::min(max, mid));}
72 
73 //U(0,1)
randu()74 inline float randu() {return 1.0*rand()/RAND_MAX;}
75 //Random integer from 0 to i-1
76 int randint(int i);
77 //N(0,1)
78 float randn();
79 
80 
81 class do_later
82 {
83 public:
do_later(void (* fn)())84   do_later (void (*fn)()){m_fn=fn;}
~do_later()85   ~do_later() {(*m_fn)();}
86 private:
87   void (*m_fn)();
88 };
89 
90 std::string int2str(int i);
91 
92 void fade_out(SDL_Surface *screen, SDL_Rect rect);
93 void update_player_status(SDL_Surface *screen);
94 
95 //Useful for creating and filling containers.
96 //(make<container<type> >(),t1,t2,t3,t4,t5)  is castable to container<type>
97 namespace private_
98 {
99 template<class T>
100 class nasty
101 {
102   T m_t;
103 public:
104   nasty<T> &operator,(const typename T::value_type &v)
105     {m_t.insert(m_t.end(), v); return *this;}
T()106   operator T() {return m_t;}
107 };
108 
109 }
110 template<class T>
make()111 private_::nasty<T> make(){return private_::nasty<T>();}
112 
113 int calc_ship_mass();
114 float calc_ship_battery();
115 float calc_ship_generate();
116 
117 //typedefs for the shot class
118 class mover;
119 typedef void detonation_fn_t(mover *, mover *, float);
120 typedef void expiration_fn_t(mover *);
121 
122 #endif
123 
124