Open object format

- To make prototyping and possibly future custom content easier, I've created a JSON-based object format with the same properties found in The Sims
- Renamed dorms directory to dorm
- Added some d20 C code I found to possibly enhance the skill system in the future
- Added voting machine by Don Hopkins
- Removed core.h in favor of niotso.zig which accomplishes the same thing
This commit is contained in:
Tony Bark 2024-05-07 07:27:59 -04:00
parent 00255a6c17
commit a1cdd92c3f
31 changed files with 259 additions and 33 deletions

View file

@ -4,7 +4,9 @@
<img title="" src="resources/logo.png" width="150" alt="""> <img title="" src="resources/logo.png" width="150" alt=""">
</p> </p>
<p align="center"> <p align="center">
<img alt="GitHub License" src="https://img.shields.io/github/license/tonytins/mysimulation"> <img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues-pr/tonytins/mysimulation"> <img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/tonytins/mysimulation/build"> <img alt="GitHub License" src="https://img.shields.io/github/license/tonytins/mysimulation"> <img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr/tonytins/mysimulation"> <img alt="GitHub Issues" src="https://img.shields.io/github/issues/tonytins/mysimulation">
</p> </p>
My Simulation is an **experimental** open source multiplayer game based upon The Sims Online. It attempts to mimic the original game as closely as possible while extending it with new features. My Simulation is an **experimental** open source multiplayer game based upon The Sims Online. It attempts to mimic the original game as closely as possible while extending it with new features.

View file

@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "mysimulation", .name = "mysim",
.root_source_file = b.path("src/main.zig"), .root_source_file = b.path("src/main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
@ -80,6 +80,7 @@ pub fn build(b: *std.Build) void {
}); });
exe_unit_tests.linkLibC(); exe_unit_tests.linkLibC();
exe_unit_tests.linkLibCpp();
exe_unit_tests.addIncludePath(.{ .path = "./library" }); exe_unit_tests.addIncludePath(.{ .path = "./library" });
exe_unit_tests.root_module.addImport("raylib", raylib); exe_unit_tests.root_module.addImport("raylib", raylib);

View file

@ -1,8 +1,8 @@
.{ .{
.name = "mysimulation", .name = "mysim",
// This is a [Semantic Version](https://semver.org/). // This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication. // In a future version of Zig it will be used for package deduplication.
.version = "0.1.100", .version = "0.1.101",
// This field is optional. // This field is optional.
// This is currently advisory only; Zig does not yet do anything // This is currently advisory only; Zig does not yet do anything

120
library/extra/d20/d20.c Normal file
View file

@ -0,0 +1,120 @@
#include <d20.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define MAX_UINT64_T 18446744073709551615ul;
/*---------------------------------------------------------------------------*/
/* This is xoshiro256** 1.0, one of our all-purpose, rock-solid
generators. It has excellent (sub-ns) speed, a state (256 bits) that is
large enough for any parallel application, and it passes all tests we
are aware of.
For generating just floating-point numbers, xoshiro256+ is even faster.
The state must be seeded so that it is not everywhere zero. If you have
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
output to fill s. */
static uint64_t rotl(const uint64_t x, int k) {
return (x << k) | (x >> (64 - k));
}
uint64_t s[4];
uint64_t next(void) {
const uint64_t result = rotl(s[1] * 5, 7) * 9;
const uint64_t t = s[1] << 17;
s[2] ^= s[0];
s[3] ^= s[1];
s[1] ^= s[2];
s[0] ^= s[3];
s[2] ^= t;
s[3] = rotl(s[3], 45);
return result;
}
/*---------------------------------------------------------------------------*/
int roll_from_char_array(const char *ca){
int dice = 0;
int sides = 0;
int modifier = 0;
int d_token = 0;
int m_token = 0;
char *d_tok = (char *)"d";
char *D_tok = (char *)"D";
char *mi_tok = (char *)"-";
char *pl_tok = (char *)"+";
while(*ca != '\0'){
if(*ca == *d_tok || *ca == *D_tok){
d_token = 1;
} else if(*ca == *mi_tok) {
m_token = -1;
} else if (*ca == *pl_tok) {
m_token = 1;
} else {
if(d_token == 0)
{
dice = dice * 10;
dice += *ca - '0';
} else if(m_token == 0){
sides = sides * 10;
sides += *ca - '0';
} else {
modifier = modifier * 10;
modifier += *ca - '0';
}
}
++ca;
}
modifier = modifier * m_token;
if(dice == 0){
return ROLL_FROM_CHAR_ARRAY_PARSE_FAILURE_NO_NUMBER_DICE;
} else if (sides == 0){
return ROLL_FROM_CHAR_ARRAY_PARSE_FAILURE_NO_NUMBER_OF_SIDES;
}
return roll(dice, sides, modifier);
}
int roll(int dice, int sides, int modifier){
uint64_t one = rand();
uint64_t two = rand();
uint64_t three = rand();
uint64_t four = rand();
s[0] = one;
s[1] = two;
s[2] = three;
s[3] = four;
unsigned mask;
mask = (1 << 12) - 1;
//uint8_t i=0,parts[8]={0};
int a = 0;
int result = 0;
do {
result += (int) floor(((float) (next() & mask) / (float) 4096) * (float) sides) + 1;
++a;
} while (a < dice);
result += modifier;
return result;
}

22
library/extra/d20/d20.h Normal file
View file

@ -0,0 +1,22 @@
/** @file d20.h
* @brief Implements Dungeons & Dragons style dice in C
*
* d20.h is a reimplementation of https://github.com/opensourcedoc/d20-c,
* but following the principles of being a single header/file library with
* a minimal API
*
* @author adamml
* @date 2022-11-07
*/
#ifndef COM_GITHUB_ADAMML_D20
#define COM_GITHUB_ADAMML_D20
#define ROLL_FROM_CHAR_ARRAY_PARSE_FAILURE_NO_NUMBER_DICE -9999; /* The number of dices to roll was not correctly parsed */
#define ROLL_FROM_CHAR_ARRAY_PARSE_FAILURE_NO_NUMBER_OF_SIDES -99999; /* The number of sides on the dice was not correctl parsed */
int roll_from_char_array(const char *ca);
int roll(int dice, int sides, int modifer);
#endif

View file

@ -1,7 +0,0 @@
#include "iff/iff.h"
#include "iff/iffparser.h"
#include "far/far.h"
#include "far/config.h"
#include "xa/read_xa.h"
#include "utk/read_utk.h"
#include "xa/read_xa.h"

View file

@ -1,10 +1 @@
--------------------------------|---------------------------------------------------------------- Thanks to Don Hopkins (https://donhopkins.medium.com/) for kickstarting The Sims 1 customization, encouraging fine individuals to document the game, and most importantly, sharing with us his documentation of his VitaBoy skeletal character animation library used in The Sims 1, in the form of articles and videos. Dozens of thanks from each one of us.
| Thanks to | for |
|--------------------------------|----------------------------------------------------------------|
| Don Hopkins | Kickstarting The Sims 1 customization, encouraging fine |
| | individuals to document the game, and most importantly, |
| | sharing with us his documentation of his VitaBoy skeletal |
| | character animation library used in The Sims 1, in the form |
| | of articles and videos. Dozens of thanks from each one of us. |
| (*) <http://www.donhopkins.com/> |
-------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,3 @@
Item(s) created by Judhudson@knology.net
For use with The Sims 1 and its expansions.
http://www.simprograms.com (now https://beyondsims.com)

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,37 @@
{
"item": {
"name": "Dorm End Table",
"description": "Created by Judhudson@knology.net",
"version": 1,
"size": 1,
"catagory": "surfaces",
"base": "table",
"views": {
"south": {
"texture": "table_1.png",
"buffer": "table_1_z.png"
},
"north": {
"texture": "table_2.png",
"buffer": "table_2_z.png"
}
},
"motives": {
"room": 5,
"hunger": 0,
"social": 0,
"fun": 0,
"hygiene": 0,
"energy": 0,
"bladder": 0
},
"skills": {
"cooking": 5,
"mechanical": 0,
"charism": 0,
"body": 0,
"logic": 0,
"creativity": 0
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -1,6 +0,0 @@
Item(s) created by Judhudson@knology.net
For use with The Sims 1 and its expansions.
Instructions: Unzip and extract to Maxis/The Sims/Downloads folder. Create the folder if necessary.
http://www.simprograms.com

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,3 @@
Dumbold Voting Machine, by Don Hopkins.
Special thanks to SimBabes, SimSlice, Will Wright, Ted Selker, John Gilmore, Cindy Cohen, Alan Korn, Bev Harris, Baxter the Chimpanzee, Black Box Voting, EFF, Verified Voting, CalTech-MIT/Voting Technology Project.
This Sims object is open source software, as all voting machine software should be.

Binary file not shown.

View file

@ -6,5 +6,10 @@ pub const Branding = struct {
pub const Config = struct { pub const Config = struct {
height: i64, height: i64,
width: i64, width: i64,
game_path: []const u8,
branding: *Branding, branding: *Branding,
pub fn init(self: Config) Config {
return self;
}
}; };

View file

@ -1,4 +0,0 @@
const iff = @cImport({
@cInclude("./iff/iff.h");
@cInclude("./iff/iffparser.h");
});

49
src/io/oiff.zig Normal file
View file

@ -0,0 +1,49 @@
const std = @import("std");
const rl = @import("raylib");
pub const Texture = struct {
texture: []const u8,
buffer: []const u8,
};
pub const View = struct {
north: *Texture,
south: *Texture,
};
pub const Motives = struct {
room: i64, // Environment in later games
hunger: i64,
social: i64,
hygiene: i64,
fun: i64,
energy: i64,
bladder: i64,
};
pub const Skills = struct {
cooking: i64,
mechanical: i64,
charisma: i64,
body: i64,
logic: i64,
creativity: i64,
};
/// Open object format with similar
pub const OpenIff = struct {
name: []const u8,
description: []const u8,
version: i64,
catagory: []const u8,
/// Item to derive all logic from.
/// By defualt, this comes from the base game.
base: []const u8,
motives: *Motives,
skills: Skills,
views: *View,
// pub fn init(file: []const u8) OpenIff {
// }
};

View file

@ -1,6 +1,7 @@
const std = @import("std"); const std = @import("std");
const rl = @import("raylib"); const rl = @import("raylib");
const world = @import("world.zig"); const world = @import("world.zig");
const nso = @import("niotso.zig");
const dbg = std.debug; const dbg = std.debug;
@ -56,8 +57,8 @@ pub fn main() anyerror!void {
const logo = rl.Texture.init("resources/logo.png"); const logo = rl.Texture.init("resources/logo.png");
const splash = rl.Texture.init("resources/tsosplash.png"); const splash = rl.Texture.init("resources/tsosplash.png");
const table3 = rl.Texture.init("resources/items/dorms/table_3.png"); const table3 = rl.Texture.init("resources/items/dorm/table/table_1.png");
const table4 = rl.Texture.init("resources/items/dorms/table_4.png"); const table4 = rl.Texture.init("resources/items/dorm/table/table_2.png");
const city = rl.loadImage("resources/cities/city_0100/elevation.png"); const city = rl.loadImage("resources/cities/city_0100/elevation.png");
// const city_texture = rl.Texture.init("resources/cities/city_0100/vertexcolor.png"); // const city_texture = rl.Texture.init("resources/cities/city_0100/vertexcolor.png");
defer rl.unloadTexture(splash); defer rl.unloadTexture(splash);

9
src/niotso.zig Normal file
View file

@ -0,0 +1,9 @@
pub usingnamespace @cImport({
@cInclude("./formats/iff/iff.h");
@cInclude("./formats/iff/iffparser.h");
@cInclude("./formats/far/far.h");
@cInclude("./formats/far/config.h");
@cInclude("./formats/cur/read_cur.h");
@cInclude("./formats/utk/read_utk.h");
@cInclude("./formats/xa/read_xa.h");
});