~ubuntu-branches/ubuntu/lucid/orbital-eunuchs-sniper/lucid

« back to all changes in this revision

Viewing changes to src/target.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-05-29 09:32:48 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 gutsy)
  • Revision ID: james.westby@ubuntu.com-20070529093248-laj1bsm2dffohdf9
Tags: 1.30+svn20070601-1
Fix broken "upstream" rule to generate correctly versioned orig.tar.gz
to avoid native package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////
 
2
// 
 
3
//  Snipe2d ludum dare 48h compo entry
 
4
//
 
5
//  Jari Komppa aka Sol 
 
6
//  http://iki.fi/sol
 
7
// 
 
8
///////////////////////////////////////////////
 
9
// License
 
10
///////////////////////////////////////////////
 
11
// 
 
12
//     This software is provided 'as-is', without any express or implied
 
13
//     warranty.    In no event will the authors be held liable for any damages
 
14
//     arising from the use of this software.
 
15
// 
 
16
//     Permission is granted to anyone to use this software for any purpose,
 
17
//     including commercial applications, and to alter it and redistribute it
 
18
//     freely, subject to the following restrictions:
 
19
// 
 
20
//     1. The origin of this software must not be misrepresented; you must not
 
21
//        claim that you wrote the original software. If you use this software
 
22
//        in a product, an acknowledgment in the product documentation would be
 
23
//        appreciated but is not required.
 
24
//     2. Altered source versions must be plainly marked as such, and must not be
 
25
//        misrepresented as being the original software.
 
26
//     3. This notice may not be removed or altered from any source distribution.
 
27
// 
 
28
// (eg. same as ZLIB license)
 
29
//
 
30
///////////////////////////////////////////////
 
31
//
 
32
// Houses are taken from a satellite picture of glasgow.
 
33
//
 
34
// The sources are a mess, as I didn't even try to do anything
 
35
// really organized here.. and hey, it's a 48h compo =)
 
36
//
 
37
#include "snipe2d.h"
 
38
 
 
39
void target()
 
40
{
 
41
    static int lastBadGuys = -1;
 
42
    static int lastVIPs = -1;
 
43
    static int badGuysChangeTick = 0;
 
44
    static int VIPsChangeTick = 0;
 
45
 
 
46
    int tick = SDL_GetTicks();
 
47
 
 
48
    if (lastBadGuys != Game.baddy.count)
 
49
    {
 
50
        lastBadGuys = Game.baddy.count;
 
51
        badGuysChangeTick = tick;
 
52
    }
 
53
    if (lastVIPs != Game.vip.count)
 
54
    {
 
55
        lastVIPs = Game.vip.count;
 
56
        VIPsChangeTick = tick;
 
57
    }
 
58
    
 
59
    if ( SDL_LockSurface(Game.Screen) < 0 ) 
 
60
        return;
 
61
 
 
62
    int i;
 
63
    short *tgt = (short*)Game.Screen->pixels;
 
64
 
 
65
    if (Game.Reloading)    
 
66
    {
 
67
        float distance = Game.Reloading / (float)Game.ReloadTime;
 
68
        distance = distance * distance * distance;
 
69
 
 
70
        int ofs = (Game.Screen->pitch / 2) * 240;
 
71
        for (i = 0; i < 640; i++, ofs++)
 
72
            tgt[ofs] = (short)0;
 
73
 
 
74
        ofs = 320;
 
75
        for (i = 0; i < 480; i++, ofs += Game.Screen->pitch / 2)
 
76
            tgt[ofs] = (short)0;
 
77
 
 
78
        ofs = (Game.Screen->pitch / 2) * (int)(240 + distance * 200);
 
79
        for (i = 0; i < 640; i++, ofs++)
 
80
            tgt[ofs] = (short)0xC000;
 
81
        
 
82
        ofs = (Game.Screen->pitch / 2) * (int)(240 - distance * 200);
 
83
        for (i = 0; i < 640; i++, ofs++)
 
84
            tgt[ofs] = (short)0xC000;
 
85
 
 
86
        ofs = (int)(320 + distance * 300);
 
87
        for (i = 0; i < 480; i++, ofs += Game.Screen->pitch / 2)
 
88
            tgt[ofs] = (short)0xC000;
 
89
 
 
90
        ofs = (int)(320 - distance * 300);
 
91
        for (i = 0; i < 480; i++, ofs += Game.Screen->pitch / 2)
 
92
            tgt[ofs] = (short)0xC000;
 
93
 
 
94
        SDL_UnlockSurface(Game.Screen);
 
95
 
 
96
    }
 
97
    else // not reloading
 
98
    {
 
99
        int ofs = (Game.Screen->pitch / 2) * 240;
 
100
        for (i = 0; i < 640; i++, ofs++)
 
101
            tgt[ofs] = (short)0xff00;
 
102
 
 
103
        ofs = 320;
 
104
        for (i = 0; i < 480; i++, ofs += Game.Screen->pitch / 2)
 
105
            tgt[ofs] = (short)0xff00;
 
106
 
 
107
        SDL_UnlockSurface(Game.Screen);
 
108
    }
 
109
    
 
110
    int row;
 
111
    row = 196;
 
112
    if(Game.verbosity >= 1) print(324, row, COLOR_YELLOW, "time:    %02d:%02d", ((SDL_GetTicks() -
 
113
    Game.GameStartTick) / 60000), ((SDL_GetTicks() - Game.GameStartTick) / 1000)%60);
 
114
    row += 7;
 
115
    if(Game.verbosity >= 1) {
 
116
    if ((tick - VIPsChangeTick) < 500)
 
117
        print(324, row, COLOR_GREEN, "VIPs    %6d", Game.vip.count);
 
118
    else
 
119
        print(324, row, COLOR_YELLOW, "VIPs    %6d", Game.vip.count);
 
120
    }
 
121
    row += 7;
 
122
    if(Game.verbosity >= 2) {
 
123
    if ((tick - badGuysChangeTick) < 500)
 
124
        print(324, row, COLOR_RED, "Threat  %6d", Game.baddy.count);
 
125
    else
 
126
        print(324, row, COLOR_YELLOW, "Threat  %6d", Game.baddy.count);
 
127
    }
 
128
    row += 7;
 
129
    if(Game.verbosity >= 2) print(324, row, COLOR_YELLOW, "Score%09.8d", Game.Score);
 
130
    row += 7;
 
131
    if(Game.verbosity >= 2) print(324, row, COLOR_YELLOW, "FPS     %3.3f", (Game.FrameCount * 1000.0f) / (tick - Game.StartTick));
 
132
    row += 7;
 
133
    if(Game.verbosity >= 1) print(324, row, COLOR_YELLOW, "Zoom  %7.0fx", (1.0f / Game.CoordScale) * 100);
 
134
    row = 244;
 
135
    if(Game.verbosity >= 2) {
 
136
        if (Game.SightedCharacter == NULL) {
 
137
        print(278, row, COLOR_YELLOW, "%10x", (tick >> 4) *  700);
 
138
        row += 7;
 
139
        print(278, row, COLOR_YELLOW, "%10x", (tick >> 3) *  1337);
 
140
        row += 7;
 
141
        print(278, row, COLOR_YELLOW, "%10x", (tick >> 2) *  4);
 
142
        row += 7;
 
143
        print(278, row, COLOR_YELLOW, "%10x", (tick >> 1) *  4935);
 
144
        row += 7;
 
145
        print(278, row, COLOR_YELLOW, "%10x", (int)(Game.MouseX * 0xc0c4c01a) - (tick >> 3));
 
146
        row += 7;
 
147
        print(278, row, COLOR_YELLOW, "%10x", (int)(Game.MouseY * 0xb4be2b3d) - (tick >> 4));
 
148
        row += 7;
 
149
        print(278, row, COLOR_YELLOW, "%10x", (tick << 4) *  4095);
 
150
        row += 7;
 
151
        print(278, row, COLOR_YELLOW, "%10x", (int)(Game.MouseZ * 0xf00ba573) - (tick >> 5));
 
152
    }
 
153
        else {
 
154
        print(238, row, COLOR_YELLOW, "%20s", "Citizen profile");
 
155
        row += 7;
 
156
        row += 7;
 
157
        print(238, row, COLOR_YELLOW, "%20s", "Coordinates");
 
158
        row += 7;
 
159
        print(238, row, COLOR_YELLOW, "     %6.2f - %6.2f", Game.SightedCharacter->mX, Game.SightedCharacter->mY);
 
160
        row += 7;
 
161
        row += 7;
 
162
        print(238, row, COLOR_YELLOW, "%20s", "Classification");
 
163
        row += 7;
 
164
        switch (Game.SightedCharacter->mType)
 
165
        {
 
166
        case 0:
 
167
            print(239, row + 1, COLOR_BLACK, "%20s", "** THREAT **");
 
168
            print(238, row, COLOR_RED, "%20s", "** THREAT **");
 
169
            row += 7;
 
170
            row += 7;
 
171
            print(238, row, COLOR_YELLOW, "%20s", "Destination");
 
172
            row += 7;
 
173
            if (Game.SightedCharacter->mTarget != -1)
 
174
            {
 
175
                print(238, row, COLOR_YELLOW, "     %6.2f - %6.2f", Game.characters[Game.SightedCharacter->mTarget].mX, Game.characters[Game.SightedCharacter->mTarget].mY);
 
176
                row += 7;
 
177
                row += 7;
 
178
                print(238, row, COLOR_YELLOW, "%20s", "Distance");
 
179
                row += 7;
 
180
                print(238, row, COLOR_YELLOW, "     %15.2f", distance(Game.characters[Game.SightedCharacter->mTarget].mX, Game.characters[Game.SightedCharacter->mTarget].mY, Game.SightedCharacter->mX, Game.SightedCharacter->mY));
 
181
            }
 
182
            else
 
183
            print(238, row, COLOR_YELLOW, "%20s", "Unknown");
 
184
            row += 7;
 
185
            row += 7;
 
186
            print(238, row, COLOR_YELLOW, "%20s", "VPB file ID");
 
187
            row += 7;
 
188
            print(238, row, COLOR_YELLOW, "      %03X-%07X/%02X", 
 
189
                        ((((uintptr_t)Game.SightedCharacter) * 7001337) & 0xfff),
 
190
                        (((uintptr_t)Game.SightedCharacter) * 1337357) & 0xfffffff,
 
191
                        (((uintptr_t)Game.SightedCharacter) * 70741)  & 0xff);
 
192
 
 
193
 
 
194
            break;
 
195
        case 1:
 
196
            print(239, row + 1, COLOR_BLACK, "%20s", "- VIP -");
 
197
            print(238, row, COLOR_GREEN, "%20s", "- VIP -");
 
198
            row += 7;
 
199
            row += 7;
 
200
            print(238, row, COLOR_YELLOW, "%20s", "Destination");
 
201
            row += 7;
 
202
            print(238, row, COLOR_YELLOW, "     %6.2f - %6.2f", (float)Game.spawnpoints[Game.SightedCharacter->mTarget].mX, (float)Game.spawnpoints[Game.SightedCharacter->mTarget].mY);
 
203
            row += 7;
 
204
            row += 7;
 
205
            print(238, row, COLOR_YELLOW, "%20s", "Distance");
 
206
            row += 7;
 
207
            print(238, row, COLOR_YELLOW, "     %15.2f", distance((float)Game.spawnpoints[Game.SightedCharacter->mTarget].mX, (float)Game.spawnpoints[Game.SightedCharacter->mTarget].mY, Game.SightedCharacter->mX, Game.SightedCharacter->mY));
 
208
            row += 7;
 
209
            row += 7;
 
210
            print(238, row, COLOR_YELLOW, "%20s", "Net worth");
 
211
            row += 7;
 
212
            print(238, row, COLOR_YELLOW, "%20s", "Classified");
 
213
            break;
 
214
        case 2:
 
215
            print(238, row, COLOR_YELLOW, "%20s", "Citizen");
 
216
            row += 7;
 
217
            row += 7;
 
218
            print(238, row, COLOR_YELLOW, "%20s", "Net worth");
 
219
            row += 7;
 
220
            print(238, row, COLOR_YELLOW, "%17u KC", (((uintptr_t)Game.SightedCharacter) * 1337357) % 71937);
 
221
            break;
 
222
        case 3:
 
223
            print(238, row, COLOR_YELLOW, "%20s", "Splat.");
 
224
            break;
 
225
        case 4:
 
226
            print(238, row, COLOR_BLACK, "%20s", "Missed shot");
 
227
            break;
 
228
        }
 
229
        row += 7;
 
230
 
 
231
        }
 
232
    }
 
233
 
 
234
    if (Game.FrameCount > 100)
 
235
    {
 
236
        Game.FrameCount = 0;
 
237
        Game.StartTick = tick;
 
238
    }
 
239
    
 
240
}
 
241