<commit_before>/*
 game_entity.h
 Classic Invaders

 Copyright (c) 2010, <NAME>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification, are permitted
 provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, this list of conditions
 and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the documentation and/or other
 materials provided with the distribution.

 * Neither the name of The No Quarter Arcade (http://www.noquarterarcade.com/)  nor the names of
 its contributors may be used to endorse or promote products derived from this software without
 specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef GAME_ENTITY_H
#define GAME_ENTITY_H

#include <assert.h>

#include "game.h"
#include "screen.h"

extern EventCounter event_counter;

enum GameEntityTypes {
    GAME_ENTITY_UNKNOWN,
    GAME_ENTITY_PLAYER,
    GAME_ENTITY_ALIEN,
    GAME_ENTITY_ALIEN2,
    GAME_ENTITY_ALIEN3,
    GAME_ENTITY_BONUS_SHIP,
    GAME_ENTITY_SMALL_BONUS_SHIP,
    GAME_ENTITY_SHOT,
    GAME_ENTITY_SHIELD_PIECE,
    GAME_ENTITY_EXPLOSION,
    GAME_ENTITY_SHIELD_GROUP,
    NUM_GAME_ENTITY_TYPES,
};

#define NUM_GAME_ENTITY_IMAGES     8

namespace GameEntities {

    // When all instances of a class of GameEntity have the same properties(),
    // use this struct to store the common property values and save memory.
    struct GameEntityTypeProperties {
        uint16_t frame_duration;  // How much time before going to next frame.
        int points; // point value of individual objects

        // width and height of the object image.
        int w, h;

        // heights, widths, and coords used for reduced bounding box collision detection
        int coll_w, coll_h, coll_x_offset, coll_y_offset;

        int right_limit, bottom_limit;

        // All image frames used to draw the entity.  Each image is represented
        // by a unique integer handle.
        int images[NUM_GAME_ENTITY_IMAGES];
    };

    class GameEntity {
    private:
        static GameEntityTypeProperties type_properties[NUM_GAME_ENTITY_TYPES];

        static Game::Game* game;          // Common pointer to the current game.
        static Graphics::Screen* screen;  // Common pointer to video screen.

        fixed x, y;   // location
        int dx, dy;   // velocity -- speed in pixels/sec and direction
        uint16_t frame_time_count; // control in place animation speed
        uint8_t position;   // used by Aliens to determine if and when to fire
        uint8_t fire_chance;

        // Entity state flags.
        bool alive:1;
        bool active:1;
        bool hit:1;       // used by Shot to avoid hitting more than one object

        int image_num;
        int type;

    public:
        GameEntity() : type(GAME_ENTITY_UNKNOWN) {}
        void init(int type, int x, int y, int dx, int dy, bool active);
        void movement(int16_t delta);
        static void set_type_property(int type,
                                      const GameEntityTypeProperties& prop) {
            type_properties[type] = prop;
        }
        GameEntityTypeProperties* properties() const {
            return &type_properties[type];
        }
        void draw();
        void cleanup_draw();
        bool is_active() const {
            return active && is_alive();
        }
        void deactivate() { active = false; }
        void activate() { active = true; }
        bool is_alive() const { return alive; }
        void kill() { alive = false; }
        void init_x(int init) { x = INT_TO_FIXED(init); }
        void init_y(int init) { y = INT_TO_FIXED(init); }
        int get_x() const { return x_int(); }
        int get_y() const { return y_int(); }<commit_msg>game_entity: Specify bit widths for small variables<commit_after>/*
 game_entity.h
 Classic Invaders

 Copyright (c) 2010, <NAME>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification, are permitted
 provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, this list of conditions
 and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the documentation and/or other
 materials provided with the distribution.

 * Neither the name of The No Quarter Arcade (http://www.noquarterarcade.com/)  nor the names of
 its contributors may be used to endorse or promote products derived from this software without
 specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef GAME_ENTITY_H
#define GAME_ENTITY_H

#include <assert.h>

#include "game.h"
#include "screen.h"

extern EventCounter event_counter;

enum GameEntityTypes {
    GAME_ENTITY_UNKNOWN,
    GAME_ENTITY_PLAYER,
    GAME_ENTITY_ALIEN,
    GAME_ENTITY_ALIEN2,
    GAME_ENTITY_ALIEN3,
    GAME_ENTITY_BONUS_SHIP,
    GAME_ENTITY_SMALL_BONUS_SHIP,
    GAME_ENTITY_SHOT,
    GAME_ENTITY_SHIELD_PIECE,
    GAME_ENTITY_EXPLOSION,
    GAME_ENTITY_SHIELD_GROUP,
    NUM_GAME_ENTITY_TYPES,
};

#define NUM_GAME_ENTITY_IMAGES     8

namespace GameEntities {

    // When all instances of a class of GameEntity have the same properties(),
    // use this struct to store the common property values and save memory.
    struct GameEntityTypeProperties {
        uint16_t frame_duration;  // How much time before going to next frame.
        int points; // point value of individual objects

        // width and height of the object image.
        int w, h;

        // heights, widths, and coords used for reduced bounding box collision detection
        int coll_w, coll_h, coll_x_offset, coll_y_offset;

        int right_limit, bottom_limit;

        // All image frames used to draw the entity.  Each image is represented
        // by a unique integer handle.
        int images[NUM_GAME_ENTITY_IMAGES];
    };

    class GameEntity {
    private:
        static GameEntityTypeProperties type_properties[NUM_GAME_ENTITY_TYPES];

        static Game::Game* game;          // Common pointer to the current game.
        static Graphics::Screen* screen;  // Common pointer to video screen.

        fixed x, y;   // location
        int dx, dy;   // velocity -- speed in pixels/sec and direction
        uint16_t frame_time_count; // control in place animation speed
        uint8_t fire_chance;

        uint8_t position:6;   // used by Aliens to determine if and when to fire

        // Entity state flags.
        bool alive:1;
        bool active:1;
        bool hit:1;       // used by Shot to avoid hitting more than one object

        uint8_t image_num:3;  // Index of the current animation image.
        uint8_t type:4;       // Must have enough bits for NUM_GAME_ENTITY_TYPES-1.

    public:
        GameEntity() : type(GAME_ENTITY_UNKNOWN) {}
        void init(int type, int x, int y, int dx, int dy, bool active);
        void movement(int16_t delta);
        static void set_type_property(int type,
                                      const GameEntityTypeProperties& prop) {
            type_properties[type] = prop;
        }
        GameEntityTypeProperties* properties() const {
            return &type_properties[type];
        }
        void draw();
        void cleanup_draw();
        bool is_active() const {
            return active && is_alive();
        }
        void deactivate() { active = false; }
        void activate() { active = true; }
        bool is_alive() const { return alive; }
        void kill() { alive = false; }
        void init_x(int init) { x = INT_TO_FIXED(init); }
        void init_y(int init) { y = INT_TO_FIXED(init); }
        int get_x() const { return x_int(); }
        int get_y() const { return y_int(); }
{'fraction_non_alphanumeric': 0.06259930092151256, 'fraction_numerical': 0.0044486812837623135, 'mean_word_length': 2.88559670781893, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1154993', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2548, 'n_words': 1036}