Skip to content

Commit e7ba98f

Browse files
finduraffinduraf
finduraf
authored and
finduraf
committed
feat: Show weight in kg
1 parent 1205611 commit e7ba98f

File tree

7 files changed

+94
-17
lines changed

7 files changed

+94
-17
lines changed

FeLib/Include/festring.h

+4
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ class festring
119119
void ExtractWord(festring&);
120120
long GetCheckSum() const;
121121
void EnsureOwnsData(bool = false);
122+
inline bool IsUnique () const { return (OwnsData && Data && (REFS(Data) == 0)); }
123+
void PutWeight (int w); // Nicely formatted weight
122124
private:
123125
static void InstallIntegerMap();
124126
static void DeInstallIntegerMap();
125127
static void CheckNull(cchar*);
126128
void CreateNewData(sizetype);
127129
void CreateOwnData(cchar*, sizetype);
128130
festring& AppendInt(long);
131+
festring& AppendIntr (cchar* CStr, sizetype clen);
132+
festring& AppendStr (cchar* s);
129133
festring& Append(char);
130134
festring& Append(cchar*, sizetype);
131135
festring& Append(cfestring&);

FeLib/Source/festring.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -907,3 +907,66 @@ void festring::EnsureOwnsData(bool Unique)
907907
CreateOwnData(Data, Size);
908908
}
909909
}
910+
911+
festring& festring::AppendIntr(cchar* CStr, sizetype N)
912+
{
913+
if(N == 0)
914+
return *this;
915+
916+
sizetype OldSize = Size;
917+
sizetype NewSize = OldSize+N;
918+
char* OldPtr = Data;
919+
920+
if(OwnsData && IsUnique() && NewSize <= Reserved) {
921+
memmove(OldPtr + OldSize, CStr, N);
922+
Size = NewSize;
923+
} else {
924+
SlowAppend(CStr, N);
925+
}
926+
return *this;
927+
}
928+
929+
festring& festring::AppendStr(cchar* s)
930+
{
931+
if(s && s[0]) {
932+
return AppendIntr(s, (sizetype)strlen(s));
933+
} else {
934+
return *this;
935+
}
936+
}
937+
938+
void festring::PutWeight(int w) {
939+
if(w < 1000) {
940+
*this << w << "g";
941+
} else {
942+
int kg = w / 1000;
943+
int g = w % 1000;
944+
945+
if(g != 0) {
946+
if(g % 100 != 0) {
947+
AppendStr("~");
948+
949+
if(g % 100 > 50)
950+
g = g / 100 + 1;
951+
else
952+
g = g / 100;
953+
954+
if(g == 10) {
955+
kg += 1;
956+
g = 0;
957+
}
958+
} else {
959+
g /= 100;
960+
}
961+
}
962+
963+
*this << kg;
964+
965+
if (g != 0) {
966+
AppendStr(".");
967+
(*this) << g;
968+
}
969+
970+
AppendStr("kg");
971+
}
972+
}

Main/Source/char.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -11542,9 +11542,7 @@ truth character::EquipmentScreen(stack* MainStack, stack* SecStack)
1154211542
if(IsPlayer())
1154311543
{
1154411544
festring Total("Total weight: ");
11545-
Total << TotalEquippedWeight;
11546-
Total << "g";
11547-
11545+
Total.PutWeight(TotalEquippedWeight);
1154811546
List.AddDescription(CONST_S(""));
1154911547
List.AddDescription(Total);
1155011548
}

Main/Source/command.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ truth commandsystem::ShowInventory(character* Char)
634634
{
635635
itemvector WhichItem;
636636
festring Title("Your inventory (total weight: ");
637-
Title << Char->GetStack()->GetWeight();
638-
Title << "g)";
637+
Title.PutWeight(Char->GetStack()->GetWeight());
638+
Title << ")";
639639

640640
Char->GetStack()->DrawContents(WhichItem, Char, Title, REMEMBER_SELECTED);
641641
return false;

Main/Source/gear.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ void meleeweapon::AddInventoryEntry(ccharacter* Viewer, festring& Entry,
427427

428428
if(ShowSpecialInfo)
429429
{
430-
Entry << " [" << GetWeight() << "g";
430+
Entry << " [";
431+
Entry.PutWeight(GetWeight());
431432
if(ivanconfig::IsShowVolume())
432433
Entry << " " << GetVolume() << "cm3";
433434
Entry << ", DAM " << GetBaseMinDamage() << '-' << GetBaseMaxDamage();
@@ -646,7 +647,8 @@ void armor::AddInventoryEntry(ccharacter*, festring& Entry, int Amount, truth Sh
646647
}
647648

648649
if(ShowSpecialInfo)
649-
Entry << " [" << GetWeight() * Amount << "g";
650+
Entry << " [";
651+
Entry.PutWeight(GetWeight() * Amount);
650652
if(ivanconfig::IsShowVolume())
651653
Entry << " " << GetVolume() << "cm3";
652654
Entry << ", AV " << GetStrengthValue() << ']';
@@ -659,7 +661,8 @@ void shield::AddInventoryEntry(ccharacter* Viewer, festring& Entry,
659661

660662
if(ShowSpecialInfo)
661663
{
662-
Entry << " [" << GetWeight() << "g";
664+
Entry << " [";
665+
Entry.PutWeight(GetWeight());
663666
if(ivanconfig::IsShowVolume())
664667
Entry << " " << GetVolume() << "cm3";
665668
Entry << ", AV " << GetStrengthValue();
@@ -1408,7 +1411,8 @@ void taiaha::AddInventoryEntry(ccharacter* Viewer, festring& Entry, int, truth S
14081411

14091412
if(ShowSpecialInfo)
14101413
{
1411-
Entry << " [" << GetWeight() << "g";
1414+
Entry << " [";
1415+
Entry.PutWeight(GetWeight());
14121416
if(ivanconfig::IsShowVolume())
14131417
Entry << " " << GetVolume() << "cm3";
14141418
Entry << ", DAM " << GetBaseMinDamage() << '-' << GetBaseMaxDamage();
@@ -1913,7 +1917,8 @@ void chastitybelt::AddInventoryEntry(ccharacter*, festring& Entry, int Amount, t
19131917
}
19141918

19151919
if(ShowSpecialInfo)
1916-
Entry << " [" << GetWeight() * Amount << "g";
1920+
Entry << " [";
1921+
Entry.PutWeight(GetWeight() * Amount);
19171922
if(ivanconfig::IsShowVolume())
19181923
Entry << ", " << GetVolume() << "cm3";
19191924
Entry << ", AV " << GetStrengthValue();

Main/Source/item.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,11 @@ void item::AddInventoryEntry(ccharacter*, festring& Entry, int Amount, truth Sho
864864
}
865865

866866
if(ShowSpecialInfo){
867-
Entry << " [" << GetWeight() * Amount << "g"; //TODO if the 1st and 2nd of 3 items have 100g and the last has 2000g, the weight shown would be 300g ... now that lumps, stones and sticks are useful, this may not be that good...
868-
if(ivanconfig::IsShowVolume()){
867+
//TODO if the 1st and 2nd of 3 items have 100g and the last has 2000g, the weight shown would be 300g ... now that lumps, stones and sticks are useful, this may not be that good...
868+
Entry << " [";
869+
Entry.PutWeight(GetWeight() * Amount);
870+
871+
if(ivanconfig::IsShowVolume()) {
869872
Entry << " " << GetVolume() * Amount << "cm3"; //the item can be seen therefore it's volume guessed already
870873
if(GetSecondaryMaterial()==NULL){ //simple items like ingots sticks etc
871874
static char density[20];

Main/Source/miscitem.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,8 @@ void wand::AddInventoryEntry(ccharacter*, festring& Entry, int, truth ShowSpecia
18101810

18111811
if(ShowSpecialInfo)
18121812
{
1813-
Entry << " [" << GetWeight() << "g";
1813+
Entry << " [";
1814+
Entry.PutWeight(GetWeight());
18141815
if(ivanconfig::IsShowVolume())
18151816
Entry << " " << GetVolume() << "cm3";
18161817

@@ -2735,7 +2736,8 @@ void holybanana::AddInventoryEntry(ccharacter* Viewer, festring& Entry, int, tru
27352736

27362737
if(ShowSpecialInfo)
27372738
{
2738-
Entry << " [" << GetWeight() << "g";
2739+
Entry << " [";
2740+
Entry.PutWeight(GetWeight());
27392741
if(ivanconfig::IsShowVolume())
27402742
Entry << " " << GetVolume() << "cm3";
27412743
Entry << ", DAM " << GetBaseMinDamage() << '-' << GetBaseMaxDamage();
@@ -3436,12 +3438,13 @@ void holyhandgrenade::AddInventoryEntry(ccharacter* Viewer, festring& Entry, int
34363438

34373439
if(ShowSpecialInfo)
34383440
{
3439-
Entry << " [" << GetWeight() << "g";
3441+
Entry << " [";
3442+
Entry.PutWeight(GetWeight());
34403443

34413444
if(!!WillExplodeSoon())
34423445
Entry << ", " << "(armed)";
34433446

3444-
Entry << ']';
3447+
Entry << "]";
34453448
}
34463449
}
34473450

@@ -3829,7 +3832,8 @@ void ullrbone::AddInventoryEntry(const character* Viewer, festring& Entry, int,
38293832

38303833
if(ShowSpecialInfo)
38313834
{
3832-
Entry << " [" << GetWeight() << "g";
3835+
Entry << " [";
3836+
Entry.PutWeight(GetWeight());
38333837
if(ivanconfig::IsShowVolume())
38343838
Entry << " " << GetVolume() << "cm3";
38353839
Entry << ", DAM " << GetBaseMinDamage() << '-' << GetBaseMaxDamage();

0 commit comments

Comments
 (0)