From be547a2dba10292fb3191bc5fec42212d2391660 Mon Sep 17 00:00:00 2001 From: rodri Date: Wed, 30 Aug 2023 22:07:50 +0000 Subject: forbid placing ships after being done with the layout. show the current ship and its length during placement. also made changes to some of the info banners. --- util.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index 826a508..f1daf2a 100644 --- a/util.c +++ b/util.c @@ -16,6 +16,13 @@ static int shiplentab[] = { [Ssubmarine] 3, [Sdestroyer] 2, }; +static char *shipnametab[] = { + [Scarrier] "carrier", + [Sbattleship] "battleship", + [Scruiser] "cruiser", + [Ssubmarine] "submarine", + [Sdestroyer] "destroyer", +}; char * @@ -109,6 +116,15 @@ countshipcells(Map *m) int shiplen(int stype) { - assert(stype >= 0 && stype < NSHIPS); + if(stype < 0 || stype >= NSHIPS) + return -1; return shiplentab[stype]; } + +char * +shipname(int stype) +{ + if(stype < 0 || stype >= NSHIPS) + return nil; + return shipnametab[stype]; +} -- cgit v1.2.3