summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-18 10:28:18 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-18 10:28:18 +0000
commit6dc0abe0ba70d87bae5c869eebef43682566c1c3 (patch)
treeba955f16bde7b2093094bc9eb8302071a25d4c3a /crawl-ref
parentae3f16ee3946f99b45e226547277a7da12425eff (diff)
downloadcrawl-ref-6dc0abe0ba70d87bae5c869eebef43682566c1c3.tar.gz
crawl-ref-6dc0abe0ba70d87bae5c869eebef43682566c1c3.zip
More strings instead of char*s.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1599 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/ghost.cc5
-rw-r--r--crawl-ref/source/itemname.cc24
-rw-r--r--crawl-ref/source/itemname.h2
-rw-r--r--crawl-ref/source/randart.cc14
-rw-r--r--crawl-ref/source/shopping.cc56
-rw-r--r--crawl-ref/source/shopping.h6
-rw-r--r--crawl-ref/source/stash.h2
7 files changed, 40 insertions, 69 deletions
diff --git a/crawl-ref/source/ghost.cc b/crawl-ref/source/ghost.cc
index bda3da6972..69de7c6d88 100644
--- a/crawl-ref/source/ghost.cc
+++ b/crawl-ref/source/ghost.cc
@@ -110,10 +110,7 @@ void ghost_demon::reset()
void ghost_demon::init_random_demon()
{
- char st_p[ITEMNAME_SIZE];
-
- make_name(random_int(), false, st_p);
- name = st_p;
+ name = make_name(random_int(), false);
// hp - could be defined below (as could ev, AC etc). Oh well, too late:
values[ GVAL_MAX_HP ] = 100 + roll_dice( 3, 50 );
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index 69dc3ae52b..172b677bfd 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -1257,15 +1257,11 @@ std::string item_def::name_aux( description_level_type desc,
}
else
{
- buff << "labeled ";
- char buff3[ ITEMNAME_SIZE ];
-
const unsigned long sseed =
this->special
+ (static_cast<unsigned long>(it_plus) << 8)
+ (static_cast<unsigned long>(OBJ_SCROLLS) << 16);
- make_name( sseed, true, buff3 );
- buff << buff3;
+ buff << "labeled " << make_name(sseed, true);
}
break;
@@ -1602,7 +1598,7 @@ void check_item_knowledge()
// Used for: Pandemonium demonlords, shopkeepers, scrolls, random artefacts
-int make_name( unsigned long seed, bool all_cap, char buff[ ITEMNAME_SIZE ] )
+std::string make_name( unsigned long seed, bool all_cap )
{
char name[ITEMNAME_SIZE];
int numb[17];
@@ -1856,23 +1852,17 @@ int make_name( unsigned long seed, bool all_cap, char buff[ ITEMNAME_SIZE ] )
}
}
- if (len >= 3)
- strncpy( buff, name, ITEMNAME_SIZE );
- else
+ if (len < 4)
{
- strncpy( buff, "plog", ITEMNAME_SIZE );
+ strcpy(name, "plog");
len = 4;
}
- buff[ ITEMNAME_SIZE - 1 ] = '\0';
-
for (i = 0; i < len; i++)
- {
- if (all_cap || i == 0 || buff[i - 1] == ' ')
- buff[i] = toupper( buff[i] );
- }
+ if (all_cap || i == 0 || name[i - 1] == ' ')
+ name[i] = toupper( name[i] );
- return (len);
+ return name;
} // end make_name()
bool is_random_name_space(char let)
diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h
index c56a1c19b5..d04cd55246 100644
--- a/crawl-ref/source/itemname.h
+++ b/crawl-ref/source/itemname.h
@@ -37,7 +37,7 @@ bool item_type_known( const item_def &item );
bool is_interesting_item( const item_def& item );
-int make_name( unsigned long seed, bool all_caps, char buff[ ITEMNAME_SIZE ] );
+std::string make_name( unsigned long seed, bool all_caps );
/* ***********************************************************************
* called from: acr
diff --git a/crawl-ref/source/randart.cc b/crawl-ref/source/randart.cc
index c38fe22f99..47d46955a8 100644
--- a/crawl-ref/source/randart.cc
+++ b/crawl-ref/source/randart.cc
@@ -1221,9 +1221,7 @@ std::string randart_name( const item_def &item )
}
else
{
- char st_p[ITEMNAME_SIZE];
-
- make_name(random_int(), false, st_p);
+ const std::string st_p = make_name(random_int(), false);
result += item_base_name(item);
if (one_chance_in(3))
@@ -1299,9 +1297,7 @@ std::string randart_armour_name( const item_def &item )
}
else
{
- char st_p[ITEMNAME_SIZE];
-
- make_name(random_int(), false, st_p);
+ const std::string st_p = make_name(random_int(), false);
result += item_base_name(item);
if (one_chance_in(3))
{
@@ -1334,9 +1330,6 @@ std::string randart_jewellery_name( const item_def &item )
: unrand->unid_name);
}
- char st_p[ITEMNAME_SIZE];
-
- // long seed = aclass + adam * (aplus % 100) + atype * aplus2;
const long seed = calc_seed( item );
push_rng_state();
seed_rng( seed );
@@ -1385,8 +1378,7 @@ std::string randart_jewellery_name( const item_def &item )
}
else
{
- make_name(random_int(), false, st_p);
-
+ const std::string st_p = make_name(random_int(), false);
result += (jewellery_is_amulet(item) ? "amulet" : "ring");
if (one_chance_in(3))
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index 549dd35976..d98117f1b5 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -1550,9 +1550,8 @@ const shop_struct *get_shop(int sx, int sy)
return (NULL);
}
-const char *shop_name(int sx, int sy)
+std::string shop_name(int sx, int sy)
{
- static char sh_name[80];
const shop_struct *cshop = get_shop(sx, sy);
// paranoia
@@ -1567,43 +1566,40 @@ const char *shop_name(int sx, int sy)
int shop_type = cshop->type;
- char st_p[ITEMNAME_SIZE];
-
unsigned long seed = static_cast<unsigned long>( cshop->keeper_name[0] )
- | (static_cast<unsigned long>( cshop->keeper_name[1] ) << 8)
- | (static_cast<unsigned long>( cshop->keeper_name[1] ) << 16);
- make_name( seed, false, st_p );
+ | (static_cast<unsigned long>( cshop->keeper_name[1] ) << 8)
+ | (static_cast<unsigned long>( cshop->keeper_name[1] ) << 16);
- strcpy(sh_name, st_p);
- strcat(sh_name, "'s ");
+ std::string sh_name = make_name(seed, false);
+ sh_name += "'s ";
if (shop_type == SHOP_WEAPON_ANTIQUE || shop_type == SHOP_ARMOUR_ANTIQUE)
- strcat( sh_name, "Antique " );
-
- strcat(sh_name, (shop_type == SHOP_WEAPON
- || shop_type == SHOP_WEAPON_ANTIQUE) ? "Weapon" :
- (shop_type == SHOP_ARMOUR
- || shop_type == SHOP_ARMOUR_ANTIQUE) ? "Armour" :
-
- (shop_type == SHOP_JEWELLERY) ? "Jewellery" :
- (shop_type == SHOP_WAND) ? "Magical Wand" :
- (shop_type == SHOP_BOOK) ? "Book" :
- (shop_type == SHOP_FOOD) ? "Food" :
- (shop_type == SHOP_SCROLL) ? "Magic Scroll" :
- (shop_type == SHOP_GENERAL_ANTIQUE) ? "Assorted Antiques" :
- (shop_type == SHOP_DISTILLERY) ? "Distillery" :
- (shop_type == SHOP_GENERAL) ? "General Store"
- : "Bug");
-
+ sh_name += "Antique ";
+
+ sh_name +=
+ (shop_type == SHOP_WEAPON
+ || shop_type == SHOP_WEAPON_ANTIQUE) ? "Weapon" :
+ (shop_type == SHOP_ARMOUR
+ || shop_type == SHOP_ARMOUR_ANTIQUE) ? "Armour" :
+
+ (shop_type == SHOP_JEWELLERY) ? "Jewellery" :
+ (shop_type == SHOP_WAND) ? "Magical Wand" :
+ (shop_type == SHOP_BOOK) ? "Book" :
+ (shop_type == SHOP_FOOD) ? "Food" :
+ (shop_type == SHOP_SCROLL) ? "Magic Scroll" :
+ (shop_type == SHOP_GENERAL_ANTIQUE) ? "Assorted Antiques" :
+ (shop_type == SHOP_DISTILLERY) ? "Distillery" :
+ (shop_type == SHOP_GENERAL) ? "General Store"
+ : "Bug";
if (shop_type != SHOP_GENERAL
&& shop_type != SHOP_GENERAL_ANTIQUE && shop_type != SHOP_DISTILLERY)
{
int temp = sx + sy % 4;
- strcat( sh_name, (temp == 0) ? " Shoppe" :
- (temp == 1) ? " Boutique" :
- (temp == 2) ? " Emporium"
- : " Shop" );
+ sh_name += (temp == 0) ? " Shoppe" :
+ (temp == 1) ? " Boutique" :
+ (temp == 2) ? " Emporium"
+ : " Shop";
}
return (sh_name);
diff --git a/crawl-ref/source/shopping.h b/crawl-ref/source/shopping.h
index e04c841321..a6918e9c0a 100644
--- a/crawl-ref/source/shopping.h
+++ b/crawl-ref/source/shopping.h
@@ -26,11 +26,7 @@ void shop();
const shop_struct *get_shop(int sx, int sy);
-// last updated 06mar2001 {gdl}
-/* ***********************************************************************
- * called from: items direct
- * *********************************************************************** */
-const char *shop_name(int sx, int sy);
+std::string shop_name(int sx, int sy);
bool shoptype_identifies_stock(int shoptype);
diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h
index fd6ac6ddba..51ce593030 100644
--- a/crawl-ref/source/stash.h
+++ b/crawl-ref/source/stash.h
@@ -127,7 +127,7 @@ public:
void write(std::ostream &os, bool identify = false) const;
void reset() { items.clear(); visited = true; }
- void set_name(const char *s) { name = s; }
+ void set_name(const std::string& s) { name = s; }
void add_item(const item_def &item, unsigned price);