mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-04 13:47:04 -04:00
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:
parent
00255a6c17
commit
a1cdd92c3f
31 changed files with 259 additions and 33 deletions
120
library/extra/d20/d20.c
Normal file
120
library/extra/d20/d20.c
Normal 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
22
library/extra/d20/d20.h
Normal 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
|
|
@ -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"
|
|
@ -1,10 +1 @@
|
|||
--------------------------------|----------------------------------------------------------------
|
||||
| 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/> |
|
||||
-------------------------------------------------------------------------------------------------
|
||||
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.
|
Loading…
Add table
Add a link
Reference in a new issue