virtual void invoke(int player, EventSequenceArg* args, int numArgs) { if(!strchr(Str_Text(&commandTemplate), '%')) { DD_Execute(true/*silent*/, Str_Text(&commandTemplate)); return; } // Compose the command from the template, inserting values for named arguments. /// @todo This logic should be extracted and made into an Str method. AutoStr* cmd = AutoStr_NewStd(); // Reserve an estimate of the composed command length. Str_Reserve(cmd, Str_Length(&commandTemplate) + numArgs + 1); int len = Str_Length(&commandTemplate); const char* start = Str_Text(&commandTemplate); const char* ch = start, *substart = start; while(ch + 1 < start + len) { if(ch[0] == '%' && ch[1] && ch[1] != '%') { Str_PartAppend(cmd, substart, 0, ch - substart); if(ch[1] == 'p') { Str_AppendChar(cmd, '0' + player); } else { int arg = ch[1] - '0' - 1; DENG_ASSERT(arg >= 0 && arg < 9); Str_AppendChar(cmd, char(args[arg])); } ch += 2; substart = ch; } else { ch++; } } // Add anything remaining. Str_Append(cmd, substart); DD_Execute(true/*silent*/, Str_Text(cmd)); }
static void sendMessage(int player, int destination, const char* msg) { char buff[256]; if(NULL == msg || !msg[0]) return; if(destination == 0) { // Send the message to the other players explicitly, if(!IS_NETGAME) { // Send it locally. int i; for(i = 0; i < MAXPLAYERS; ++i) { D_NetMessageNoSound(i, msg); } } else { strcpy(buff, "chat "); M_StrCatQuoted(buff, msg, 256); DD_Execute(false, buff); } } else { // Send to all on the same team (team = color). int i; destination -= 1; for(i = 0; i < MAXPLAYERS; ++i) if(players[i].plr->inGame && cfg.playerColor[i] == destination) { if(!IS_NETGAME) { // Send it locally. D_NetMessageNoSound(i, msg); } else { sprintf(buff, "chatNum %d ", i); M_StrCatQuoted(buff, msg, 256); DD_Execute(false, buff); } } } playMessageSentSound(); }