Initial public release of SystemK.

This commit is contained in:
Joe Kearney 2025-01-25 13:45:14 -06:00
parent 387f57cdda
commit 6f51f5b006
129 changed files with 11654 additions and 2 deletions

31
Game/Game.c Normal file
View file

@ -0,0 +1,31 @@
/*
* This program source code file is part of SystemK, a library in the KTag project.
*
* 🛡 <https://ktag.clubk.club> 🃞
*
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* There should be a copy of the GNU Affero General Public License in the LICENSE
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SystemK.h"
KTag_Game_Data_T KTAG_Game_Data =
{
.My_Health = MAX_HEALTH,
.My_Weapon = TEST_PATTERN_ID,
.My_Shield_Strength = 100,
.Time_Remaining_in_Game_in_ms = UINT32_MAX,
.Time_Remaining_Until_Countdown_in_ms = CONFIG_KTAG_T_DEFAULT_START_GAME_in_ms
};

238
Game/Game.h Normal file
View file

@ -0,0 +1,238 @@
/*
* This program source code file is part of SystemK, a library in the KTag project.
*
* 🛡 <https://ktag.clubk.club> 🃞
*
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* There should be a copy of the GNU Affero General Public License in the LICENSE
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GAME_H
#define GAME_H
#include "Weapons.h"
#define MAX_HEALTH 10
//! Implemented according to the 2024-07-20 "KTag Teams Compatibility Matrix".
typedef enum
{
TEAM_PURPLE = 0,
TEAM_RED = 1,
TEAM_BLUE = 2,
TEAM_WHITE = 3,
COMMON_TEAM_ID_MASK = 3,
TEAM_ORANGE = 4,
TEAM_GREEN = 5,
TEAM_YELLOW = 6,
TEAM_BLACK = 7,
EXTENDED_TEAM_ID_MASK = 7
} TeamID_t;
__attribute__((always_inline)) inline TeamID_t Resolve_Common_Team_ID(uint8_t team_ID)
{
return (team_ID & COMMON_TEAM_ID_MASK);
}
__attribute__((always_inline)) inline bool Team_Can_Tag_Me(uint8_t tagging_team_ID)
{
bool can_tag = false;
uint8_t team_ID;
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &team_ID);
TeamID_t my_common_team_ID = Resolve_Common_Team_ID(team_ID);
if (tagging_team_ID == TEAM_PURPLE)
{
can_tag = true;
}
else if (tagging_team_ID != my_common_team_ID)
{
if ((tagging_team_ID == TEAM_RED) || (tagging_team_ID == TEAM_BLUE))
{
can_tag = true;
}
}
return can_tag;
}
typedef struct
{
uint8_t My_Health;
WeaponID_t My_Weapon;
uint8_t My_Shield_Strength;
uint32_t Time_Remaining_in_Game_in_ms;
uint32_t Time_Remaining_Until_Countdown_in_ms;
uint16_t Shots_Fired;
uint16_t Tags_Received;
uint16_t Times_Tagged_Out;
uint8_t Bombs_Remaining;
} KTag_Game_Data_T;
extern KTag_Game_Data_T KTAG_Game_Data;
__attribute__((always_inline)) inline uint8_t Get_Health()
{
return KTAG_Game_Data.My_Health;
}
__attribute__((always_inline)) inline void Set_Health(uint8_t health)
{
KTAG_Game_Data.My_Health = health;
if (KTAG_Game_Data.My_Health == 0)
{
KEvent_T tagged_out_event = { .ID = KEVENT_TAGGED_OUT, .Data = (void *)0x00 };
Post_KEvent(&tagged_out_event);
}
}
__attribute__((always_inline)) inline void Reduce_Health(uint8_t reduction)
{
if (reduction < KTAG_Game_Data.My_Health)
{
KTAG_Game_Data.My_Health -= reduction;
}
else
{
KTAG_Game_Data.My_Health = 0;
KEvent_T tagged_out_event = { .ID = KEVENT_TAGGED_OUT, .Data = (void *)0x00 };
Post_KEvent(&tagged_out_event);
}
}
__attribute__((always_inline)) inline WeaponID_t Get_Weapon()
{
return KTAG_Game_Data.My_Weapon;
}
__attribute__((always_inline)) inline void Set_Weapon(WeaponID_t weapon)
{
KTAG_Game_Data.My_Weapon = weapon;
}
__attribute__((always_inline)) inline uint16_t Get_Shield_Strength()
{
return KTAG_Game_Data.My_Shield_Strength;
}
__attribute__((always_inline)) inline void Set_Shield_Strength(uint16_t strength)
{
KTAG_Game_Data.My_Shield_Strength = strength;
}
__attribute__((always_inline)) inline void Reset_Shots_Fired()
{
KTAG_Game_Data.Shots_Fired = 0;
}
__attribute__((always_inline)) inline void Increment_Shots_Fired()
{
if (KTAG_Game_Data.Shots_Fired < UINT16_MAX)
{
KTAG_Game_Data.Shots_Fired++;
}
}
__attribute__((always_inline)) inline void Reset_Tags_Received()
{
KTAG_Game_Data.Tags_Received = 0;
}
__attribute__((always_inline)) inline void Increment_Tags_Received()
{
if (KTAG_Game_Data.Tags_Received < UINT16_MAX)
{
KTAG_Game_Data.Tags_Received++;
}
}
__attribute__((always_inline)) inline void Reset_Times_Tagged_Out()
{
KTAG_Game_Data.Times_Tagged_Out = 0;
}
__attribute__((always_inline)) inline void Increment_Times_Tagged_Out()
{
if (KTAG_Game_Data.Times_Tagged_Out < UINT16_MAX)
{
KTAG_Game_Data.Times_Tagged_Out++;
}
}
__attribute__((always_inline)) inline bool Still_Playing()
{
return (KTAG_Game_Data.My_Health > 0);
}
__attribute__((always_inline)) inline bool Back_In()
{
return Still_Playing();
}
__attribute__((always_inline)) inline void Set_Time_Remaining_in_Game(uint32_t time_in_ms)
{
KTAG_Game_Data.Time_Remaining_in_Game_in_ms = time_in_ms;
}
__attribute__((always_inline)) inline uint32_t Get_Time_Remaining_in_Game_in_ms()
{
return KTAG_Game_Data.Time_Remaining_in_Game_in_ms;
}
__attribute__((always_inline)) inline void Set_Time_Remaining_Until_Countdown(uint32_t time_in_ms)
{
KTAG_Game_Data.Time_Remaining_Until_Countdown_in_ms = time_in_ms;
}
__attribute__((always_inline)) inline uint32_t Get_Time_Remaining_Until_Countdown_in_ms()
{
return KTAG_Game_Data.Time_Remaining_Until_Countdown_in_ms;
}
__attribute__((always_inline)) inline uint16_t Get_Shots_Fired()
{
return KTAG_Game_Data.Shots_Fired;
}
__attribute__((always_inline)) inline uint16_t Get_Tags_Received()
{
return KTAG_Game_Data.Tags_Received;
}
__attribute__((always_inline)) inline uint16_t Get_Times_Tagged_Out()
{
return KTAG_Game_Data.Times_Tagged_Out;
}
__attribute__((always_inline)) inline void Set_Available_Bombs(uint8_t n_bombs)
{
KTAG_Game_Data.Bombs_Remaining = n_bombs;
}
__attribute__((always_inline)) inline bool Use_Bomb_If_Available()
{
bool available = false;
if (KTAG_Game_Data.Bombs_Remaining > 0)
{
KTAG_Game_Data.Bombs_Remaining--;
available = true;
}
return available;
}
#endif // GAME_H

171
Game/Weapons.c Normal file
View file

@ -0,0 +1,171 @@
/*
* This program source code file is part of SystemK, a library in the KTag project.
*
* 🛡 <https://ktag.clubk.club> 🃞
*
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* There should be a copy of the GNU Affero General Public License in the LICENSE
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SystemK.h"
//! All the weapons, in the same order as #WeaponID_t.
Weapon_t WeaponsByID[NUMBER_OF_WEAPONS] =
{
// Test Pattern
{
.ID = TEST_PATTERN_ID,
.Type = ENERGY,
.Protocol = TEST_PROTOCOL,
.Damage_Per_Shot = 1,
.Shots_Per_Reload = UINT16_MAX,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 1000,
.Time_To_Reload_in_ms = 0
},
// Bayonette
{
.ID = BAYONETTE_ID,
.Type = EDGE,
.Protocol = MILES_TAG_II_PROTOCOL, // For now...
.Damage_Per_Shot = 1,
.Shots_Per_Reload = UINT16_MAX,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 1000,
.Time_To_Reload_in_ms = 0
},
// Pistol
{
.ID = PISTOL_ID,
.Type = PROJECTILE,
.Protocol = MILES_TAG_II_PROTOCOL, // For now...
.Damage_Per_Shot = 10,
.Shots_Per_Reload = 8,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
},
// Shotgun
{
.ID = SHOTGUN_ID,
.Type = PROJECTILE,
.Protocol = MILES_TAG_II_PROTOCOL, // For now...
.Damage_Per_Shot = 20,
.Shots_Per_Reload = 2,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 500,
.Time_To_Reload_in_ms = 10000
},
// Rifle
{
.ID = RIFLE_ID,
.Type = PROJECTILE,
.Protocol = MILES_TAG_II_PROTOCOL, // For now...
.Damage_Per_Shot = 10,
.Shots_Per_Reload = 8,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 5000
},
// Machine Gun
{
.ID = MACHINE_GUN_ID,
.Type = PROJECTILE,
.Protocol = MILES_TAG_II_PROTOCOL, // For now...
.Damage_Per_Shot = 10,
.Shots_Per_Reload = 250,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 0,
.Time_To_Reload_in_ms = 2*60*1000
},
// Nerf Laser Ops Pro
{
.ID = NERF_LASER_OPS_ID,
.Type = ENERGY,
.Protocol = NERF_LASER_OPS_PRO_PROTOCOL,
.Damage_Per_Shot = 10,
.Shots_Per_Reload = 10,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
},
// Nerf Laser Strike Blaster
{
.ID = NERF_LASER_STRIKE_BLASTER_ID,
.Type = ENERGY,
.Protocol = NERF_LASER_STRIKE_PROTOCOL,
.Damage_Per_Shot = 10,
.Shots_Per_Reload = 12,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
},
// Nerf Phoenix LTX
{
.ID = NERF_PHOENIX_LTX_ID,
.Type = ENERGY,
.Protocol = NERF_PHOENIX_LTX_PROTOCOL,
.Damage_Per_Shot = 10,
.Shots_Per_Reload = 10,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
},
// Squad Hero Pistol
{
.ID = SQUAD_HERO_PISTOL,
.Type = ENERGY,
.Protocol = SQUAD_HERO_PROTOCOL,
.Damage_Per_Shot = 1,
.Shots_Per_Reload = 10,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
},
// Laser X
{
.ID = LASER_X_ID,
.Type = ENERGY,
.Protocol = LASER_X_PROTOCOL,
.Damage_Per_Shot = 1,
.Shots_Per_Reload = 10,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
},
// The Dubuque Protocol
{
.ID = LASER_X_ID,
.Type = ENERGY,
.Protocol = DUBUQUE_PROTOCOL,
.Damage_Per_Shot = 1,
.Shots_Per_Reload = 10,
.Delay_Before_Sending_Shot_in_ms = 0,
.Time_Between_Shots_in_ms = 300,
.Time_To_Reload_in_ms = 3000
}
};

82
Game/Weapons.h Normal file
View file

@ -0,0 +1,82 @@
/*
* This program source code file is part of SystemK, a library in the KTag project.
*
* 🛡 <https://ktag.clubk.club> 🃞
*
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* There should be a copy of the GNU Affero General Public License in the LICENSE
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WEAPON_H
#define WEAPON_H
//! These have assigned values because they are stored in #NVM_WEAPON_ID.
typedef enum
{
TEST_PATTERN_ID = 0,
BAYONETTE_ID = 1,
PISTOL_ID = 2,
SHOTGUN_ID = 3,
RIFLE_ID = 4,
MACHINE_GUN_ID = 5,
NERF_LASER_OPS_ID = 6,
NERF_LASER_STRIKE_BLASTER_ID = 7,
NERF_PHOENIX_LTX_ID = 8,
SQUAD_HERO_PISTOL = 9,
LASER_X_ID = 10,
DUBUQUE_PROTOCOL_ID = 11,
// Leave this last!
NUMBER_OF_WEAPONS
} WeaponID_t;
typedef enum
{
EDGE,
PROJECTILE,
EXPLOSION,
ENERGY
} WeaponType_t;
typedef struct
{
WeaponID_t ID;
WeaponType_t Type;
Protocol_T Protocol;
uint16_t Damage_Per_Shot;
uint16_t Shots_Per_Reload;
uint32_t Delay_Before_Sending_Shot_in_ms;
//! This is the inverse of "Rate of Fire".
uint32_t Time_Between_Shots_in_ms;
uint32_t Time_To_Reload_in_ms;
} Weapon_t;
extern Weapon_t WeaponsByID[NUMBER_OF_WEAPONS];
__attribute__((always_inline)) inline Weapon_t GetWeaponFromID(WeaponID_t id)
{
Weapon_t result = WeaponsByID[TEST_PATTERN_ID];
if (id < NUMBER_OF_WEAPONS)
{
result = WeaponsByID[id];
}
return result;
}
#endif // WEAPON_H