Guest User

Untitled

a guest
May 25th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. if(b->location->commodity != NULL){
  2.  
  3.  
  4. trader *s = malloc(sizeof(trader));
  5. s->store = b->location;
  6. s->distance = i;
  7.  
  8. int index = search_items(commodity_list, b->location->commodity->name);
  9.  
  10. if(index == -1){ //this is a new commodity, not found in commodity list
  11.  
  12. item *it = malloc(sizeof(item)); //create a new commodity in list
  13. v_init(&it->sellers);
  14. v_init(&it->buyers);
  15. it->name = b->location->commodity->name;
  16.  
  17. if(b->location->type == LOCATION_SELLER){
  18. v_add(&it->sellers, s); //add buyer/seller to list of patrons in said commodity
  19. } else {
  20. v_add(&it->buyers, s);
  21. }
  22.  
  23. v_add(commodity_list,it); // add commodity to list of commodities
  24.  
  25. } else { //add seller/buyer to existing item in the commodity list
  26.  
  27. item *it = ((item *) v_get(commodity_list, index));
  28.  
  29. if(b->location->type == LOCATION_SELLER){
  30.     v_add(&it->sellers, s);
  31. } else {
  32.         v_add(&it->buyers, s);
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment