wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src actions.cpp dialogs.cpp dialogs.hpp...


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src actions.cpp dialogs.cpp dialogs.hpp...
Date: Sat, 19 Mar 2005 08:02:35 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      05/03/19 13:02:34

Modified files:
        src            : actions.cpp dialogs.cpp dialogs.hpp game.cpp 
                         game_events.cpp help.cpp playlevel.cpp 
                         playturn.cpp team.cpp team.hpp 

Log message:
        * Added the ability for each side to have its own objectives.
        * Applied a modified version of patch #3789 from ott which allows 
objectives to
        be set via events.
        * Fixed some compile-time warnings

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.196&tr2=1.197&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/dialogs.cpp.diff?tr1=1.90&tr2=1.91&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/dialogs.hpp.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.207&tr2=1.208&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game_events.cpp.diff?tr1=1.128&tr2=1.129&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/help.cpp.diff?tr1=1.78&tr2=1.79&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.186&tr2=1.187&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.344&tr2=1.345&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/team.cpp.diff?tr1=1.81&tr2=1.82&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/team.hpp.diff?tr1=1.53&tr2=1.54&r1=text&r2=text

Patches:
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.196 wesnoth/src/actions.cpp:1.197
--- wesnoth/src/actions.cpp:1.196       Thu Mar 10 21:42:04 2005
+++ wesnoth/src/actions.cpp     Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.196 2005/03/10 21:42:04 ydirson Exp $ */
+/* $Id: actions.cpp,v 1.197 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1677,7 +1677,7 @@
        if(map.is_village(steps.back())) {
                orig_village_owner = village_owner(steps.back(),teams);
 
-               if(orig_village_owner != team_num) {
+               if(orig_village_owner >= 0 && size_t(orig_village_owner) != 
team_num) {
                        ui->second.set_movement(0);
                        get_village(steps.back(),teams,team_num,units);
                }
Index: wesnoth/src/dialogs.cpp
diff -u wesnoth/src/dialogs.cpp:1.90 wesnoth/src/dialogs.cpp:1.91
--- wesnoth/src/dialogs.cpp:1.90        Sat Mar 19 10:26:43 2005
+++ wesnoth/src/dialogs.cpp     Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: dialogs.cpp,v 1.90 2005/03/19 10:26:43 gruikya Exp $ */
+/* $Id: dialogs.cpp,v 1.91 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -163,14 +163,11 @@
        return true;
 }
 
-void show_objectives(display& disp, const config& level_info)
+void show_objectives(display& disp, const config& level, const std::string& 
objectives)
 {
        static const std::string no_objectives(_("No objectives available"));
-       const std::string& name = level_info["name"];
-       const std::string& lang_objectives = level_info["objectives"];
+       const std::string& name = level["name"];
 
-       const std::string& objectives = lang_objectives.empty() ?
-               level_info["objectives"] : lang_objectives;
        gui::show_dialog(disp, NULL, "", font::LARGE_TEXT + name + "\n" +
                 (objectives.empty() ? no_objectives : objectives), 
gui::OK_ONLY);
 
@@ -278,7 +275,7 @@
 
 void save_preview_pane::draw_contents()
 {
-       if(index_ < 0 || index_ >= int(summaries_->size()) || info_->size() != 
summaries_->size()) {
+       if(index_ < 0 || size_t(index_) >= summaries_->size() || info_->size() 
!= summaries_->size()) {
                return;
        }
 
@@ -760,7 +757,7 @@
 
 void campaign_preview_pane::draw_contents()
 {
-       if(index_ < 0 || index_ >= descriptions_->size()) {
+       if(index_ < 0 || size_t(index_) >= descriptions_->size()) {
                return;
        }
 
Index: wesnoth/src/dialogs.hpp
diff -u wesnoth/src/dialogs.hpp:1.32 wesnoth/src/dialogs.hpp:1.33
--- wesnoth/src/dialogs.hpp:1.32        Sat Mar 19 10:26:43 2005
+++ wesnoth/src/dialogs.hpp     Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: dialogs.hpp,v 1.32 2005/03/19 10:26:43 gruikya Exp $ */
+/* $Id: dialogs.hpp,v 1.33 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -36,7 +36,7 @@
 
 bool animate_unit_advancement(const game_data& info,unit_map& units, 
gamemap::location loc, display& gui, size_t choice);
 
-void show_objectives(display& disp, const config& level_info);
+void show_objectives(display& disp, const config& level, const std::string& 
objectives);
 
 // Ask user if I should really save the game and what name I should use
 // returns 0 iff user wants to save the game
@@ -73,6 +73,8 @@
        void set_selection(int index);
 
 private:
+       display& disp_;
+
        void draw_contents();
        void process_event();
 
@@ -83,7 +85,6 @@
        int index_;
        bool left_;
        bool weapons_;
-       display& disp_;
 };
 
 void show_unit_description(display &disp, const unit& u);
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.207 wesnoth/src/game.cpp:1.208
--- wesnoth/src/game.cpp:1.207  Fri Mar 18 21:21:48 2005
+++ wesnoth/src/game.cpp        Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.207 2005/03/18 21:21:48 ydirson Exp $ */
+/* $Id: game.cpp,v 1.208 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -648,7 +648,7 @@
        std::map<int,std::string> side_types, side_controllers, side_algorithms;
        std::map<int,string_map> side_parameters;
 
-       int sides_counted = 0;
+       size_t sides_counted = 0;
 
        for(++arg_; arg_ < argc_; ++arg_) {
                const std::string val(argv_[arg_]);
@@ -667,7 +667,7 @@
                        const std::string name_head = 
name.substr(0,name.size()-1);
                        const char name_tail = name[name.size()-1];
                        const bool last_digit = isdigit(name_tail) ? true:false;
-                       const int side = name_tail - '0';
+                       const size_t side = name_tail - '0';
 
                        if(last_digit && side > sides_counted) {
                                std::cerr << "counted sides: " << side << "\n";
Index: wesnoth/src/game_events.cpp
diff -u wesnoth/src/game_events.cpp:1.128 wesnoth/src/game_events.cpp:1.129
--- wesnoth/src/game_events.cpp:1.128   Sat Mar 19 10:26:43 2005
+++ wesnoth/src/game_events.cpp Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: game_events.cpp,v 1.128 2005/03/19 10:26:43 gruikya Exp $ */
+/* $Id: game_events.cpp,v 1.129 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -28,6 +28,7 @@
 #include "util.hpp"
 #include "variable.hpp"
 #include "wassert.hpp"
+#include "gettext.hpp"
 #include "serialization/string_utils.hpp"
 
 #include <cstdlib>
@@ -458,7 +459,7 @@
        else if(cmd == "move_unit_fake") {
                const std::string& type = cfg["type"];
                const std::string& side = cfg["side"];
-               int side_num = atoi(side.c_str())-1;
+               size_t side_num = atoi(side.c_str())-1;
                if(side_num < 0 || side_num >= teams->size()) side_num = 0;
 
                const unit_race::GENDER gender = cfg["gender"] == "female" ? 
unit_race::FEMALE : unit_race::MALE;
@@ -494,6 +495,109 @@
                        }
                }
        }
+ 
+       //provide a means of specifying win/loss conditions:
+       // [event]
+       // name=prestart
+       // [objectives]
+       //   side=1
+       //   summary="Escape the forest alive"
+       //   victory_string="Victory:"
+       //   defeat_string="Defeat:"
+       //   [objective]
+       //     condition=win
+       //     description="Defeat all enemies"
+       //   [/objective]
+       //   [objective]
+       //     description="Death of Konrad"
+       //     condition=loss
+       //   [/objective]
+       // [/objectives]
+       // [/event]
+       //instead of the current (but still supported):
+       // objectives= _ "
+       // Victory:
+       // @Move Konrad to the signpost in the north-west
+       // Defeat:
+       // #Death of Konrad
+       // #Death of Delfador
+       // #Turns run out"
+       //
+       // If side is set to 0, the new objectives are added to each player.
+       //
+       // The new objectives will be automatically displayed, but only to the
+       // player whose objectives did change, and only when it's this player's
+       // turn.
+       else if(cmd == "objectives") {
+               const std::string win_str = "@";
+               const std::string lose_str = "#";
+               const std::string none_str = _("None specified");
+
+               const std::string& summary = cfg["summary"];
+               const size_t side = lexical_cast_default<size_t>(cfg["side"], 
0);
+
+               if(side != 0 && (side - 1) >= teams->size()) {
+                       ERR_NG << "Invalid side: " << cfg["side"] << " in 
objectives event\n";
+                       return rval;
+               }
+
+               std::string win_string = cfg["victory_string"];
+               if(win_string.empty()) 
+                       win_string = _("Victory:");
+               std::string lose_string = cfg["defeat_string"];
+               if(lose_string.empty())
+                       lose_string = _("Defeat:");
+
+               std::string win_objectives;
+               std::string lose_objectives;
+
+               const config::child_list& objectives = 
cfg.get_children("objective");
+               for(config::child_list::const_iterator obj_it = 
objectives.begin(); 
+                               obj_it != objectives.end(); ++obj_it) {
+
+                       const std::string& description = 
(**obj_it)["description"];
+                       const std::string& condition = (**obj_it)["condition"];
+                       LOG_NG << condition << " objective: " << description << 
"\n";
+                       if(condition == "win") {
+                               win_objectives.append("\n");
+                               win_objectives.append(win_str);
+                               win_objectives.append(description);
+                       } else if(condition == "loss") {
+                               lose_objectives.append("\n");
+                               lose_objectives.append(lose_str);
+                               lose_objectives.append(description);
+                       } else {
+                               ERR_NG << "unknown condition '" << condition << 
"', ignoring\n";
+                       }
+               }
+
+               std::stringstream objs;
+               if(!summary.empty())
+                       objs << "*" << summary << "\n";
+               objs << win_string << "\n";
+               if(win_objectives.empty()) {
+                       objs << none_str << "\n";
+               } else {
+                       objs << win_objectives << "\n";
+               }
+               objs << lose_string << "\n";
+               if(lose_objectives.empty()) {
+                       objs << none_str << "\n";
+               } else {
+                       objs << lose_objectives << "\n";
+               }
+
+               if(side == 0) {
+                       for(std::vector<team>::iterator itor = teams->begin();
+                                       itor != teams->end(); ++itor) {
+
+                               itor->set_objectives(objs.str());
+                       }
+               } else {
+                       (*teams)[side - 1].set_objectives(objs.str());
+               }
+       }
+
 
        //setting a variable
        else if(cmd == "set_variable") {
@@ -544,11 +648,11 @@
                if(random.empty() == false) {
                        std::string random_value, word;
                        std::vector<std::string> words;
-                       std::vector<std::pair<int,int> > ranges;
+                       std::vector<std::pair<size_t,size_t> > ranges;
                        int num_choices = 0;
-                       int pos = 0, pos2 = -1, tmp; 
+                       std::string::size_type pos = 0, pos2 = 
std::string::npos, tmp; 
                        std::stringstream 
ss(std::stringstream::in|std::stringstream::out);
-                       while (pos2 != (int)random.length()) {
+                       while (pos2 != random.length()) {
                                pos = pos2+1;
                                pos2 = random.find(",", pos);
 
@@ -569,9 +673,9 @@
                                        // treat as a numerical range
                                        const std::string first = 
word.substr(0, tmp);
                                        const std::string second = 
word.substr(tmp+2,
-                                                                               
                                random.length());
+                                                       random.length());
 
-                                       int low, high;
+                                       size_t low, high;
                                        ss << first + " " + second;
                                        ss >> low;
                                        ss >> high;
@@ -587,7 +691,7 @@
                                }
                        }
 
-                       int choice = get_random() % num_choices;
+                       size_t choice = get_random() % num_choices;
                        tmp = 0;        
                        for(size_t i = 0; i < ranges.size(); i++) {
                                tmp += (ranges[i].second - ranges[i].first) + 1;
Index: wesnoth/src/help.cpp
diff -u wesnoth/src/help.cpp:1.78 wesnoth/src/help.cpp:1.79
--- wesnoth/src/help.cpp:1.78   Sat Mar 19 10:26:43 2005
+++ wesnoth/src/help.cpp        Sat Mar 19 13:02:34 2005
@@ -2587,8 +2587,11 @@
        gui::draw_dialog(xloc, yloc, width, height, disp.video(), _("The Battle 
for Wesnoth Help"),
                                         NULL, &buttons_ptr, &restorer);
 
-       if (preferences::encountered_units().size() != 
last_num_encountered_units
-               || preferences::encountered_terrains().size() != 
last_num_encountered_terrains) {
+       if ( (last_num_encountered_units >= 0 && 
+                        preferences::encountered_units().size() != 
size_t(last_num_encountered_units)) ||
+                       (last_num_encountered_terrains >= 0 &&
+                        preferences::encountered_terrains().size() != 
size_t(last_num_encountered_terrains))) {
+
                // More units or terrains encountered, update the contents.
                last_num_encountered_units = 
preferences::encountered_units().size();
                last_num_encountered_terrains = 
preferences::encountered_terrains().size();
Index: wesnoth/src/playlevel.cpp
diff -u wesnoth/src/playlevel.cpp:1.186 wesnoth/src/playlevel.cpp:1.187
--- wesnoth/src/playlevel.cpp:1.186     Sat Mar 19 10:26:43 2005
+++ wesnoth/src/playlevel.cpp   Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: playlevel.cpp,v 1.186 2005/03/19 10:26:43 gruikya Exp $ */
+/* $Id: playlevel.cpp,v 1.187 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -248,6 +248,11 @@
 
                teams.push_back(team(**ui,ngold));
 
+               //if this team has no objectives, set its objectives to the
+               //level-global "objectives"
+               if(teams.back().objectives().empty())
+                       teams.back().set_objectives((*level)["objectives"]);
+
                //if this side tag describes the leader of the side
                if((**ui)["no_leader"] != "yes" && (**ui)["controller"] != 
"null") {
                        unit new_unit(gameinfo, **ui);
@@ -589,12 +594,6 @@
                                if(!replaying && team_it->is_human()) {
                                        LOG_NG << "is human...\n";
 
-                                       if(first_time && team_it == 
teams.begin()) {
-                                               if(lvl["objectives"].empty() == 
false) {
-                                                       
dialogs::show_objectives(gui,*level);
-                                               }
-                                       }
-
                                        try {
                                                
play_turn(gameinfo,state_of_game,status,game_config,
                                                          *level, key, gui, 
map, teams, player_number,
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.344 wesnoth/src/playturn.cpp:1.345
--- wesnoth/src/playturn.cpp:1.344      Sat Mar 19 10:26:43 2005
+++ wesnoth/src/playturn.cpp    Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.344 2005/03/19 10:26:43 gruikya Exp $ */
+/* $Id: playturn.cpp,v 1.345 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -190,6 +190,12 @@
        
        if(use_left_right && key_[SDLK_RIGHT] || mousex > 
gui_.x()-scroll_threshold)
                gui_.scroll(preferences::scroll_speed(),0);
+
+       if(!browse_ && current_team().objectives_changed()) {
+               dialogs::show_objectives(gui_, level_, 
current_team().objectives());
+               current_team().reset_objectives_changed();
+       }
+
 }
 
 bool turn_info::turn_over() const { return end_turn_; }
@@ -1170,7 +1176,7 @@
        static const std::string style = "menu2";
        const int res = gui::show_dialog(gui_,NULL,"","",
                        
gui::MESSAGE,&menu,NULL,"",NULL,-1,NULL,NULL,xloc,yloc,&style);
-       if(res < 0 || res >= items.size())
+       if(res < 0 || size_t(res) >= items.size())
                return;
 
        const hotkey::HOTKEY_COMMAND cmd = 
hotkey::get_hotkey(items[res]).get_id();
@@ -2064,7 +2070,7 @@
                                          
gui::OK_CANCEL,&options,&preview_panes);
        }
 
-       if(choice >= 0 && choice < unit_choices.size()) {
+       if(choice >= 0 && size_t(choice) < unit_choices.size()) {
                units_.erase(last_hex_);
                
units_.insert(std::pair<gamemap::location,unit>(last_hex_,unit_choices[choice]));
                gui_.invalidate(last_hex_);
@@ -2096,7 +2102,8 @@
 
 void turn_info::objectives()
 {
-       dialogs::show_objectives(gui_,level_);
+       dialogs::show_objectives(gui_, level_, current_team().objectives());
+       current_team().reset_objectives_changed();
 }
 
 void turn_info::unit_list()
Index: wesnoth/src/team.cpp
diff -u wesnoth/src/team.cpp:1.81 wesnoth/src/team.cpp:1.82
--- wesnoth/src/team.cpp:1.81   Sat Mar  5 10:54:25 2005
+++ wesnoth/src/team.cpp        Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: team.cpp,v 1.81 2005/03/05 10:54:25 silene Exp $ */
+/* $Id: team.cpp,v 1.82 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -86,6 +86,8 @@
        flag = cfg["flag"];
 
        description = cfg["description"];
+       objectives = cfg["objectives"];
+       objectives_changed = (cfg["objectives_changed"] == "yes");
 
        const std::string& village_income = cfg["village_gold"];
        if(village_income.empty())
@@ -209,6 +211,8 @@
        cfg["save_id"] = save_id;
        cfg["flag"] = flag;
        cfg["description"] = description;
+       cfg["objectives"] = objectives;
+       cfg["objectives_changed"] = objectives_changed ? "yes" : "no";
 
        char buf[50];
        sprintf(buf,"%d",income_per_village);
@@ -522,6 +526,27 @@
        return info_.save_id;
 }
 
+void team::set_objectives(const std::string& new_objectives)
+{
+       info_.objectives = new_objectives;
+       info_.objectives_changed = true;
+}
+
+void team::reset_objectives_changed() 
+{
+       info_.objectives_changed = false;
+}
+
+const std::string& team::objectives() const
+{
+       return info_.objectives;
+}
+
+bool team::objectives_changed() const
+{
+       return info_.objectives_changed;
+}
+
 const std::string& team::flag() const
 {
        return info_.flag;
Index: wesnoth/src/team.hpp
diff -u wesnoth/src/team.hpp:1.53 wesnoth/src/team.hpp:1.54
--- wesnoth/src/team.hpp:1.53   Thu Mar 10 01:47:57 2005
+++ wesnoth/src/team.hpp        Sat Mar 19 13:02:34 2005
@@ -1,4 +1,4 @@
-/* $Id: team.hpp,v 1.53 2005/03/10 01:47:57 ydirson Exp $ */
+/* $Id: team.hpp,v 1.54 2005/03/19 13:02:34 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -75,6 +75,13 @@
 
                std::string description;
 
+               std::string objectives; /** < Team's objectives for the current 
level. */
+
+               /** Set to true when the objectives for this time changes.
+                * Reset to false when the objectives for this team have been
+                * displayed to the user. */
+               bool objectives_changed;
+
                enum CONTROLLER { HUMAN, AI, NETWORK, EMPTY };
                CONTROLLER controller;
                bool persistent;
@@ -118,6 +125,12 @@
        const std::string& name() const;
        const std::string& save_id() const;
 
+       void set_objectives(const std::string& new_objectives);
+       void reset_objectives_changed();
+
+       const std::string& objectives() const;
+       bool objectives_changed() const;
+
        bool is_enemy(int n) const {
                const size_t index = size_t(n-1);
                if(index < enemies_.size()) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]