4.2 KiB
4.2 KiB
Network Engineering Simulator - Pseudocode Specification
// GLOBAL STATE
world: 3D voxel space (solid/air)
devices: List<Device> = []
connections: List<Connection> = []
credits: int = 0
technicians: List<Bot> = [free_starter_bot]
// DEVICE TYPES
struct Framework:
id: IP_address (A.B.C.D where 0≤A,B,C,D≤3)
packet_gen_rate: float // packets/sec
struct Router:
ports: [Device|null, Device|null]
struct Hub:
ports: [Device|null, Device|null, Device|null]
rotation: enum{ CLOCKWISE, COUNTERCLOCKWISE }
active_port: int (0,1,2)
// ECONOMY
shop_items = {
"cable": {cost:1, qty:20},
"router": {cost:2, qty:1},
"hub": {cost:10, qty:1},
"technician": {cost:10000, qty:1},
"drill_fuel": {cost:20, qty:100}
}
// CONSTRUCTION SYSTEM
function toggle_networking_mode(enabled):
if enabled:
use_technician_bots()
else:
free_instant_build()
function place_device(type, position):
if networking_mode:
assign_to_technician(type, position)
else:
spawn_device(type, position)
function drill_volume(start, end):
blocks = calculate_blocks(start, end)
if networking_mode:
consume_fuel(blocks)
technician.drill(start, end)
else:
instant_clear_volume(start, end)
function create_connection(devA, devB):
distance = distance(devA.pos, devB.pos)
cable_cost = ceil(distance / 3.0)
if credits < cable_cost: return FAIL
// Ray collision check (ignore shared planes)
if has_collision(devA.pos, devB.pos): return FAIL
credits -= cable_cost
connection = new Connection(devA, devB, cable_cost)
connections.add(connection)
// HUB MANAGEMENT
function connect_to_hub(device, hub, port_index):
hub.ports[port_index] = device
create_connection(device, hub)
function rotate_hubs(): // Called every second
for hub in all_hubs:
if hub.rotation == CLOCKWISE:
hub.active_port = (hub.active_port + 1) % 3
else:
hub.active_port = (hub.active_port - 1) % 3
// PACKET SYSTEM
function generate_packets():
for framework in all_frameworks:
dest = random_valid_ip()
spawn_packet(framework, dest)
function route_packets(): // Called every second
for packet in all_packets:
current = packet.current_device
next = get_next_hop(current, packet.dest)
packet.hops += connection_cost(current, next)
packet.move_to(next)
// ECONOMY & UI
function free_money_button():
if credits < 10:
credits += 100
function calculate_earnings():
for packet in delivered_packets:
credits += BASE_REWARD * packet.hops
// MAIN GAME LOOP
every_frame:
handle_player_input()
render_world()
every_second:
generate_packets()
route_packets()
calculate_earnings()
rotate_hubs()
Key Constants
BASE_REWARD = 1.0 // Credit per hop
IP_RANGE = [0,1,2,3] // Valid IP digits
Simplified Device Behavior
Router:
Input → Output (direct passthrough)
Hub:
Always routes to active_port
Port rotation occurs AFTER packet transfer
Connection:
Cost = ceil(distance/3)
Each connection adds 'cost' hops to packets
Input Handling Pseudocode
on_mouse_click:
if in_build_mode:
place_device(selected_type, world_position)
if in_drill_mode:
drill_volume(selection_start, selection_end)
if in_connect_mode:
create_connection(selected_device1, selected_device2)
if ui_element_clicked("free_money"):
free_money_button()
Collision Detection
function has_collision(posA, posB):
// Ignore collisions on shared planes
if same_x_plane(posA, posB): ignore YZ
if same_y_plane(posA, posB): ignore XZ
if same_z_plane(posA, posB): ignore XY
return raycast(posA, posB) hits non-device solid
This specification contains all mechanics in condensed pseudocode format, covering:
- IP-based routing (0-3 digits)
- Cable cost/distance formula
- 1-second packet synchronization
- Networking mode toggle
- Collision-aware connections
- Hop-based economy
- Free money condition
- Device placement logic
- Hub rotation system