|
@@ -1,11 +1,11 @@
|
|
|
/*
|
|
|
- Space Construct v0.3-dev
|
|
|
+ Space Construct v0.4-dev
|
|
|
Beanzilla@21:4/110 on FsxNet
|
|
|
Beanzilla@637:1/110 on HappyNet
|
|
|
*/
|
|
|
|
|
|
#define VERSION_MAJOR 0
|
|
|
-#define VERSION_MINOR 3
|
|
|
+#define VERSION_MINOR 4
|
|
|
#ifndef VERSION_TYPE
|
|
|
#define VERSION_TYPE "dev"
|
|
|
#endif
|
|
@@ -538,6 +538,8 @@ int display_all_players() {
|
|
|
}
|
|
|
if(total > 1) {
|
|
|
md_printf("`green`There are a total of `bright green`%d`green` players\r\n", total);
|
|
|
+ } else if(total == 0) {
|
|
|
+ md_printf("`green`There are a total of `bright green`%d`green` players\r\n", total);
|
|
|
} else {
|
|
|
md_printf("`green`There are a total of `bright green`%d`green` player\r\n", total);
|
|
|
}
|
|
@@ -546,9 +548,35 @@ int display_all_players() {
|
|
|
return total;
|
|
|
}
|
|
|
|
|
|
+int display_all_opponents(int us) {
|
|
|
+ sqlite3 *db;
|
|
|
+ sqlite3_stmt *stmt;
|
|
|
+ char sqlbuffer[1024];
|
|
|
+ int rc = sqlite3_open("spaceconstruct.db3", &db);
|
|
|
+ if(rc) { // Did we do a successful open?
|
|
|
+ dolog("E: failed opening database %s", sqlite3_errmsg(db));
|
|
|
+ sqlite3_close(db);
|
|
|
+ md_exit(1);
|
|
|
+ }
|
|
|
+ sqlite3_busy_timeout(db, 5000);
|
|
|
+ strcpy(sqlbuffer, "SELECT * from user ORDER BY experience DESC, nick DESC;");
|
|
|
+ sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
|
|
|
+ int total = 1;
|
|
|
+ md_printf("`bright green`___ Target List ___\r\n");
|
|
|
+ while(sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
+ if(total != us) {
|
|
|
+ md_printf("`bright black`(`bright white`%d`bright black`) `bright white`%s (%d)\r\n", total, sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 3));
|
|
|
+ }
|
|
|
+ total += 1;
|
|
|
+ }
|
|
|
+ total -= 1;
|
|
|
+ sqlite3_finalize(stmt);
|
|
|
+ sqlite3_close(db);
|
|
|
+ return total;
|
|
|
+}
|
|
|
+
|
|
|
user_inf build_menu(user_inf my) {
|
|
|
int done = 0;
|
|
|
- int didUp = 0;
|
|
|
char ch;
|
|
|
if(my.metal != 0) {
|
|
|
while(!done) {
|
|
@@ -562,7 +590,6 @@ user_inf build_menu(user_inf my) {
|
|
|
my.metal -= (4 * (my.guns + 1));
|
|
|
my.guns += 1;
|
|
|
my.hitpoints += 1;
|
|
|
- didUp = 1; // We need to save
|
|
|
md_printf("`bright green`Added a new gun!\r\n`white`");
|
|
|
paws();
|
|
|
} else {
|
|
@@ -576,7 +603,6 @@ user_inf build_menu(user_inf my) {
|
|
|
my.armors += 1;
|
|
|
my.hitpoints += 1;
|
|
|
my.armorpoints += 8;
|
|
|
- didUp = 1; // We need to save
|
|
|
md_printf("`bright green`Added a new armor!\r\n`white`");
|
|
|
paws();
|
|
|
} else {
|
|
@@ -594,7 +620,6 @@ user_inf build_menu(user_inf my) {
|
|
|
} else {
|
|
|
my.shieldpoints += 1;
|
|
|
}
|
|
|
- didUp = 1; // We need to save
|
|
|
md_printf("`bright green`Added a new shield!\r\n`white`");
|
|
|
paws();
|
|
|
} else {
|
|
@@ -612,7 +637,6 @@ user_inf build_menu(user_inf my) {
|
|
|
my.experience -= 25;
|
|
|
my.metal -= 25;
|
|
|
my.fuel += 5;
|
|
|
- didUp = 1;
|
|
|
md_printf("`bright green`Made 5 fuel using 25 experience and 25 metal!\r\n");
|
|
|
paws();
|
|
|
} else {
|
|
@@ -626,15 +650,285 @@ user_inf build_menu(user_inf my) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if(didUp) {
|
|
|
- update_player(my);
|
|
|
- }
|
|
|
+ update_player(my);
|
|
|
return my;
|
|
|
} else {
|
|
|
return my;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void pvp_menu(user_inf my, user_inf targ) {
|
|
|
+ int done = 0;
|
|
|
+ int playerWon = 0;
|
|
|
+ char ch;
|
|
|
+ // Extract temp values, assume offline player is at their best
|
|
|
+ int temp_hp = (targ.shields + targ.armors + targ.guns + 2);
|
|
|
+ int temp_ap = (targ.armors * 8);
|
|
|
+ int temp_sp = (targ.shields * 3);
|
|
|
+ int temp_su = 0;
|
|
|
+ int temp_dmg = (targ.guns + 1); // Add 1 additional point of damage for offline player
|
|
|
+ // Prep Combat values
|
|
|
+ int fire = 0; // Fire Guns
|
|
|
+ int flee = 0; // Run away
|
|
|
+ int regen = 0; // Shields
|
|
|
+ int temp = 0;
|
|
|
+ int temp1 = 0;
|
|
|
+ while(!done) {
|
|
|
+ // Process Shields up
|
|
|
+ if(temp_su != 0) {
|
|
|
+ temp_su -= 1;
|
|
|
+ }
|
|
|
+ if(my.shieldsup != 0) {
|
|
|
+ my.shieldsup -= 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Process Crew repairing hitpoints
|
|
|
+ if(temp_hp < (targ.shields + targ.armors + targ.guns + 2)) {
|
|
|
+ regen = rand() % 100;
|
|
|
+ if(regen >= 85) { // 15%, offline get a bonus 5% on repairing hull.
|
|
|
+ temp_hp += 1;
|
|
|
+ md_printf("`bright green`%s`green`'s crew repaired their hull for 1 point!\r\n", targ.nick);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(my.hitpoints < (my.shields + my.armors + my.guns + 2)) {
|
|
|
+ regen = rand() % 100;
|
|
|
+ if(regen >= 90) { // 10%
|
|
|
+ my.hitpoints += 1;
|
|
|
+ md_printf("`bright green`Your crew repaired your hull for 1 point!\r\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Process Shields regenerating and display player stats
|
|
|
+ if(temp_su == 0) {
|
|
|
+ if(temp_sp < (targ.shields * 3)) {
|
|
|
+ regen = rand() % 100;
|
|
|
+ if(regen >= 65) { // 35%, offline bonus
|
|
|
+ temp_sp += targ.shields;
|
|
|
+ if(temp_sp > (targ.shields * 3)) {
|
|
|
+ temp_sp = (targ.shields * 3);
|
|
|
+ }
|
|
|
+ md_printf("`bright green`%s`green`'s shields regenerate %d points!\r\n", targ.nick, targ.shields);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ md_printf("`bright white`%s has `bright blue`%d`bright white` shields, %d armor and %d hitpoints left\r\n", targ.nick, temp_sp, temp_ap, temp_hp);
|
|
|
+ } else {
|
|
|
+ if(temp_sp < (targ.shields * 3)) {
|
|
|
+ regen = rand() % 100;
|
|
|
+ if(regen >= 65) { // 35%, offline bonus
|
|
|
+ temp_sp += 1;
|
|
|
+ if(temp_sp > (targ.shields * 3)) {
|
|
|
+ temp_sp = (targ.shields * 3);
|
|
|
+ }
|
|
|
+ md_printf("`bright green`%s`green`'s shields regenerate 1 points!\r\n", targ.nick);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ md_printf("`bright white`%s has `blue`%d`bright white` shields, %d armor and %d hitpoints left\r\n", targ.nick, temp_sp, temp_ap, temp_hp);
|
|
|
+ }
|
|
|
+ // Online Players Shields
|
|
|
+ if(my.shieldsup == 0) {
|
|
|
+ if(my.shieldpoints < (my.shields * 3)) {
|
|
|
+ regen = rand() % 100;
|
|
|
+ if(regen >= 70) { // 30%
|
|
|
+ my.shieldpoints += my.shields;
|
|
|
+ if(my.shieldpoints > (my.shields * 3)) {
|
|
|
+ my.shieldpoints = (my.shields * 3);
|
|
|
+ }
|
|
|
+ md_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ md_printf("`bright white`Your ship has `bright blue`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.shieldpoints, my.armorpoints, my.hitpoints);
|
|
|
+ } else {
|
|
|
+ if(my.shieldpoints < (my.shields * 3)) {
|
|
|
+ regen = rand() % 100;
|
|
|
+ if(regen >= 70) { // 30%
|
|
|
+ my.shieldpoints += 1;
|
|
|
+ if(my.shieldpoints > (my.shields * 3)) {
|
|
|
+ my.shieldpoints = (my.shields * 3);
|
|
|
+ }
|
|
|
+ md_printf("`bright green`Your shields regenerate 1 points!\r\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ md_printf("`bright white`Your ship has `blue`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.shieldpoints, my.armorpoints, my.hitpoints);
|
|
|
+ }
|
|
|
+ // Form combat menu (Not allowing online to repair since offline can't really repair either)
|
|
|
+ md_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n");
|
|
|
+ md_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n");
|
|
|
+ // Online Players action
|
|
|
+ ch = md_get_answer("AaFf\r");
|
|
|
+ switch(tolower(ch)) {
|
|
|
+ case '\r':
|
|
|
+ case 'a':
|
|
|
+ fire = rand() % 100;
|
|
|
+ temp = my.guns;
|
|
|
+ if(fire >= 50) {
|
|
|
+ // Proccess online dealing damage to offline
|
|
|
+ if(temp_su == 0 && temp_sp != 0) {
|
|
|
+ if(temp >= temp_sp) {
|
|
|
+ temp_su = (targ.shields + 2);
|
|
|
+ temp -= temp_sp;
|
|
|
+ temp_sp = 0;
|
|
|
+ md_printf("`bright blue`%s's shields absorbed %d damage and went offline!\r\n", targ.nick, temp_dmg);
|
|
|
+ } else {
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= temp_sp;
|
|
|
+ temp_sp -= temp1;
|
|
|
+ md_printf("`bright blue`%s's shields absorbed %d damage!\r\n", targ.nick, temp1);
|
|
|
+ temp1 = 0;
|
|
|
+ }
|
|
|
+ } // Armor
|
|
|
+ if(temp > 0) {
|
|
|
+ if(temp_ap != 0) {
|
|
|
+ if(temp >= temp_ap) {
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= temp_ap;
|
|
|
+ temp_ap = 0;
|
|
|
+ md_printf("`yellow`%s's armor took %d damage and broke!\r\n`white`", targ.nick, temp1);
|
|
|
+ temp1 = 0;
|
|
|
+ } else {
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= temp_ap;
|
|
|
+ temp_ap -= temp1;
|
|
|
+ md_printf("`bright yellow`%s's armor took %d damage!\r\n`white`", targ.nick, temp1);
|
|
|
+ temp1 = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } // Offline's hitpoints!
|
|
|
+ if(temp > 0) {
|
|
|
+ if(temp < temp_hp) {
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= temp_hp; // should be 0
|
|
|
+ temp_hp -= temp1;
|
|
|
+ md_printf("`bright red`%s's hull took %d damage!\r\n", targ.nick, temp1);
|
|
|
+ temp1 = 0;
|
|
|
+ } else {
|
|
|
+ playerWon = 1; // Online won over Offline!
|
|
|
+ done = 1;
|
|
|
+ md_printf("`red`%s's hull took %d damage and broke!\r\n", targ.nick, temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else { // Online missed
|
|
|
+ md_printf("`white`You missed!\r\n");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'f':
|
|
|
+ flee = rand() % 100;
|
|
|
+ if(flee >= 80) { // 20% chance the online flees
|
|
|
+ playerWon = 3; // Online ran away from Offline
|
|
|
+ done = 1;
|
|
|
+ md_printf("`bright green`You ran away from %s!\r\n", targ.nick);
|
|
|
+ } else {
|
|
|
+ md_printf("`bright red`%s found you!\r\n", targ.nick);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ } // Now for Offline to attack
|
|
|
+ if(!playerWon) {
|
|
|
+ temp = temp_dmg;
|
|
|
+ fire = rand() % 100;
|
|
|
+ if(fire >= 45) { // 55%, 5% bonus for offline
|
|
|
+ if(my.shieldsup == 0 && my.shieldpoints != 0) {
|
|
|
+ if(temp >= my.shieldpoints) {
|
|
|
+ // Damage will lower shields!
|
|
|
+ my.shieldsup = (my.shields + 2);
|
|
|
+ temp -= my.shieldpoints;
|
|
|
+ my.shieldpoints = 0;
|
|
|
+ md_printf("`bright blue`Shields absorbed %d damage and went offline!\r\n`white`", temp_dmg);
|
|
|
+ } else {
|
|
|
+ // Damage to shields but not lower them
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= my.shieldpoints;
|
|
|
+ my.shieldpoints -= temp1;
|
|
|
+ temp1 = 0;
|
|
|
+ md_printf("`bright blue`Shields absorbed %d damage!\r\n`white`", temp_dmg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // shields now armor
|
|
|
+ if(temp > 0) {
|
|
|
+ if(my.armorpoints != 0) {
|
|
|
+ // We do have armor
|
|
|
+ if(temp >= my.armorpoints) {
|
|
|
+ // Damage will destroy armor!
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= my.armorpoints;
|
|
|
+ my.armorpoints = 0;
|
|
|
+ md_printf("`yellow`Armor took %d damage and broke!\r\n`white`", temp1);
|
|
|
+ temp1 = 0;
|
|
|
+ } else {
|
|
|
+ // Nope armor is good
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= my.armorpoints;
|
|
|
+ my.armorpoints -= temp1;
|
|
|
+ md_printf("`bright yellow`Armor took %d damage!\r\n`white`", temp1);
|
|
|
+ temp1 = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // armor now hull
|
|
|
+ if(temp > 0) {
|
|
|
+ if(temp < my.hitpoints) {
|
|
|
+ temp1 = temp;
|
|
|
+ temp -= my.hitpoints; // should be 0
|
|
|
+ my.hitpoints -= temp1;
|
|
|
+ md_printf("`bright red`Hull took %d damage!\r\n", temp1);
|
|
|
+ } else {
|
|
|
+ playerWon = 2; // offline won over online!
|
|
|
+ done = 1;
|
|
|
+ my.hitpoints = 0;
|
|
|
+ md_printf("`red`Hull took %d damage and broke!\r\n", temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Winning Move?
|
|
|
+ if(playerWon) {
|
|
|
+ switch(playerWon) {
|
|
|
+ case 1: // Online won over offline
|
|
|
+ if(targ.experience) { // Just incase someone is dumb and attacked a player with no exp
|
|
|
+ my.experience += (targ.experience / 2); // Gain half exp from offline
|
|
|
+ targ.experience -= (targ.experience / 2); // Process offline giving online that exp
|
|
|
+ }
|
|
|
+ if(targ.metal) {
|
|
|
+ my.metal += (targ.metal / 2);
|
|
|
+ targ.metal -= (targ.metal / 2);
|
|
|
+ }
|
|
|
+ my.fuel -= 4;
|
|
|
+ if(my.fuel < 0) {
|
|
|
+ my.fuel = 0;
|
|
|
+ }
|
|
|
+ md_printf("`bright green`Congrats on defeating %s!\r\n`white`", targ.nick);
|
|
|
+ break;
|
|
|
+ case 2: // Offline won over online!
|
|
|
+ if(my.experience) {
|
|
|
+ targ.experience += (my.experience / 2);
|
|
|
+ my.experience -= (my.experience / 2);
|
|
|
+ }
|
|
|
+ if(my.metal) {
|
|
|
+ targ.metal += (my.metal / 2);
|
|
|
+ my.metal -= (my.metal / 2);
|
|
|
+ }
|
|
|
+ my.fuel -= 4;
|
|
|
+ if(my.fuel < 0) {
|
|
|
+ my.fuel = 0;
|
|
|
+ }
|
|
|
+ md_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n");
|
|
|
+ my.hitpoints = 4;
|
|
|
+ my.armorpoints = 8;
|
|
|
+ my.shieldpoints = 0;
|
|
|
+ my.shieldsup = 0;
|
|
|
+ my.armors = 1;
|
|
|
+ my.shields = 0;
|
|
|
+ my.guns = 1;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ my.fuel -= 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // DOne
|
|
|
+ update_player(targ);
|
|
|
+ update_player(my);
|
|
|
+}
|
|
|
+
|
|
|
user_inf combat_menu(user_inf my, int targ_hp, int targ_dmg, int asteroid) {
|
|
|
int done = 0;
|
|
|
int playerWon = 0; // Did the player win? (1 = Yes, 2 = No, 3 = Flee)
|
|
@@ -675,7 +969,7 @@ user_inf combat_menu(user_inf my, int targ_hp, int targ_dmg, int asteroid) {
|
|
|
if(my.shieldpoints < (my.shields * 3)) {
|
|
|
regen = rand() % 100;
|
|
|
if(regen >= 70) {
|
|
|
- my.shieldpoints += (my.shields + 1);
|
|
|
+ my.shieldpoints += my.shields;
|
|
|
if(my.shieldpoints > (my.shields * 3)) {
|
|
|
my.shieldpoints = (my.shields * 3);
|
|
|
}
|
|
@@ -1103,7 +1397,47 @@ void play_game() {
|
|
|
}
|
|
|
break;
|
|
|
case 'h':
|
|
|
- md_printf("`bright white`Comming v0.4-dev\r\n");
|
|
|
+ if(myself.fuel >= 4) {
|
|
|
+ int targs = display_all_opponents(myself.uid);
|
|
|
+ int targg = 1;
|
|
|
+ int done2 = 0;
|
|
|
+ if(targg == myself.uid) {
|
|
|
+ targg += 1;
|
|
|
+ }
|
|
|
+ while(!done2) {
|
|
|
+ md_printf("`bright red`Targetting: %d\r\n", targg);
|
|
|
+ if(yesNo()) {
|
|
|
+ done2 = 1;
|
|
|
+ } else if(targg < targs){
|
|
|
+ targg += 1;
|
|
|
+ } else {
|
|
|
+ done2 = 1;
|
|
|
+ md_printf("`bright red`ABORTED!\r\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ user_inf targ = load_player(targg);
|
|
|
+ if(targ.uid != 0) {
|
|
|
+ // I need to add some limits in here else someone could attack weaker players!
|
|
|
+ int proceed = 0;
|
|
|
+ int temp = targ.experience + 1000; // Prevent the person from selecting a player that is higher than them
|
|
|
+ int temp1 = targ.experience - 500; // Prevent the person from selecting a player that is lower than them
|
|
|
+ if(temp1 > 0) {
|
|
|
+ temp1 = 0;
|
|
|
+ }
|
|
|
+ if(temp > myself.experience && temp1 < myself.experience) {
|
|
|
+ proceed = 1;
|
|
|
+ }
|
|
|
+ if(proceed) {
|
|
|
+ pvp_menu(myself, targ);
|
|
|
+ } else {
|
|
|
+ md_printf("`bright white`Please select a opponent within your range of expertise!\r\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ md_printf("`bright white`You need 4 fuel to fight another player!\r\n`white`");
|
|
|
+ }
|
|
|
break;
|
|
|
case 'b':
|
|
|
if(myself.metal != 0) {
|