Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "room.h"
- // Note, stdio and printstring are only here for debugging purposes.
- #import <stdio.h>
- void printstring(NSString *input);
- void makeexits(NSString* list, Room* storage, BOOL hidden) {
- BOOL pipe = NO; // When we hit a pipe, this turns to yes
- NSUInteger character_counter = 0;
- NSUInteger current_index = 0; // Array index of current door we're working on
- NSMutableString* buffer = [NSMutableString string];
- if (hidden == YES) {
- [storage Add_Hidden_Exit: [[door alloc] Init]];
- while (pipe == NO) {
- unichar* bar = malloc(1);
- *bar = [list characterAtIndex: character_counter];
- switch (*bar) {
- case '|':
- pipe = YES;
- break;
- case '=':
- // Dump string into room's door
- [[[storage Hidden_Exits] objectAtIndex: current_index] setDirection: [NSString stringWithString: buffer]];
- // Reset buffer
- [buffer release]; buffer = [NSMutableString string];
- break;
- case ',':
- // Dump integer into room's door
- [[[storage Hidden_Exits] objectAtIndex: current_index] setAddress: [[NSString stringWithString: buffer] integerValue]];
- // Create new door
- [storage Add_Hidden_Exit: [[door alloc] Init]];
- // Reset buffer
- [buffer release]; buffer = [NSMutableString string];
- // Increment index to accomodate new door in array
- current_index = current_index + 1;
- break;
- default:
- [buffer appendString: [NSString stringWithCharacters: bar length: 1]];
- break;
- }
- // Last line in function. Do not write below this
- character_counter += 1;
- free(bar);
- }
- } else {
- [storage Add_Direction: [[door alloc] Init]];
- while (pipe == NO) {
- unichar* bar = malloc(1);
- *bar = [list characterAtIndex: character_counter];
- switch (*bar) {
- case '|':
- pipe = YES;
- break;
- case '=':
- // Dump string into room's door
- [[[storage Directions] objectAtIndex: current_index] setDirection: [NSString stringWithString: buffer]];
- // Reset buffer
- [buffer release]; buffer = [NSMutableString string];
- break;
- case ',':
- // Dump integer into room's door
- [[[storage Directions] objectAtIndex: current_index] setAddress: [[NSString stringWithString: buffer] integerValue]];
- // Create new door
- [storage Add_Direction: [[door alloc] Init]];
- // Reset buffer
- [buffer release]; buffer = [NSMutableString string];
- // Increment index to accomodate new door in array
- current_index = current_index + 1;
- break;
- default:
- [buffer appendString: [NSString stringWithCharacters: bar length: 1]];
- break;
- }
- // Last line in function. Do not write below this
- character_counter += 1;
- free(bar);
- }
- }
- [buffer release];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement