Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(b->location->commodity != NULL){
- trader *s = malloc(sizeof(trader));
- s->store = b->location;
- s->distance = i;
- int index = search_items(commodity_list, b->location->commodity->name);
- if(index == -1){ //this is a new commodity, not found in commodity list
- item *it = malloc(sizeof(item)); //create a new commodity in list
- v_init(&it->sellers);
- v_init(&it->buyers);
- it->name = b->location->commodity->name;
- if(b->location->type == LOCATION_SELLER){
- v_add(&it->sellers, s); //add buyer/seller to list of patrons in said commodity
- } else {
- v_add(&it->buyers, s);
- }
- v_add(commodity_list,it); // add commodity to list of commodities
- } else { //add seller/buyer to existing item in the commodity list
- item *it = ((item *) v_get(commodity_list, index));
- if(b->location->type == LOCATION_SELLER){
- v_add(&it->sellers, s);
- } else {
- v_add(&it->buyers, s);
- }
- }
- }
Add Comment
Please, Sign In to add comment