void Kingdom::ActionNewWeek(void) { ResetModes(DISABLEHIRES); // skip first day if(1 < world.CountDay()) { // castle New Week std::for_each(castles.begin(), castles.end(), std::mem_fun(&Castle::ActionNewWeek)); // heroes New Week std::for_each(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::ActionNewWeek)); // debug an gift if(IS_DEVEL() && (CONTROL_HUMAN & GetControl())) { Funds gift(20, 20, 10, 10, 10, 10, 5000); DEBUG(DBG_GAME, DBG_INFO, "debug gift: " << gift.String()); resource += gift; } } // remove week visit object visit_object.remove_if(Visit::isWeekLife); UpdateRecruits(); }
bool load_gifts(const std::string &file, gifts_t &gifts) { std::ifstream fp; std::string line; gifts.clear(); fp.open(file.c_str()); if (!fp) { std::cerr << "load error:" << file << std::endl; return false; } getline(fp, line); // skip headeer while (getline(fp, line)) { std::istringstream is(line); char sep; int id; double lat, lng, weight; is >> id >> sep; is >> lat >> sep; is >> lng >> sep; is >> weight >> sep; gift_t gift(lat, lng, weight); gift.id = id; gifts.push_back(gift); } fp.close(); return true; }
void pawsNpcDialogWindow::OnListAction( pawsListBox* widget, int status ) { if (status == LISTBOX_HIGHLIGHTED) { pawsTextBox *fld = dynamic_cast<pawsTextBox *>(widget->GetSelectedRow()->FindWidgetXMLBinding("text")); Debug2(LOG_QUESTS, 0, "Pressed: %s\n",fld->GetText() ); } else if (status == LISTBOX_SELECTED) { //if no row is selected if(!widget->GetSelectedRow()) return; pawsTextBox *fld = dynamic_cast<pawsTextBox *>(widget->GetSelectedRow()->FindWidgetXMLBinding("text")); Debug2(LOG_QUESTS, 0,"Player chose '%s'.\n", fld->GetText() ); pawsTextBox *trig = dynamic_cast<pawsTextBox *>(widget->GetSelectedRow()->FindWidgetXMLBinding("trig")); Debug2(LOG_QUESTS, 0,"Player says '%s'.\n", trig->GetText() ); csString trigger(trig->GetText()); // Send the server the original trigger csString cmd; if (trigger.GetAt(0) == '=') // prompt window signal { pawsStringPromptWindow::Create(csString(trigger.GetData()+1), csString(""), false, 320, 30, this, trigger.GetData()+1 ); } else { if (trigger.GetAt(0) != '<') { cmd.Format("/tellnpc %s", trigger.GetData() ); psengine->GetCmdHandler()->Publish(cmd); } else { psSimpleStringMessage gift(0,MSGTYPE_EXCHANGE_AUTOGIVE,trigger); gift.SendMessage(); } DisplayTextBubbles(fld->GetText()); } Hide(); } }
static int load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp) { struct nstr_item ni; struct lndstr land; int loaded = 0; char *p; char prompt[512]; char buf[1024]; if (load_unload == LOAD && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) { if (noisy) { if (lchr[lp->lnd_type].l_nland) pr("%s doesn't have room for any more land units!\n", prland(lp)); else pr("%s cannot carry land units!\n", prland(lp)); } return 0; } sprintf(prompt, "Land unit(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prland(lp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_LAND, p, NULL)) return RET_SYN; if (!still_ok_land(sectp, lp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &land)) { if (!player->owner) continue; if (load_unload == LOAD) { if (land.lnd_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prland(&land), land.lnd_ship); continue; } if (land.lnd_land > -1) { if (noisy) pr("%s is already on land #%d!\n", prland(&land), land.lnd_land); continue; } if (lnd_first_on_land(&land) >= 0) { if (noisy) pr("%s cannot be loaded since it is carrying units\n", prland(&land)); continue; } if (land.lnd_uid == lp->lnd_uid) { if (noisy) pr("%s can't be loaded onto itself!\n", prland(&land)); continue; } if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) { if (noisy) pr("%s is too heavy to load.\n", prland(&land)); continue; } } /* Unit sanity done */ /* Find the right ship */ if (load_unload == UNLOAD) { if (land.lnd_land != lp->lnd_uid) continue; if (land.lnd_ship > -1) continue; } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y) continue; /* Fit unit on ship */ if (load_unload == LOAD) { if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) { if (noisy) { if (lchr[lp->lnd_type].l_nland) pr("%s doesn't have room for any more land units!\n", prland(lp)); else pr("%s cannot carry land units!\n", prland(lp)); } break; } sprintf(buf, "loaded on your %s at %s", prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); gift(lp->lnd_own, player->cnum, &land, buf); land.lnd_land = lp->lnd_uid; land.lnd_harden = 0; putland(land.lnd_uid, &land); #if 0 /* FIXME same issue as in load_land_ship() */ if (!lnd_supply_all(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #else if (!lnd_in_supply(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #endif } else { sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); gift(sectp->sct_own, player->cnum, &land, buf); land.lnd_land = -1; putland(land.lnd_uid, &land); } pr("%s %s %s at %s.\n", prland(&land), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); loaded = 1; } *nunitsp += loaded; return 0; }
static int load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp) { struct nstr_item ni; struct lndstr land; int loaded = 0; char *p; char prompt[512]; char buf[1024]; int load_spy = 0; if (load_unload == LOAD) { if ((mchr[(int)sp->shp_type].m_flags & M_SUB) && (mchr[(int)sp->shp_type].m_nland == 0)) { if (shp_nland(sp) >= 2) { pr("Non-land unit carrying subs can only carry up to two spy units.\n"); return 0; } /* Eh, let 'em load a spy only */ load_spy = 1; } if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) { if (noisy) { if (mchr[(int)sp->shp_type].m_nland) pr("%s doesn't have room for any more land units!\n", prship(sp)); else pr("%s cannot carry land units!\n", prship(sp)); } return 0; } } sprintf(prompt, "Land unit(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prship(sp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_LAND, p, NULL)) return RET_SYN; if (!still_ok_ship(sectp, sp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &land)) { if (!player->owner) continue; if (load_unload == LOAD) { if (land.lnd_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prland(&land), land.lnd_ship); continue; } if (land.lnd_land > -1) { if (noisy) pr("%s is already on land #%d!\n", prland(&land), land.lnd_land); continue; } if (lnd_first_on_land(&land) >= 0) { if (noisy) pr("%s cannot be loaded since it is carrying units\n", prland(&land)); continue; } if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) { if (noisy) pr("%s is too heavy to load.\n", prland(&land)); continue; } if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) { if (noisy) pr("Subs can only carry spy units.\n"); continue; } } /* Unit sanity done */ /* Find the right ship */ if (load_unload == UNLOAD) { if (land.lnd_ship != sp->shp_uid) continue; if (land.lnd_land > -1) continue; } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y) continue; if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) && (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) && (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) { if (noisy) { pr("You can only load light units onto ships,\n"); pr("unless the ship is a non-sub supply ship\n"); pr("%s not loaded\n", prland(&land)); } continue; } /* Fit unit on ship */ if (load_unload == LOAD) { /* We have to check again, since it may have changed */ if ((mchr[(int)sp->shp_type].m_flags & M_SUB) && (mchr[(int)sp->shp_type].m_nland == 0)) { if (shp_nland(sp) >= 2) { pr("Non-land unit carrying subs can only carry up to two spy units.\n"); return 0; } /* Eh, let 'em load a spy only */ load_spy = 1; } if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) { if (noisy) { if (mchr[(int)sp->shp_type].m_nland) pr("%s doesn't have room for any more land units!\n", prship(sp)); else pr("%s cannot carry land units!\n", prship(sp)); } return 0; } sprintf(buf, "loaded on your %s at %s", prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); gift(sp->shp_own, player->cnum, &land, buf); land.lnd_ship = sp->shp_uid; land.lnd_harden = 0; putland(land.lnd_uid, &land); #if 0 /* * FIXME if this supplies from the sector, the putsect in * load() / lload() duplicates those supplies, causing a * seqno mismatch */ if (!lnd_supply_all(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #else if (!lnd_in_supply(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #endif } else { sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); /* Spies are unloaded quietly, others aren't */ if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) gift(sectp->sct_own, player->cnum, &land, buf); land.lnd_ship = -1; putland(land.lnd_uid, &land); } pr("%s %s %s at %s.\n", prland(&land), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); loaded = 1; } *nshipsp += loaded; return 0; }
static int load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp) { struct nstr_item ni; struct plnstr pln; int loaded = 0; char *p; char prompt[512]; char buf[1024]; struct lchrstr *lcp = lchr + lp->lnd_type; if (!lcp->l_nxlight) { if (noisy) pr("%s cannot carry extra-light planes.\n", prland(lp)); return 0; } if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) { if (noisy) pr("%s doesn't have room for any more extra-light planes\n", prland(lp)); return 0; } sprintf(prompt, "Plane(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prland(lp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_PLANE, p, NULL)) return RET_SYN; if (!still_ok_land(sectp, lp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &pln)) { if (!player->owner) continue; if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) { if (noisy) pr("You can only load xlight planes onto units.\n"); continue; } if (load_unload == LOAD && pln.pln_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prplane(&pln), pln.pln_ship); continue; } if (load_unload == LOAD && pln.pln_land > -1) { if (noisy) pr("%s is already on unit #%d!\n", prplane(&pln), pln.pln_land); continue; } if (pln.pln_harden != 0) { if (noisy) pr("%s has been hardened and can't be loaded\n", prplane(&pln)); continue; } /* Plane sanity done */ /* Find the right unit */ if (load_unload == UNLOAD) { if (pln.pln_land != lp->lnd_uid) continue; } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y) continue; /* Fit plane on unit */ if (load_unload == LOAD) { if (!put_plane_on_land(&pln, lp)) { if (noisy) pr("Can't put plane %d on this unit!\n", pln.pln_uid); continue; } sprintf(buf, "loaded on %s at %s", prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); gift(lp->lnd_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } else { pln.pln_land = -1; sprintf(buf, "unloaded at your sector at %s", xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); gift(sectp->sct_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } pr("%s %s %s at %s.\n", prplane(&pln), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); loaded = 1; } *nunitsp += loaded; return 0; }
static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp) { struct nstr_item ni; struct plnstr pln; int loaded = 0; char buf[1024]; char *p; char prompt[512]; struct mchrstr *mcp = mchr + sp->shp_type; if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) { if (noisy) pr("%s cannot carry planes\n", prship(sp)); return 0; } if (load_unload == LOAD && shp_nplane(sp, NULL, NULL, NULL) >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) { if (noisy) pr("%s doesn't have room for any more planes\n", prship(sp)); return 0; } sprintf(prompt, "Plane(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prship(sp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_PLANE, p, NULL)) return RET_SYN; if (!still_ok_ship(sectp, sp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &pln)) { if (!player->owner) continue; if (!(plchr[(int)pln.pln_type].pl_flags & P_L) && !(plchr[(int)pln.pln_type].pl_flags & P_E) && !(plchr[(int)pln.pln_type].pl_flags & P_K) && !(plchr[(int)pln.pln_type].pl_flags & P_M) ) { if (noisy) pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n"); continue; } if (load_unload == LOAD && pln.pln_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prplane(&pln), pln.pln_ship); continue; } if (load_unload == LOAD && pln.pln_land > -1) { if (noisy) pr("%s is already on land unit #%d!\n", prplane(&pln), pln.pln_land); continue; } if (pln.pln_harden != 0) { if (noisy) pr("%s has been hardened and can't be loaded\n", prplane(&pln)); continue; } if (load_unload == UNLOAD) { if (pln.pln_ship != sp->shp_uid) continue; } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y) continue; if (!could_be_on_ship(&pln, sp)) { if (noisy) { if (plchr[(int)pln.pln_type].pl_flags & P_K) p = "choppers"; else if (plchr[(int)pln.pln_type].pl_flags & P_E) p = "extra light planes"; else if (plchr[(int)pln.pln_type].pl_flags & P_M) p = "missiles"; else p = "planes"; pr("%s cannot carry %s.\n", prship(sp), p); } continue; } /* Fit plane on ship */ if (load_unload == LOAD) { if (!put_plane_on_ship(&pln, sp)) { if (noisy) pr("Can't put plane %d on this ship!\n", pln.pln_uid); continue; } sprintf(buf, "loaded on your %s at %s", prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); gift(sp->shp_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } else { pln.pln_ship = -1; sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); gift(sectp->sct_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } pr("%s %s %s at %s.\n", prplane(&pln), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); loaded = 1; } *nshipsp += loaded; return 0; }
static int tend_land(struct shpstr *tenderp, char *units) { struct nstr_item lni; struct nstr_item targets; struct shpstr target; struct lndstr land; char buf[1024]; if (!snxtitem(&lni, EF_LAND, units, NULL)) return RET_SYN; while (nxtitem(&lni, &land)) { if (!player->owner) continue; if (land.lnd_ship != tenderp->shp_uid) { pr("%s is not on %s!\n", prland(&land), prship(tenderp)); continue; } if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) { pr("%s does not have \"assault\" capability and can't be tended\n", prland(&land)); continue; } if (!snxtitem(&targets, EF_SHIP, player->argp[4], "Ship to be tended? ")) return RET_FAIL; if (!check_ship_ok(tenderp) || !check_land_ok(&land)) return RET_SYN; while (nxtitem(&targets, &target)) { if (!player->owner && relations_with(target.shp_own, player->cnum) < FRIENDLY) continue; if (target.shp_uid == tenderp->shp_uid) continue; if (tenderp->shp_x != target.shp_x || tenderp->shp_y != target.shp_y) continue; /* Fit unit on ship */ getship(target.shp_uid, &target); if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) && (!((mchr[(int)target.shp_type].m_flags & M_SUPPLY) && (!(mchr[(int)target.shp_type].m_flags & M_SUB))))) { pr("You can only load light units onto ships,\n" "unless the ship is a non-sub supply ship\n" "%s not tended\n", prland(&land)); continue; } if ((mchr[(int)target.shp_type].m_flags & M_SUB) && (lchr[(int)land.lnd_type].l_flags & L_SPY) && !mchr[(int)target.shp_type].m_nland) { if (shp_nland(&target) > 1) { pr("%s doesn't have room for more than two spy units!\n", prship(&target)); continue; } } else if (shp_nland(&target) >= mchr[target.shp_type].m_nland) { if (mchr[(int)target.shp_type].m_nland) pr("%s doesn't have room for any more land units!\n", prship(&target)); else pr("%s doesn't carry land units!\n", prship(&target)); continue; } pr("%s transferred from %s to %s\n", prland(&land), prship(tenderp), prship(&target)); sprintf(buf, "loaded on your %s at %s", prship(&target), xyas(target.shp_x, target.shp_y, target.shp_own)); gift(target.shp_own, player->cnum, &land, buf); land.lnd_ship = target.shp_uid; land.lnd_harden = 0; putland(land.lnd_uid, &land); expose_ship(tenderp, &target); putship(target.shp_uid, &target); putship(tenderp->shp_uid, tenderp); } } return 0; }
void pawsNpcDialogWindow::OnListAction(pawsListBox* widget, int status) { if(status == LISTBOX_HIGHLIGHTED) { pawsTextBox* fld = dynamic_cast<pawsTextBox*>(widget->GetSelectedRow()->FindWidgetXMLBinding("text")); Debug2(LOG_QUESTS, 0, "Pressed: %s\n",fld->GetText()); } else if(status == LISTBOX_SELECTED) { //if no row is selected if(!widget->GetSelectedRow()) return; pawsTextBox* fld = dynamic_cast<pawsTextBox*>(widget->GetSelectedRow()->FindWidgetXMLBinding("text")); Debug2(LOG_QUESTS, 0,"Player chose '%s'.\n", fld->GetText()); pawsTextBox* trig = dynamic_cast<pawsTextBox*>(widget->GetSelectedRow()->FindWidgetXMLBinding("trig")); Debug2(LOG_QUESTS, 0,"Player says '%s'.\n", trig->GetText()); csString trigger(trig->GetText()); // Send the server the original trigger csString cmd; if(trigger.GetAt(0) == '=') // prompt window signal { // cut the questID and convert it to a number as it's needed by the prompt window management size_t pos = trigger.FindFirst("{"); size_t endPos = trigger.FindFirst("}"); int questID = -1; if(pos != SIZET_NOT_FOUND) { unsigned long value = strtoul(trigger.GetData() + pos + 1, NULL, 0); questID = value; // check for overflows if(questID < -1) { questID = -1; } endPos += 1; } else { endPos = 1; } pawsStringPromptWindow::Create(csString(trigger.GetData()+endPos), csString(""), false, 320, 30, this, trigger.GetData()+endPos, questID); } else { if(trigger.GetAt(0) != '<') { cmd.Format("/tellnpc %s", trigger.GetData()); psengine->GetCmdHandler()->Publish(cmd); } else { psSimpleStringMessage gift(0,MSGTYPE_EXCHANGE_AUTOGIVE,trigger); gift.SendMessage(); } DisplayTextInChat(fld->GetText()); } Hide(); } }
bool pawsNpcDialogWindow::OnButtonPressed(int button, int keyModifier, pawsWidget* widget) { if(useBubbles) { if(widget) { csString name = widget->GetName(); // process clicking on bubbles, but allow click-through on empty space if(name.StartsWith("Bubble")) { //get the trigger which was selected. we should never get out of bounds //if the system works well csString trigger = questInfo.Get(displayIndex+widget->GetID()-100).trig; csString text = questInfo.Get(displayIndex+widget->GetID()-100).text; // we clicked on a free text question, leave only free text box if(trigger.GetAt(0) == '=') { // cut the questID and convert it to a number as it's needed by the prompt window management size_t pos = trigger.FindFirst("{"); int questID = -1; if(pos != SIZET_NOT_FOUND) { unsigned long value = strtoul(trigger.GetData() + pos + 1, NULL, 0); questID = value; // check for overflows if(questID < -1) { questID = -1; } } questIDFree = questID; ShowOnlyFreeText(); PawsManager::GetSingleton().SetCurrentFocusedWidget(textBox); gotNewMenu = true; return true; } else if(trigger.GetAt(0) != '<') { csString cmd; cmd.Format("/tellnpc %s", trigger.GetData()); psengine->GetCmdHandler()->Publish(cmd); } else { psSimpleStringMessage gift(0, MSGTYPE_EXCHANGE_AUTOGIVE, trigger); gift.SendMessage(); } DisplayTextInChat(text.GetData()); CleanBubbles(); PawsManager::GetSingleton().SetCurrentFocusedWidget(textBox); ticks = csGetTicks(); // reset time, so we can wait for the next server response gotNewMenu = false; } else if(name == "CloseBubble") { gotNewMenu = false; Hide(); } else if(name == "SpeechBubble") { clickedOnResponseBubble = true; } // process the left/right arrow clicking event else { if(name == "LeftArrow") { if(displayIndex >= 3) displayIndex -= 3; else displayIndex = 0; } else if(name == "RightArrow") { if(displayIndex < questInfo.GetSize() - 3) displayIndex += 3; else displayIndex = questInfo.GetSize() - 3; } DisplayQuestBubbles(displayIndex); pawsWidget* pw1 = FindWidget("LeftArrow"); pawsWidget* pw2 = FindWidget("RightArrow"); if(displayIndex < 3) pw1->Hide(); else pw1->Show(); if(displayIndex >= questInfo.GetSize() - 3) pw2->Hide(); else pw2->Show(); PawsManager::GetSingleton().SetCurrentFocusedWidget(textBox); } } return true; } return pawsWidget::OnButtonPressed(button, keyModifier, widget); }
bool pawsNpcDialogWindow::OnKeyDown(utf32_char keyCode, utf32_char key, int modifiers) { //manage when the window has bubbles enabled if(useBubbles) { //check if the text entry box has focus else just let the basic //pawswidget implementation handle it if(!textBox->HasFocus()) { return pawsWidget::OnKeyDown(keyCode, key, modifiers); } switch(key) { case CSKEY_ENTER: { csString text = textBox->GetText(); csString answer = ""; // for(size_t i = 0 ; i < questInfo.GetSize(); i++) { csString tmp = questInfo[i].text; tmp.DeleteAt(0,2); tmp = tmp.Trim(); if(text == tmp) { answer = questInfo[i].trig; break; } } //try checking if there is free text instead if(answer == "" && text != "") { if(questIDFree != -1) answer.Format("{%d} ", questIDFree); answer += text; questIDFree = -1; } if(answer != "") { csString cmd; if(answer.GetAt(0) == '=') // prompt window signal { // cut the questID and convert it to a number as it's needed by the prompt window management size_t pos = answer.FindFirst("{"); size_t endPos = answer.FindFirst("}"); int questID = -1; if(pos != SIZET_NOT_FOUND) { unsigned long value = strtoul(answer.GetData() + pos + 1, NULL, 0); questID = value; // check for overflows if(questID < -1) { questID = -1; } endPos += 1; } else { endPos = 1; } pawsStringPromptWindow::Create(csString(answer.GetData()+endPos), csString(""), false, 320, 30, this, answer.GetData()+endPos, questID); } else { if(answer.GetAt(0) != '<') { cmd.Format("/tellnpc %s", answer.GetData()); psengine->GetCmdHandler()->Publish(cmd); } else { psSimpleStringMessage gift(0,MSGTYPE_EXCHANGE_AUTOGIVE,answer); gift.SendMessage(); } ticks = csGetTicks(); // reset time , so we wait for the next response gotNewMenu = false; DisplayTextInChat(text.GetData()); } textBox->Clear(); } break; } } } else { return pawsWidget::OnKeyDown(keyCode, key, modifiers); } return true; }