Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Feb 18, 2024
2 parents 85eebe1 + 3a0c456 commit 2fa49c2
Show file tree
Hide file tree
Showing 112 changed files with 2,783 additions and 1,120 deletions.
92 changes: 92 additions & 0 deletions gse/default/factions.gls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
return [

// SMAC
['GAIANS', {
name: 'Gaians',
files: {
pcx: 'Gaians.pcx'
}
}],
['HIVE', {
name: 'Hive',
files: {
pcx: 'hive.pcx'
}
}],
['UNIVERSITY', {
name: 'University',
files: {
pcx: 'univ.pcx'
}
}],
['MORGANITES', {
name: 'Morganites',
files: {
pcx: 'morgan.pcx'
}
}],
['SPARTANS', {
name: 'Spartans',
files: {
pcx: 'spartans.pcx'
}
}],
['BELIEVERS', {
name: 'Believers',
files: {
pcx: 'believe.pcx'
}
}],
['PEACEKEEPERS', {
name: 'Peacekeepers',
files: {
pcx: 'peace.pcx'
}
}],

// SMACX
['CONSCIOUSNESS', {
name: 'Consciousness',
files: {
pcx: 'cyborg.pcx'
}
}],
['PIRATES', {
name: 'Pirates',
files: {
pcx: 'pirates.pcx'
}
}],
['DRONES', {
name: 'Drones',
files: {
pcx: 'drone.pcx'
}
}],
['ANGELS', {
name: 'Angels',
files: {
pcx: 'angels.pcx'
}
}],
['PLANETCULT', {
name: 'Planet Cult',
files: {
pcx: 'fungboy.pcx'
}
}],
['CARETAKERS', {
name: 'Caretakers',
files: {
pcx: 'caretake.pcx'
},
is_progenitor: true
}],
['USURPERS', {
name: 'Usurpers',
files: {
pcx: 'usurper.pcx'
},
is_progenitor: true
}],
];
76 changes: 66 additions & 10 deletions gse/default/main.gls.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,82 @@
#game.on.start(() => {
#game.on.configure(() => {

const factions = #include('factions');
let i = 0;
let sz = #size(factions);
while (i < sz) {
#game.factions.define(factions[i][0], factions[i][1]);
i++;
}

const rules = #include('rules');
const units = #include('units');
// TODO

});

// will be populated on start
let players = [];
let players_sz = 0;
let random_player = () => {
return players[(#game.random.get_int(0, players_sz - 1))];
};

let random_morale = () => {
return #game.random.get_int(1, 7); // TODO: get some constants from api
};

let random_health = () => {
return #game.random.get_float(#to_float(0), #to_float(1));
};

#game.on.start(() => {

// init players
players = #game.players.get_all();
players_sz = #size(players);

const units = #include('units');
let i = 0;
while (i < #size(units)) {
let sz = #size(units);
while (i < sz) {
#game.units.define(units[i][0], units[i][1]);
i++;
}

let y = 0;
while (y < #game.map.height) {
let w = #game.map.get_width();
let h = #game.map.get_height();
while (y < h) {
let x = 0;
while (x < #game.map.width) {
while (x < w) {
if (x % 2 == y % 2) {
if (#game.random.get_int(0, 1) == 1) {
let owner = random_player();
let tile = #game.map.get_tile(x, y);
let unit = null;
if (tile.is_land) {
if (#game.random.get_int(0, 2) != 1) {
unit = #game.units.spawn('MindWorms', tile);
unit = #game.units.spawn('MindWorms', owner, tile, random_morale(), random_health());
} else {
unit = #game.units.spawn('SporeLauncher', tile);
if (tile.has_fungus && #game.random.get_int(0, 1) == 0) {
// morale depends on count of fungus tiles around
let morale = 1;
let neighbours = tile.get_surrounding_tiles();
let sz = #size(neighbours);
let i = 0;
while (morale < 7 && i < sz) {
if (neighbours[i].has_fungus) {
morale++;
}
i++;
}
unit = #game.units.spawn('FungalTower', owner, tile, morale, random_health());
} else {
unit = #game.units.spawn('SporeLauncher', owner, tile, random_morale(), random_health());
}
}
} else {
if (#game.random.get_int(0, 1) == 1) {
unit = #game.units.spawn('SeaLurk', tile);
unit = #game.units.spawn('SeaLurk', owner, tile, random_morale(), random_health());
}
}
}
Expand All @@ -36,14 +87,19 @@
}
});

#game.on.turn(() => {
#print('NEW TURN');
#print('PLAYERS: ' + #to_string(#game.players.get_all()));
});

#game.on.spawn_unit((unit) => {
let def = unit.get_def();
if (def.name != 'MindWorms') {
let tile = unit.get_tile();
let neighbours = [tile.get_W(), tile.get_NW(), tile.get_N(), tile.get_NE(), tile.get_E(), tile.get_SE(), tile.get_S(), tile.get_SW()];
let nearby_units_count = 0;
let i = 0;
let sz = #size(neighbours);
let nearby_units_count = 0;
while (i < sz) {
if (!#is_empty(neighbours[i].get_units())) {
nearby_units_count++;
Expand All @@ -58,6 +114,6 @@

#game.on.despawn_unit((unit) => {
if (unit.get_def() == 'SporeLauncher') {
#game.units.spawn('MindWorms', unit.get_tile());
#game.units.spawn('MindWorms', random_player(), unit.get_tile(), random_morale(), random_health());
}
});
40 changes: 12 additions & 28 deletions gse/default/units.gls.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
return [

['MindWorms', {
type: 'static',
render: {
type: 'sprite',
file: 'Units.pcx',
x: 206, y: 233,
w: 100, h: 75,
cx: 257, cy: 284,
},
}],

['SeaLurk', {
let native_lifeform = (name, base_y) => {
return [name, {
type: 'static',
render: {
type: 'sprite',
file: 'Units.pcx',
x: 104, y: 310,
x: 2, y: base_y,
w: 100, h: 75,
cx: 155, cy: 353,
cx: 53, cy: base_y + 51,
morale_based_xshift: 102
},
}],

['SporeLauncher', {
type: 'static',
render: {
type: 'sprite',
file: 'Units.pcx',
x: 308, y: 387,
w: 100, h: 75,
cx: 359, cy: 438,
}
}]
}];
};

return [
native_lifeform('FungalTower', 79),
native_lifeform('MindWorms', 233),
native_lifeform('SeaLurk', 310),
native_lifeform('SporeLauncher', 387),
];
29 changes: 27 additions & 2 deletions src/game/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,26 @@ Event::Event( const Event& other )
NEW( data.global_message.message, std::string, *other.data.global_message.message );
break;
}
case ET_TURN_COMPLETE_STATUS: {
data.turn_complete_status.is_turn_complete = other.data.turn_complete_status.is_turn_complete;
break;
}
case ET_SLOT_DEFINE: {
NEW( data.slot_define.slotdefs, slot_defines_t, *other.data.slot_define.slotdefs );
break;
}
case ET_UNIT_DEFINE: {
NEW( data.unit_define.serialized_unitdef, std::string, *other.data.unit_define.serialized_unitdef );
break;
}
case ET_UNIT_SPAWN: {
NEW( data.unit_spawn.serialized_unit, std::string, *other.data.unit_spawn.serialized_unit );
data.unit_spawn.unit_id = other.data.unit_spawn.unit_id;
NEW( data.unit_spawn.unitdef_name, std::string, *other.data.unit_spawn.unitdef_name );
data.unit_spawn.slot_index = other.data.unit_spawn.slot_index;
data.unit_spawn.coords = other.data.unit_spawn.coords;
data.unit_spawn.is_active = other.data.unit_spawn.is_active;
data.unit_spawn.morale = other.data.unit_spawn.morale;
data.unit_spawn.health = other.data.unit_spawn.health;
break;
}
case ET_UNIT_DESPAWN: {
Expand Down Expand Up @@ -57,8 +74,16 @@ Event::~Event() {
DELETE( data.global_message.message );
break;
}
case ET_SLOT_DEFINE: {
DELETE( data.slot_define.slotdefs );
break;
}
case ET_UNIT_DEFINE: {
DELETE( data.unit_define.serialized_unitdef );
break;
}
case ET_UNIT_SPAWN: {
DELETE( data.unit_spawn.serialized_unit );
DELETE( data.unit_spawn.unitdef_name );
break;
}
default: {
Expand Down
40 changes: 35 additions & 5 deletions src/game/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Event {
ET_QUIT,
ET_ERROR,
ET_GLOBAL_MESSAGE,
ET_TURN_COMPLETE_STATUS,
ET_SLOT_DEFINE,
ET_UNIT_DEFINE,
ET_UNIT_SPAWN,
ET_UNIT_DESPAWN,
};
Expand All @@ -24,24 +27,51 @@ class Event {

const event_type_t type = ET_NONE;

struct slot_define_t {
size_t slot_index;
// TODO: name etc
struct {
float r;
float g;
float b;
float a;
} color;
bool is_progenitor;
};
typedef std::vector< slot_define_t > slot_defines_t;

union {
struct {
std::string* reason;
const std::string* reason;
} quit;
struct {
std::string* what;
std::string* stacktrace;
const std::string* what;
const std::string* stacktrace;
} error;
struct {
std::string* message;
const std::string* message;
} global_message;
struct {
std::string* serialized_unit;
bool is_turn_complete;
} turn_complete_status;
struct {
slot_defines_t* slotdefs;
} slot_define;
struct {
const std::string* serialized_unitdef; // can be optimized
} unit_define;
struct {
size_t unit_id;
const std::string* unitdef_name;
size_t slot_index;
struct {
float x;
float y;
float z;
} coords;
bool is_active;
unit::Unit::morale_t morale;
unit::Unit::health_t health;
} unit_spawn;
struct {
size_t unit_id;
Expand Down
Loading

0 comments on commit 2fa49c2

Please sign in to comment.