Created
August 14, 2017 01:55
-
-
Save winny-/7181ddf4ea032458e52e74e4552785e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require db/base | |
db/postgresql | |
db/util/datetime | |
db/util/geometry) | |
(struct planet (id location conqueror-id name mine-limit) | |
#:transparent) | |
(struct ship (id player-id fleet-id name | |
last-move-tic last-action-tic last-living-tic | |
current-health max-health current-fuel max-fuel | |
attack defense engineering prospecting | |
range | |
location destination | |
speed target-speed max-speed | |
direction target-direction | |
action action-target-id | |
repair-priority) | |
#:transparent) | |
(define user "winny") | |
(define pgc | |
(postgresql-connect #:user user | |
#:password password | |
#:database "schemaverse" | |
#:server "db.schemaverse.com" | |
#:ssl 'yes)) | |
(define (my-player) | |
(query-row pgc "SELECT * FROM my_player")) | |
(define (fuel) | |
(query-value pgc "SELECT fuel_reserve FROM my_player")) | |
(define (balance) | |
(query-value pgc "SELECT balance FROM my_player")) | |
(define (player-id) | |
(query-value pgc "SELECT get_player_id($1)" user)) | |
(define (conquered-planets) | |
(map (compose (curry apply planet) vector->list) | |
(query-rows pgc "SELECT id, location, conqueror_id, name, mine_limit FROM planets WHERE conqueror_id=get_player_id($1)" user))) | |
(define (ships) | |
(map (compose (curry apply ship) vector->list) | |
(query-rows pgc "SELECT ID,PLAYER_ID,FLEET_ID,NAME,LAST_MOVE_TIC,LAST_ACTION_TIC,LAST_LIVING_TIC,CURRENT_HEALTH,MAX_HEALTH,CURRENT_FUEL,MAX_FUEL,ATTACK,DEFENSE,ENGINEERING,PROSPECTING,RANGE,LOCATION,DESTINATION,SPEED,TARGET_SPEED,MAX_SPEED,DIRECTION,TARGET_DIRECTION,ACTION,ACTION_TARGET_ID,REPAIR_PRIORITY FROM my_ships"))) | |
(define default-skills | |
(hash | |
'attack 5 | |
'defense 5 | |
'engineering 5 | |
'prospecting 5)) | |
(define (create-ship name planet [skills default-skills]) | |
(apply ship | |
(vector->list | |
(query-row pgc "INSERT INTO my_ships(name, location, attack, defense, engineering, prospecting) VALUES($1,$2,$3,$4,$5, $6) RETURNING ID,PLAYER_ID,FLEET_ID,NAME,LAST_MOVE_TIC,LAST_ACTION_TIC,LAST_LIVING_TIC,CURRENT_HEALTH,MAX_HEALTH,CURRENT_FUEL,MAX_FUEL,ATTACK,DEFENSE,ENGINEERING,PROSPECTING,RANGE,LOCATION,DESTINATION,SPEED,TARGET_SPEED,MAX_SPEED,DIRECTION,TARGET_DIRECTION,ACTION,ACTION_TARGET_ID,REPAIR_PRIORITY" | |
name | |
(planet-location planet) | |
(hash-ref skills 'attack) | |
(hash-ref skills 'defense) | |
(hash-ref skills 'engineering) | |
(hash-ref skills 'prospecting))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment