/*======================================================================* * C65 implementation of Hammarubi * *======================================================================*/ #version $50 #reserve 6 #copyright "King.cmd Copyright 1995 K-Products" #address $7000 #include runtime.h #include bbs_pro.h #define ATASCII 0 #define ASCII 1 #define DISK2 2 #define FOREVER 1 #define MAX_YEARS 40 float population, grain, land, price, born, died, came, starved, u_score, tot_born, tot_starved, fp1, fp2, F_0, F_1, F_2, F_4, F_5, F_p75, F_100; byte year, first_play; char score_fn [30]; char score_buff [200]; /* 10 entries * 8 bytes each */ main() { itof(0, F_0); itof(1, F_1); itof(2, F_2); itof(4, F_4); itof(5, F_5); itof(100,F_100); strtof(".75", F_p75); strcpy (score_fn, "Dx:>PRO>DATA>KINGDOM.DAT"); score_fn [2] = s_datadr; while ( 1 ) { case (main_menu()) { 'R' : play_kingdom(); 'H' : view_hall(); 'X' : return; } if (over_time_limit()) return; } } main_menu() { char ch; echo(125); cr_lf(); if (trans = ATASCII) { centere(control(" qrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrre")); centere( " | Kingdom v5.0 |" ); centere( " | (c) 1995 K-Products |" ); centere(control(" arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrd")); centere( " | Can you rule Prometheus? |" ); centere(control(" zrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrc")); } else { centere(" +----------------------------------+"); centere(" ! Kingdom v5.0 !"); centere(" ! (c) 1995 K-Products !"); centere(" +----------------------------------+"); centere(" ! Can you rule Prometheus? !"); centere(" +----------------------------------+"); } cr_lf(); cr_lf(); centere(" [R] Rule the Kingdom!"); cr_lf(); centere(" [H] Kingdom Hall of Fame"); cr_lf(); centere(" [X] Exit the Kingdom"); cr_lf(); center (" Option => "); do { ch = upcase (get_key()); } while (ch != 'R' && ch != 'H' && ch != 'X'); echo(ch); cr_lf(); return (ch); } play_kingdom() { init_kingdom(); while (cont() = 'Y' && year <= MAX_YEARS && fcompare(population,F_0)==1) { calc_food(); calc_plague(); calc_rats(); buy_land(); crops(); fdiv (fp1, population, F_2); if (fcompare(starved, fp1) == 1) { revolt(); break; } statprint(); if (over_time_limit()) /* exit gracefully if they */ year = MAX_YEARS + 1; /* go over time limit.. */ } if (year > MAX_YEARS) { cr_lf(); echose ("You've served the maximum term!"); any_key(); } score(); view_hall(); cr_lf(); } center (char *s) { if (u_vw == 80) echos(" "); echos (s); } centere(char *s) { center (s); cr_lf(); } init_kingdom() { first_play = 1; year = 1; itof (100, population); itof (500, grain); itof (100, land); itof (10, price); itof (0, starved); itof (20, born); itof (20, tot_born); itof (0, tot_starved); echo(125); cr_lf(); echos (" You have been chosen by the people\"); echose("of Prometheus to lead them into the"); echose("Promised Land."); cr_lf(); echos (" You will have 40 years in which to\"); echose("build Prometheus into a major city."); echose("Many before you have failed..."); cr_lf(); any_key(); } cont() { char c; cr_lf(); if (first_play == 1) { first_play = 0; return('Y'); } echos ("Continue your reign? "); return (y_or_n()); } revolt() { cr_lf(); cr_lf(); echos ("A dark night has fallen over your\"); echose("Kingdom. Under your poor planning,"); echos ("over 1/2 of Prometheus's people have\"); echose("starved. The poor, feeble remainder"); echos ("of the population have taken control\"); echose("of your land, and were last heard"); echose("shouting:"); cr_lf(); echos ("'Death to "); echos (u_handle); echose("!'"); cr_lf(); any_key(); } any_key() { echos ("Press any key..."); get_key(); } calc_plague() { if (clock() > 240) { cr_lf(); cr_lf(); echose(inverse(" A disastrous plague strikes,")); echose(inverse("killing half of your kingdom!")); cr_lf(); fdiv (population, population, F_2); } } calc_rats() { int c; if (fcompare (grain, F_1) == 2) return; c = clock() >> 5; if (c < 2) return; cr_lf(); cr_lf(); echose(">> A fire in your grainary has"); echos (">> destroyed 1/"); echoc (c); echose(" of your grain!"); cr_lf(); itof (c, fp1); fdiv (fp2, grain, fp1); fsub (grain, grain, fp2); } statprint() { int i; cr_lf(); echose("Another year is gone, your Lordship"); cr_lf(); echos ("Press a key to see the statistics.."); get_key(); echo(125); cr_lf(); echos ("In year "); echoc (year); echose(" of your reign:"); bar(); fsub (population, population, starved); if (negative (population)) fzero (population); fadd (tot_starved, tot_starved, starved); i = clock() & $3f + 15; itof(i, fp1); fmult (fp1, population, fp1); fdiv (born, fp1, F_100); fadd (population, population, born); fadd (tot_born, tot_born, born); dotpoint(); echofl (born); echose (" babies were born."); dotpoint(); echofl (starved); echose(" people starved."); fzero (starved); ++year; dotpoint(); echos("New population: "); echofl(population); echose("."); dotpoint(); echos("Land holdings : "); echofl(land); echose(" acres."); dotpoint(); echos("Grain owned : "); echofl(grain); echose(" bushels."); bar(); calc_score(); echos("Your current score: "); echofl(u_score); cr_lf(); } echofl (float fp) { char temp [40]; byte x; ftostr (fp, temp); for (x = 1; x <= length(temp); ++x) { if (temp [x] = '.') return else echo (temp [x]); } } echofe (float fp) { echofl (fp); cr_lf(); } dotpoint() { if (trans == ATASCII) echo (20); else echo ('-'); echo (' '); } bar() { if (trans == ATASCII) echose(control("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")); else echose("------------------------------------"); } buy_land() { char inkey; float c, amount,canbuy, temp; if (fcompare (grain, F_1) == 2) return; inkey = clock() & 7; if (inkey = 0) inkey = 1; itof (inkey, c); inkey = 0; cr_lf(); cr_lf(); echos("Land is selling for "); echofl(c); echose(" bu./acre."); cr_lf(); echos("[B]uy, [S]ell, or [I]gnore? "); do { inkey = upcase( get_key() ); } while (inkey != 'B' && inkey != 'S' && inkey != 'I'); echo(inkey); cr_lf(); if (inkey == 'B') { fdiv (canbuy, grain, c); do { cr_lf(); echos ("You can afford "); echofl(canbuy); echose(" acres."); cr_lf(); echos ("How many would you like to buy? "); get_float (amount); } while (fcompare (amount, canbuy) == 1); cr_lf(); fmult(temp, amount, c); fsub (grain, grain, temp); fadd (land, land, amount); return; } if (inkey == 'S') { do { cr_lf(); echos ("You have "); echofl(land); echose(" acres of land."); cr_lf(); echos ("How many acres will you sell? "); get_float (amount); } while (fcompare (amount, land) == 1); fmult (temp, amount, c); fadd (grain, grain, temp); fsub (land, land, amount); return; } } calc_food() { float needed,given,temp; fmult (needed, population, F_p75); if (fcompare (grain, F_1) == 2) { cr_lf(); echose("You have no grain left!"); fmove (starved, population); return; } cr_lf(); echos ("Your Lordship, the people are in\"); echos ("dire need of "); echofl (needed); echose (" bushels of grain."); do { cr_lf(); echos ("You have "); echofl(grain); echose(" bushels stored away."); cr_lf(); echose("How many bushels shall I give them? "); echos ("-> "); get_float (given); } while (fcompare (given, grain) == 1); fsub (grain, grain, given); fmult (temp, population, F_p75); fsub (temp, temp, given); if (negative (temp)) starved = 0; else fmult (starved, temp, F_p75); } crops() { float planted, canplant, total,cantill, temp; int yield; if (fcompare (grain, F_1) == 2) return; fmult (canplant, grain, F_2); if (fcompare (canplant, land) == 1) fmove (canplant, land); cr_lf(); echos ("You have "); echofl(land); echose(" acres."); do { echos ("You can plant up to "); echofl(canplant); echose(" acres."); cr_lf(); echose("How many shall we plant, Sir? "); get_float (planted); } while (fcompare (planted, canplant) == 1); yield = clock() & 7; if (yield == 0) yield = 1; fmult (cantill, population, F_5); if (fcompare (cantill, planted) == 2) { cr_lf(); echos ("Lack of workers means you only manage\"); echos ("to plant "); echofl(cantill); echose(" acres."); fmove (planted, cantill); } fdiv (temp, planted, F_2); fsub (grain, grain, temp); itof (yield, fp1); fmult(total, planted, fp1); cr_lf(); echos("Your land produced "); echoc(yield); echos (" bu./acre\"); echos("for a total of "); echofl(total); echose(" bushels."); fadd (grain, grain, total); } get_float (float fp) { char temp [12]; get_string (temp, 10, 1, 0); strtof (temp, fp); } /*======================================================================* * See if they cracked the top scorer.. * *======================================================================*/ score() { int x, y; int *bp; echo(125); cr_lf(); echos("Checking top scorer list..."); MIOsuspend(); if (open (DISK2, score_fn, 4, 0) != OK) /* file not there */ zero (score_buff, 80); /* so create it */ else blockread (DISK2, score_buff, 80); /* else read it */ close(DISK2); calc_score(); for (x=0; x < 10; ++x) { bp = x*8 + score_buff; fmove (fp1, bp+2); /* get float number */ if (fcompare(u_score,fp1)==1 || fcompare(u_score,fp1)==0) { if (x < 9) { for (y=79; y > x*8; --y) /* move scores down */ score_buff[y] = score_buff[y-8]; } *bp = usernum; fmove (bp+2, u_score); break; } } if (open (DISK2, score_fn, 8, 0) == OK) blockwrite (DISK2, score_buff, 80); close (DISK2); MIOresume(); } view_hall() { int tbytes, user, x, y; byte rc; int *bp; echo(125); cr_lf(); if (trans = ATASCII) { centere(control(" qrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrre")); centere( " | Kingdom |" ); centere( " | (c) 1995 K-Products |" ); centere(control(" arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrd")); centere( " | The Kingdom Hall of Fame |" ); centere(control(" zrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrc")); } else { centere(" +----------------------------------+"); centere(" ! Kingdom !"); centere(" ! (c) 1995 K-Products !"); centere(" +----------------------------------+"); centere(" ! The Kingdom Hall of Fame !"); centere(" +----------------------------------+"); } cr_lf(); MIOsuspend(); file_stat (score_fn); if (open (DISK2, score_fn, 4, 0) != OK) { MIOresume(); echose ("Unable to find data file!"); cr_lf(); any_key(); return; } tbytes = blockread (DISK2, score_buff, 80); close (DISK2); MIOresume(); if (tbytes != 80) { echose ("Unable to find read file!"); cr_lf(); any_key(); return; } centere (" User Name Score"); centere (" -------------------- -----"); MIOsuspend(); if (open_ulog() > 127) { MIOresume(); echose ("Unable to open USERLOG!"); cr_lf(); any_key(); return; } for (x=0; x < 10; ++x) { MIOsuspend(); bp = x*8 + score_buff; user = *bp; if (user > 0 && read_user (user) == OK) { MIOresume(); center (" "); echos (t_handle); for (y=length(t_handle); y < 23; ++y) echo(' '); fmove (u_score, bp+2); echofl (u_score); cr_lf(); } } MIOsuspend(); close_ulog(); MIOresume(); cr_lf(); any_key(); } calc_score() { float i1,i2,i3; char temp [40]; int x; fzero(u_score); fdiv (i1, land, 10); fdiv (i2, grain, 10); fdiv (i3, population, 10); fadd (u_score, u_score, i1); fadd (u_score, u_score, i2); fadd (u_score, u_score, i3); fadd (u_score, u_score, tot_born); fsub (u_score, u_score, tot_starved); if (negative (u_score)) u_score = 0; ftostr(u_score, temp); /* convert to string */ for (x=1; x<=length(temp);++x) { /* remove '.' if there */ if (temp[x] = '.') { temp[0] = x-1; break; } } strtof(temp, u_score); } over_time_limit() { if (min_conn > u_tlcall) return(1); else if (min_conn+u_mintoday > u_tlday) return(1); return(0); } clock() { #asm { lda 20 ldx #0 rts } }