void NPC::speak() { // This is a render function, so it must be within drawSprite // called from Map::render() int prevResponses = responses; if(speaking) { responses = 0; dialogBox->setX(gameConfig->getDialogBoxAnchorX()); dialogBox->setY(gameConfig->getDialogBoxAnchorY()); dialogBox->draw(graphicsNS::ALPHA75); if(messageNum == 0) sprintf_s(dialog, "O hai. I'm the owner of the dialog box. You should be able to fit 6 long lines of text in here, or you could do 4 lines of text and 2 selection options. Or, you could even do 3 lines of text and 3 selection options. Logic would tell you that you could also do 2 lines of text and 4 selection options. Understand that this dialog is long and useless for the sake of testing word-wrap functionality. Now leave me alone."); if(messageNum == 1) { sprintf_s(dialog, "Answer!"); addResponses("Yes", "No"); } if(messageNum == 2) { if(actualResponse == 0) sprintf_s(dialog, "You said yes"); else if(actualResponse == 1) sprintf_s(dialog, "You said no"); } dialogText.print(dialog, (int)dialogBox->getX() + textNS::BORDER_BUFFER, (int)dialogBox->getY() + textNS::BORDER_BUFFER, textNS::WORD_WRAP_LIMIT); if(prevResponses != responses) { // if number of responses was changed in this frame, set the selector to default to the top option selector.setX(dialogBox->getX() + textNS::BORDER_BUFFER); selector.setY(dialogBox->getY() + dialogBox->getHeight() - textNS::BORDER_BUFFER - responseText.getFontHeight()*responses); selectedResponse = 0; } if(responses) selector.draw(); } }
/*Function: createBot Expects: int, char** Returns: Bot* A Bot is a struct I created. It holds settings for the bot during execution, such as the bots nickname, real name, and messages it is expected to deliver. This function will attempt to malloc memory for a Bot, and various strings contained within. On success it will return a Bot*. On failure, it will return NULL */ Bot * createBot(int argc, char * argv[]) { int i; Bot * tempBot; //char * input; //FILE * filePtr; char ** responses; tempBot = malloc(sizeof(Bot)); if (tempBot != NULL) { tempBot->inChannel = 0; tempBot->inServer = 0; tempBot->quitMsg = strdup("QUIT :Tah Tah for now \r\n"); tempBot->passResp = strdup("PASS herpDerp\r\n"); tempBot->list = NULL; tempBot->joinMsg = malloc(sizeof(char) * (strlen("JOIN \r\n") + strlen(argv[3]))); sprintf(tempBot->joinMsg, "JOIN %s\r\n", argv[3]); tempBot->channelName = strndup(argv[3], 64); for (i = 4; i < argc; i++) { if (strncmp(argv[i], "--record", 8) == 0) tempBot->recordFlag = 1; //At this time, the record flag should always be set if (strncmp(argv[i], "--nick", 6) == 0) { if (i + 1 > argc) { fprintf(stderr, "Not enough arguments for --nick\n"); exit(1); } else { tempBot->nickResp = malloc(sizeof(char) * (strlen("NICK \r\n") + strlen(argv[i+1]))); sprintf(tempBot->nickResp, "NICK %s\r\n", argv[i+1]); } } if (strncmp(argv[i], "--name", 6) ==0) { if (i+1 > argc) { fprintf(stderr, "Not enough arguments for --name\n"); exit(1); } else { tempBot->userResp = malloc(sizeof(char) * (strlen("USER 0 0 :\r\n") + strlen(argv[i+1])*2)); sprintf(tempBot->userResp, "USER %s 0 0 :%s\r\n", argv[i+1], argv[i+1]); } } if (strncmp(argv[i], "--responses", 11) == 0) { /*if (i+1 > argc) { fprintf(stderr, "Not enough arguments for --responses\n"); exit(1); } else { responses = readResponses(); }*/ responses = readResponses(); tempBot->list = addResponses(responses); } } } return tempBot; }