fixed customer negotiation calculations
This commit is contained in:
49
main.c
49
main.c
@@ -25,16 +25,16 @@
|
|||||||
struct gameItem
|
struct gameItem
|
||||||
{
|
{
|
||||||
char itemName[10];
|
char itemName[10];
|
||||||
unsigned int itemCurrentItemPrice;
|
int itemCurrentItemPrice;
|
||||||
unsigned int itemStartingPrice;
|
int itemStartingPrice;
|
||||||
unsigned int itemWiggleRoom;
|
int itemWiggleRoom;
|
||||||
bool itemInInventory;
|
bool itemInInventory;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gameCustomer
|
struct gameCustomer
|
||||||
{
|
{
|
||||||
char customerName[10];
|
char customerName[10];
|
||||||
unsigned int customerWiggleRoom; //should be a randomly generated number
|
int customerWiggleRoom; //should be a randomly generated number
|
||||||
bool customerRecentlyDoneDeal;
|
bool customerRecentlyDoneDeal;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,9 +61,9 @@ struct gameItem item[10] =
|
|||||||
{"TV", 400, 400, 20, 0},
|
{"TV", 400, 400, 20, 0},
|
||||||
{"Smartphone", 0, 1200, 0, 0},
|
{"Smartphone", 0, 1200, 0, 0},
|
||||||
//special items
|
//special items
|
||||||
{"Ink", 65, 65, 150, 0},
|
{"Ink", 65, 65, 35, 0},
|
||||||
{"Weed", 12, 12, 300, 0},
|
{"Weed", 12, 12, 60, 0},
|
||||||
{"Crypto", 150, 150, 500, 0}
|
{"Crypto", 150, 100, 500, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gameCustomer customer[10] =
|
struct gameCustomer customer[10] =
|
||||||
@@ -281,12 +281,7 @@ void buyItems()
|
|||||||
|
|
||||||
bool checkForItem(int itemPicked)
|
bool checkForItem(int itemPicked)
|
||||||
{
|
{
|
||||||
if ((item[itemPicked].itemInInventory == true) && (itemPicked >= 7))
|
if (item[itemPicked].itemInInventory == true)
|
||||||
{
|
|
||||||
player.illegalItemsSold++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (item[itemPicked].itemInInventory == true)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -460,15 +455,23 @@ int gameUI(int itemPicked)
|
|||||||
|
|
||||||
bool checkCustomerWiggle(int potNewItemPrice, int customerPicked, int itemPicked)
|
bool checkCustomerWiggle(int potNewItemPrice, int customerPicked, int itemPicked)
|
||||||
{
|
{
|
||||||
if ((rand() % customer[customerPicked].customerWiggleRoom - item[itemPicked].itemWiggleRoom) > item[itemPicked].itemCurrentItemPrice - potNewItemPrice)
|
int randomness = rand() % 100 + 1;
|
||||||
{
|
float wiggleness = (float)randomness / (float)customer[customerPicked].customerWiggleRoom;
|
||||||
return false;
|
float negotionness = ((float)potNewItemPrice - (float)item[itemPicked].itemCurrentItemPrice) / (float)item[itemPicked].itemWiggleRoom;
|
||||||
}
|
if ((potNewItemPrice - item[itemPicked].itemCurrentItemPrice) <= 0)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
item[itemPicked].itemCurrentItemPrice = potNewItemPrice;
|
item[itemPicked].itemCurrentItemPrice = potNewItemPrice;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (wiggleness <= 1 && negotionness <= 1)
|
||||||
|
{
|
||||||
|
item[itemPicked].itemCurrentItemPrice = potNewItemPrice;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sellItem(int itemPicked)
|
void sellItem(int itemPicked)
|
||||||
@@ -478,6 +481,11 @@ void sellItem(int itemPicked)
|
|||||||
item[itemPicked].itemInInventory = false;
|
item[itemPicked].itemInInventory = false;
|
||||||
player.totalItemsSold++;
|
player.totalItemsSold++;
|
||||||
printf("Sold!\n\n");
|
printf("Sold!\n\n");
|
||||||
|
if (itemPicked >= 7)
|
||||||
|
{
|
||||||
|
printf("You have sold an illegal item. Keep it up and the police might start asking questions");
|
||||||
|
player.illegalItemsSold++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void negotiateItem(int itemPicked, int customerPicked)
|
void negotiateItem(int itemPicked, int customerPicked)
|
||||||
@@ -493,6 +501,11 @@ void negotiateItem(int itemPicked, int customerPicked)
|
|||||||
item[itemPicked].itemInInventory = false;
|
item[itemPicked].itemInInventory = false;
|
||||||
player.totalItemsSold++;
|
player.totalItemsSold++;
|
||||||
printf("Sold!\n\n");
|
printf("Sold!\n\n");
|
||||||
|
if (itemPicked >= 7)
|
||||||
|
{
|
||||||
|
printf("You have sold an illegal item. Keep it up and the police might start asking questions");
|
||||||
|
player.illegalItemsSold++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user