This commit is contained in:
Masashi 2025-12-18 22:04:23 +05:30
commit de14cb8f14
4 changed files with 32 additions and 5 deletions

Binary file not shown.

View file

@ -176,9 +176,9 @@ static float fbm_noise(float x, float y, int octaves) {
}
float get_terrain_height(float x, float z) {
float height = fbm_noise(x * 0.03f, z * 0.03f, 4);
float height = fbm_noise(x * 0.05f, z * 0.05f, 2);
height += fbm_noise(x * 0.01f, z * 0.01f, 2) * 1.5f;
return height * 6.0f + 2.0f;
return height * 4.0f + 2.0f;
}
#define TERRAIN_SIZE 256

Binary file not shown.

View file

@ -2,6 +2,7 @@
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -142,9 +143,9 @@ static float fbm_noise(float x, float y, int octaves) {
}
float get_terrain_height(float x, float z) {
float height = fbm_noise(x * 0.03f, z * 0.03f, 4);
float height = fbm_noise(x * 0.05f, z * 0.05f, 2);
height += fbm_noise(x * 0.01f, z * 0.01f, 2) * 1.5f;
return height * 5.0f + 2.0f;
return height * 4.0f + 2.0f;
}
#define TERRAIN_SIZE 256
@ -550,6 +551,8 @@ int main(void) {
WSAStartup(MAKEWORD(2, 2), &wsa);
#endif
srand((unsigned)time(NULL));
ode_init_world();
int sock = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@ -571,7 +574,7 @@ int main(void) {
}
Player players[MAX_PLAYERS] = {0};
uint32_t serverTick = 0, itemsTickDiv = 0;
uint32_t serverTick = 0, itemsTickDiv = 0, spawnCounter = 0;
printf("Server listening UDP %d\n", SERVER_PORT);
double nextTick = now_seconds();
@ -791,6 +794,7 @@ int main(void) {
if (t >= nextTick) {
nextTick += DT;
serverTick++;
spawnCounter++;
dSpaceCollide(gSpace, 0, &nearCallback);
dWorldQuickStep(gWorld, DT);
@ -825,6 +829,29 @@ int main(void) {
}
}
// Spawn random items every 30 seconds (900 ticks at 30Hz)
if (spawnCounter >= 900) {
spawnCounter = 0;
for (int i = 0; i < 2; i++) {
int type_idx = rand() % 3;
uint8_t type;
int qty;
if (type_idx == 0) {
type = ITEM_MEDKIT;
qty = 1;
} else if (type_idx == 1) {
type = ITEM_AMMO_PISTOL;
qty = 10 + (rand() % 6);
} else {
type = ITEM_AMMO_RIFLE;
qty = 20 + (rand() % 11);
}
float x = (float)(rand() % 200 - 100);
float z = (float)(rand() % 200 - 100);
item_spawn(type, qty, x, z);
}
}
for (int i = 0; i < MAX_PLAYERS; i++) {
Player *p = &players[i];
if (!p->inUse || !p->alive)