aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/army/new army 0.txtbin0 -> 21528 bytes
-rw-r--r--build/army/steaks.txt (renamed from build/army/army.txt)bin21528 -> 21528 bytes
-rw-r--r--build/content/templates/default.txt6
-rw-r--r--build/test.exebin776738 -> 780777 bytes
-rw-r--r--design/notes.txt8
-rw-r--r--gst/info.c11
-rw-r--r--gst/info.h2
-rw-r--r--hud/hud.c180
-rw-r--r--hud/hud.h7
-rw-r--r--hud/hud_views.c12
-rw-r--r--main.c1
11 files changed, 177 insertions, 50 deletions
diff --git a/build/army/new army 0.txt b/build/army/new army 0.txt
new file mode 100644
index 0000000..6c15580
--- /dev/null
+++ b/build/army/new army 0.txt
Binary files differ
diff --git a/build/army/army.txt b/build/army/steaks.txt
index 7e40c14..a6d9795 100644
--- a/build/army/army.txt
+++ b/build/army/steaks.txt
Binary files differ
diff --git a/build/content/templates/default.txt b/build/content/templates/default.txt
index 9b68936..dece5bd 100644
--- a/build/content/templates/default.txt
+++ b/build/content/templates/default.txt
@@ -1,6 +1,6 @@
[
{
- "name": "tank",
+ "name": "medium rare",
"chassis": "0",
"brain": "0",
"battery": "0",
@@ -10,7 +10,7 @@
"levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
- "name": "tank2",
+ "name": "raw",
"chassis": "5",
"brain": "0",
"battery": "0",
@@ -20,7 +20,7 @@
"levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
- "name": "nameless",
+ "name": "well done",
"chassis": "9",
"brain": "2",
"battery": "2",
diff --git a/build/test.exe b/build/test.exe
index 44ed130..ea9a706 100644
--- a/build/test.exe
+++ b/build/test.exe
Binary files differ
diff --git a/design/notes.txt b/design/notes.txt
index 0cd57c3..2caa6f7 100644
--- a/design/notes.txt
+++ b/design/notes.txt
@@ -1,13 +1,11 @@
tasks: (date)
-[ ] implement cost function (issued on 18:02:21)
[ ] implement stats hud view (issued on 18:02:21)
[ ] implement net hud and minilobby (issued on 18:02:21)
[ ] implement brain behaviour (issued on 18:02:21)
[ ] implement army hud view (issued on 18:02:21)
[ ] implement lobby cost constraints (issued on 18:02:21)
[ ] implement edit unit directly (issued on 18:02:21)
-[ ] implement naming template and army (issued on 18:02:21)
[ ] implement persistent settings (issued on 18:02:21)
[ ] implement move animation (issued on 18:02:21)
[ ] implement fire animation (issued on 18:02:21)
@@ -18,6 +16,8 @@ tasks: (date)
[ ] design component sprites (issued on 18:02:21)
[ ] implement sound (issued on 18:02:21)
+[x] implement naming template and army (issued on 18:02:21, done on 22:02:21)
+[x] implement cost function (issued on 18:02:21, done on 20:02:21)
[x] implement end of battle condition (issued on 19:02:21, done on 19:02:21)
[x] implement battery calculation (issued on 18:02:21, done on 19:02:21)
[x] implement component levels (issued on 18:02:21, done on 19:02:21)
@@ -52,6 +52,9 @@ view from 18:02:21 to the end:
details:
+implement naming army -> done
+implement naming template -> almost
+
implement stats hud view:
? stats have to include individual weapon cooldowns and damage, what to do
either put all as lines in stats (clean, but ugly)
@@ -121,6 +124,7 @@ implement cost function:
. sum of cost of components but with the final modified values
i can also price components based on no bonuses to provide a price gauge -> meh
i think it's better to focus on the cost indipendently of weight for now
+-> done inpependent wrt weight
implement end of battle condition:
i was thinking i can detect the end as no damage is being dealt in 10 turns
diff --git a/gst/info.c b/gst/info.c
index 15c7c0b..2328df3 100644
--- a/gst/info.c
+++ b/gst/info.c
@@ -941,3 +941,14 @@ int info_army_get_list (char l[][32]) {
}
return len;
}
+
+void info_army_rename (char oldn[], char newn[]) {
+ char pathnameold[64]; sprintf(pathnameold, "army/%s.txt", oldn);
+ char pathnamenew[64]; sprintf(pathnamenew, "army/%s.txt", newn);
+ rename(pathnameold, pathnamenew);
+}
+
+void info_army_remove (char name[]) {
+ char pathname[64]; sprintf(pathname, "army/%s.txt", name);
+ remove(pathname);
+}
diff --git a/gst/info.h b/gst/info.h
index 9219f8b..2fe0973 100644
--- a/gst/info.h
+++ b/gst/info.h
@@ -128,6 +128,8 @@ void info_load_army(struct army_ *ar, char *filename);
void info_save_army(struct army_ *ar, char *filename);
int info_army_get_list(char l[][32]);
+void info_army_rename (char oldn[], char newn[]);
+void info_army_remove (char name[]);
void info_load_playername(char n[]);
void info_save_playername(char n[]);
diff --git a/hud/hud.c b/hud/hud.c
index 97fba77..b109ef5 100644
--- a/hud/hud.c
+++ b/hud/hud.c
@@ -53,18 +53,32 @@ void init_overlay_game (graphic_settings *gs, overlay_game *og, txtd *t) {
og->rect_templates = { 10, gs->resy-10-h, w, h };
float wnu = get_text_width("new template", t);
- button b = { "new template", 4, { w-wnu-4*2, 20 } };
+ button b = { "new template", 4, { w-wnu-4*2+5, 10+5 } };
og->new_template = b;
float wst = get_text_width("save templates", t);
- button b2 = { "save templates", 4, { w-wst-4*2, gs->resy-20-4*2-10 } };
+ button b2 = { "save templates", 4, { w-wst-4*2+5, gs->resy-20-4*2-5 } };
og->save_templates = b2;
int warmy = 250, harmy = gs->resy-20;
og->rect_army = { gs->resx-warmy-10, gs->resy-harmy-10, warmy, harmy };
- button b3 = { "save army", 4, { gs->resx-warmy, gs->resy-20-4*2-10 } };
+ button b3 = { "save army", 4, { gs->resx-warmy-5, gs->resy-20-4*2-5 } };
og->save_army = b3;
+ {
+ int w = get_text_width("delete army", t);
+ button b = { "delete army", 4, {
+ gs->resx-w-4*2-15, gs->resy-20-4*2-5 } };
+ og->delete_army = b;
+ }
+
+ {
+ int w = get_text_width("new army", t);
+ button b = { "new army", 4, {
+ gs->resx-warmy-5, gs->resy-15-4*4-20-5 } };
+ og->new_army = b;
+ }
+
int wbattle = 400, hbattle = 100;
og->rect_battle = { gs->resx/2-wbattle/2, 10, wbattle, hbattle };
@@ -96,13 +110,15 @@ void hud_init (graphic_settings *gs, hud *h, txtd *t) {
h->sc.ref = &h->fnu.rect_chassis;
h->og.temp_place = -1;
info_unit_init(&h->fnu.uinfo);
- strcpy(h->og.army_listcur, "army");
+ h->og.army_listcur = 0;
strcpy(h->og.playername, "");
strcpy(h->og.ip, "192.168.1.255");
h->nameedit = NULL;
h->og.battle_state = 0;
h->og.input_playername = 0;
h->og.input_ip = 0;
+ h->og.input_army = -1;
+ h->og.input_temp = -1;
hud_reset(gs, h, t);
}
@@ -201,20 +217,28 @@ void hud_process_sel (graphic_settings *gs, hud *h, MKb *mkb,
}
-void hud_edit_close(hud *h) {
- h->nameedit = NULL;
+void hud_edit_close(hud *h, infos *info) {
if (h->og.input_playername != 0) {
info_save_playername(h->og.playername);
}
h->og.input_playername = 0;
h->og.input_ip = 0;
+ if (h->og.input_army != -1) {
+ info_army_rename(h->og.army_rename, h->nameedit);
+ }
+ h->og.input_army = -1;
+ if (h->og.input_temp != -1) {
+ info_save_templates(info, "default");
+ }
+ h->og.input_temp = -1;
+ h->nameedit = NULL;
}
-void hud_open_fnu (hud *h, info_unit *u, int i) {
+void hud_open_fnu (hud *h, infos *info, info_unit *u, int i) {
h->state = 1;
h->fnu.uinfo = *u;
h->og.temp_modify = i;
- hud_edit_close(h);
+ hud_edit_close(h, info);
}
void hud_close_fnu (hud *h, infos *info) {
@@ -360,6 +384,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
gst->cam[1] = -gs->resy/2+gst->map_battle.sy*gst->map_battle.ts/2;
h->state = 3;
net_server_close(nets);
+ hud_edit_close(h, info);
}
}
}
@@ -377,6 +402,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
gst->cam[1] = -gs->resy/2+gst->map_battle.sy*gst->map_battle.ts/2;
h->state = 3;
net_client_close(netc);
+ hud_edit_close(h, info);
}
}
@@ -384,7 +410,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
if (mkb->mheld[0] == 1) {
if (mouse_in_button(mousepos, t, &h->og.new_template)) {
info_unit u; info_unit_init(&u);
- hud_open_fnu(h, &u, -1);
+ hud_open_fnu(h, info, &u, -1);
h->og.temp_place = -1;
}
@@ -394,9 +420,6 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
}
if (mouse_in_button(mousepos, t, &h->og.start_battle)) {
- /*
- army_move(info, ar, m);
- army_fire(info, ar, m);*/
gst_tobattle(gst);
gst->cam[0] = -gs->resx/2+gst->map_battle.sx*gst->map_battle.ts/2;
gst->cam[1] = -gs->resy/2+gst->map_battle.sy*gst->map_battle.ts/2;
@@ -432,10 +455,49 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
}
if (mouse_in_button(mousepos, t, &h->og.save_army)) {
- info_save_army(gst->army_bp+0, h->og.army_listcur);
+ int cur = h->og.army_listcur;
+ info_save_army(gst->army_bp+0, h->og.army_list[cur]);
h->og.army_listlen = info_army_get_list(h->og.army_list);
}
+ if (mouse_in_button(mousepos, t, &h->og.new_army)) {
+ army ar; ar.uslen = 0; ar.sx = 10; ar.sy = 10;
+ char name[32]; strcpy(name, "new army");
+ char namecmp[32]; strcpy(namecmp, name);
+ for (int i=0; i<128; i++) {
+ int flag = 0;
+ for (int j=0; j<h->og.army_listlen; j++) {
+ sprintf(namecmp, "%s %d", name, i);
+ if (strcmp(namecmp, h->og.army_list[j]) == 0) {
+ flag = 1; break;
+ }
+ }
+ if (flag == 0) break;
+ }
+ info_save_army(&ar, namecmp);
+ h->og.army_listlen = info_army_get_list(h->og.army_list);
+ for (int i=0; i<h->og.army_listlen; i++) {
+ if (strcmp(namecmp, h->og.army_list[i]) == 0) {
+ h->og.army_listcur = i; break;
+ }
+ }
+ }
+
+ if (mouse_in_button(mousepos, t, &h->og.delete_army)) {
+ if (h->og.army_listlen > 1) {
+ if (h->og.input_army != -1) {
+ h->og.input_army = -1;
+ hud_edit_close(h, info);
+ }
+ int cur = h->og.army_listcur;
+ info_army_remove(h->og.army_list[cur]);
+ h->og.army_listlen = info_army_get_list(h->og.army_list);
+ if (cur >= 0) h->og.army_listcur--;
+ cur = h->og.army_listcur;
+ info_load_army(gst->army_bp+0, h->og.army_list[cur]);
+ }
+ }
+
if (h->og.temp_place != -1) {
int x = (int)((mkb->mx+gst->cam[0])/32);
int y = (int)((mkb->my+gst->cam[1])/32);
@@ -450,7 +512,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
h->og.temp_place = -1;
}
}
-
+
for (int i=0; i<info->templateslen; i++) {
float x = h->og.rect_templates.x+5;
float y = h->og.rect_templates.y+5 + i*20 + 30;
@@ -458,7 +520,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
float possa[2] = { x, y };
float sizesa[2] = { wedit+4*2, 11+4*2 };
if (pt_rect(mousepos, possa, sizesa)) {
- hud_open_fnu(h, info->templates+i, i);
+ hud_open_fnu(h, info, info->templates+i, i);
h->og.temp_place = -1;
}
float wplace = get_text_width("place", t);
@@ -467,19 +529,41 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
if (pt_rect(mousepos, posp, sizep)) {
hud_og_place(h, i);
}
+ if (h->nameedit == NULL) {
+ float pn[2] = { x+wedit+5+wplace+4*4, y+4 };
+ char *sname = info->templates[i].name;
+ float w = get_text_width(sname, t);
+ if (w==0) w = 5;
+ float sizen[2] = { w, 10 };
+ if (pt_rect(mousepos, pn, sizen)) {
+ h->nameedit = sname;
+ h->og.input_temp = i;
+ }
+ }
}
-
+
for (int i=0; i<h->og.army_listlen; i++) {
float x = h->og.rect_army.x+5;
float y = h->og.rect_army.y+5 + i*20 + 30;
- float wload = get_text_width("load", t);
+ float wload = get_text_width("load", t)+4*2;
float posp[2] = { x, y };
- float sizep[2] = { wload+4*2, 11+4*2 };
+ float sizep[2] = { wload, 11+4*2 };
if (pt_rect(mousepos, posp, sizep)) {
- strcpy(h->og.army_listcur, h->og.army_list[i]);
- info_load_army(gst->army_bp+0, h->og.army_listcur);
+ h->og.army_listcur = i;
+ info_load_army(gst->army_bp+0, h->og.army_list[i]);
Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
}
+ else if (h->nameedit == NULL) {
+ float pn[2] = { x+wload+5, y+4 };
+ float w = get_text_width(h->og.army_list[i], t);
+ if (w==0) w = 5;
+ float sizen[2] = { w, 10 };
+ if (pt_rect(mousepos, pn, sizen)) {
+ h->nameedit = h->og.army_list[i];
+ strcpy(h->og.army_rename, h->nameedit);
+ h->og.input_army = i;
+ }
+ }
}
if (h->nameedit == NULL) {
@@ -489,11 +573,8 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
if (pt_rect(mousepos, pn, sizen)) {
h->nameedit = h->og.playername;
h->og.input_playername = 1;
- }
- } else {
- Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
- hud_edit_close(h);
- }
+ }
+ }
if (h->nameedit == NULL) {
float pn[2] = { h->og.rect_battle.x+5, h->og.rect_battle.y+25 };
@@ -503,10 +584,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
h->nameedit = h->og.ip;
h->og.input_ip = 1;
}
- } else {
- Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
- hud_edit_close(h);
- }
+ }
}
// rm unit
@@ -522,7 +600,8 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
}
}
-void hud_edit_name(hud *h, MKb *mkb, Mix_Chunk *sounds[]) {
+void hud_edit_name(hud *h, infos *info, MKb *mkb, Mix_Chunk *sounds[]) {
+ if (h->nameedit == NULL) return;
for (int i=0; i<mkb->kbnum; i++) {
if (strlen(h->nameedit) < 31) {
if (mkb->kb[i] >= SDL_SCANCODE_A
@@ -566,7 +645,7 @@ void hud_edit_name(hud *h, MKb *mkb, Mix_Chunk *sounds[]) {
if (mkb_search(mkb, SDL_SCANCODE_ESCAPE)
|| mkb_search(mkb, SDL_SCANCODE_RETURN)) {
Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
- hud_edit_close(h); return;
+ hud_edit_close(h, info); return;
}
}
@@ -574,7 +653,7 @@ void hud_process (graphic_settings *gs, hud *h, MKb *mkb,
infos *info, army *ar, map *m, txtd *t, gamestate *gst,
net_client *netc, net_server *nets, Mix_Chunk *sounds[])
{
- if (h->nameedit != NULL) { hud_edit_name(h, mkb, sounds); }
+ if (h->nameedit != NULL) { hud_edit_name(h, info, mkb, sounds); }
switch (h->state) {
case 0:
hud_process_overlay_game(gs, h, mkb, info, ar, m, t, gst,
@@ -777,9 +856,25 @@ void hud_render_overlay_game (overlay_game *og, MKb *mkb,
render_button(rend, t, &og->save_templates);
for (int i=0; i<info->templateslen; i++) {
- float x = og->rect_templates.x+5;
- float y = og->rect_templates.y+5 + i*20 + 30;
- render_view_template(rend, t, x, y, info, i, 0);
+ float px = og->rect_templates.x+5;
+ float py = og->rect_templates.y+5 + i*20 + 30;
+ { button b = { "edit", 4, { px, py } };
+ render_button(rend, t, &b); }
+ float wedit = get_text_width("edit", t);
+
+ { button b = { "place", 4, { px+wedit+2*4+5, py } };
+ render_button(rend, t, &b); }
+ float wplace = get_text_width("place", t);
+
+ float pname[2] = { wplace+wedit+4*4+10+px, py+4 };
+ char *sname = info->templates[i].name;
+ char sn[64];
+ if (og->input_temp == i) {
+ sprintf(sn, "%s_", sname);
+ } else {
+ sprintf(sn, "%s", sname);
+ }
+ render_text_scaled(rend, sn, pname, t, 1);
}
SDL_SetRenderDrawColor(rend, 0, 200, 120, 255);
@@ -794,6 +889,8 @@ void hud_render_overlay_game (overlay_game *og, MKb *mkb,
render_text_scaled(rend, sarmy, parmy, t, 2);
render_button(rend, t, &og->save_army);
+ render_button(rend, t, &og->new_army);
+ render_button(rend, t, &og->delete_army);
button b = { "load", 4, { 0, 0 } };
for (int i=0; i<og->army_listlen; i++) {
@@ -802,10 +899,17 @@ void hud_render_overlay_game (overlay_game *og, MKb *mkb,
float bw = get_text_width("load", t)+4*2;
b.pos[0] = x; b.pos[1] = y;
render_button(rend, t, &b);
+
+ char sn[64];
+ if (og->input_army == i) {
+ sprintf(sn, "%s_", og->army_list[i]);
+ } else {
+ sprintf(sn, "%s", og->army_list[i]);
+ }
float pa[2] = { x+bw+5, y+4 };
- render_text_scaled(rend, og->army_list[i], pa, t, 1);
- if (strcmp(og->army_listcur, og->army_list[i]) == 0) {
- float w = get_text_width(og->army_list[i], t);
+ render_text_scaled(rend, sn, pa, t, 1);
+ if (og->army_listcur == i) {
+ float w = get_text_width(sn, t);
float pe[2] = { x+bw+5+w+5, y+4 };
render_text_scaled(rend, "<- editing", pe, t, 1);
}
diff --git a/hud/hud.h b/hud/hud.h
index 6b3005e..a520dcb 100644
--- a/hud/hud.h
+++ b/hud/hud.h
@@ -25,6 +25,8 @@ typedef struct {
button new_template;
button save_templates;
button save_army;
+ button delete_army;
+ button new_army;
button start_battle;
button host_game;
button join_game;
@@ -35,12 +37,15 @@ typedef struct {
SDL_Rect rect_army;
char army_list[64][32];
int army_listlen;
- char army_listcur[32];
+ int army_listcur;
int battle_state;
char playername[32];
int input_playername;
char ip[32];
int input_ip;
+ int input_army;
+ int input_temp;
+ char army_rename[32];
} overlay_game;
typedef struct {
diff --git a/hud/hud_views.c b/hud/hud_views.c
index 046ba53..a58e058 100644
--- a/hud/hud_views.c
+++ b/hud/hud_views.c
@@ -373,13 +373,13 @@ void render_view_brain (SDL_Renderer* rend, txtd *t, int px, int py,
void render_view_template (SDL_Renderer* rend, txtd *t, int px, int py,
infos *info, int temp, int lvl)
{
- button b = { "edit", 4, { px, py } };
- render_button(rend, t, &b);
- float wedit = get_text_width("edit", t);
+ { button b = { "edit", 4, { px, py } };
+ render_button(rend, t, &b); }
+ float wedit = get_text_width("edit", t);
- button b1 = { "place", 4, { px+wedit+2*4+5, py } };
- render_button(rend, t, &b1);
- float wplace = get_text_width("place", t);
+ { button b = { "place", 4, { px+wedit+2*4+5, py } };
+ render_button(rend, t, &b); }
+ float wplace = get_text_width("place", t);
float pname[2] = { wplace+wedit+4*4+10+px, py+4 };
char *sname = info->templates[temp].name;
diff --git a/main.c b/main.c
index 4c5c9b4..0e4f77d 100644
--- a/main.c
+++ b/main.c
@@ -101,6 +101,7 @@ int main( int argc, char* args[] ) {
hud _hud;
hud_init(&gs, &_hud, &textd);
_hud.og.army_listlen = info_army_get_list(_hud.og.army_list);
+ info_load_army(gst.army_bp+0, _hud.og.army_list[0]);
info_load_playername(_hud.og.playername);
float mlast[2] = {0, 0};