forum.webdiplomacy.net

webDip dev coordination forum / public access todo list
It is currently Sun Nov 19, 2017 5:31 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sat Apr 10, 2010 4:15 am 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
My current setup is net that complicated.
I changed the following functions:
Code:
class chatbox -> funtion output (remove the chatbox for the "neutral player"
class adjudicatorPreGame -> funtion isEnoughPlayers (hardcode to 2 players)
class adjudicatorPreGame -> funtion userCountries (add the neutral player last)
class panelGameBoard -> funtion needsProcess  (hardcode to 2 players)
class  panelMembers -> funtion membersList (Delete the "neutral" player from the playerlist)
class panelMembersHome  -> funtion membersList (Delete the "neutral" player from the playerlist)
class processGame -> funtion needsProcess  (hardcode to 2 players)
class processGame -> funtion process (put the orders in the wD_Orders table)

SO most action is just in processGame. The rest is just to "hide" the player.


Top
 Profile  
 
PostPosted: Sat Apr 10, 2010 4:19 am 
Offline
Site Admin

Joined: Sat Jun 28, 2008 6:24 am
Posts: 892
Neat, though I wonder about things like voting and how points are distributed etc, but glad you got it working


Top
 Profile  
 
PostPosted: Sat Apr 10, 2010 6:20 am 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
kestasjk wrote:
Neat, though I wonder about things like voting and how points are distributed etc, but glad you got it working

In processGame i set the neutral player to "defeated" after processing and back to playing before the processing starts.


Top
 Profile  
 
PostPosted: Sun Apr 11, 2010 12:20 pm 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Interesting.
Given the simplicity with with you've worked-around the problem I wonder if it's worth adding it to the propper format. After all, it would probably be easier for anyone else doing these to simply copy your method.


Top
 Profile  
 
PostPosted: Mon Apr 12, 2010 10:01 am 
Offline

Joined: Mon Apr 12, 2010 9:59 am
Posts: 3
Hi everyone!

Jumping in this topic for my first post, as I'd like to play according to the classical 6 players variant (Italy is holding), this piece of code would be of interest to me. Would there be any other solution? Would you mind putting a patch somewhere for me to see what you did?

Thanks!


Top
 Profile  
 
PostPosted: Mon Apr 12, 2010 11:29 am 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
For a basic guide how the variant system works check out the default-variants in the source-code.
It should be easy to extent the "Classic" map in the same way "Build-anywhere" and "custom start" do this.

Most time I just remove the "neutral" player from the player-list before I call the original version.
Also my variant is a 2-player variant, so you might have to change some indexes.

Here are my changes (that are important for the "neutral" player):

If you have a working 6-player variant ready feel free to post it here, so I can include it in my list and host it on my site too.

Code:
class DuoVariant_panelMembers extends panelMembers {

   // Delete the "neutral" player from the playerlist
   public function membersList()
   {
      if (isset($this->ByUserID[3])) {
         unset($this->ByStatus[$this->ByUserID[3]->status][$this->ByUserID[3]->id]);
         $ret=parent::membersList();
         $this->ByStatus[$this->ByUserID[3]->status][$this->ByUserID[3]->id]=$this->ByUserID[3];
      } else {
         $ret=parent::membersList();
      }
      return $ret;
   }
   
}

class DuoVariant_panelMembersHome extends panelMembersHome {

   // DElete the "neutral" player from the home-view
   function membersList()
   {
      $a=$this->Game->Variant->countries[2];
      unset ($this->Game->Variant->countries[2]);
   
      $ret=parent::membersList();

      $this->Game->Variant->countries[2]=$a;
      return $ret;
   }
}

class DuoVariant_Chatbox extends Chatbox {

   // Delete "neutral" players chatbox...
   public function output ($msgCountryID)
   {
      global $Game;
      $a=$Game->Variant->countries[2];
      unset ($Game->Variant->countries[2]);
      
      $ret=parent::output($msgCountryID);
      
      $Game->Variant->countries[2]=$a;
      return $ret;
   }
      
}

class DuoVariant_panelGameBoard extends panelGameBoard {

   // 2 players are enough in Pregame to start the game:
   public function needsProcess()
   {
      if ($this->phase=='Pre-game' && count($this->Members->ByID)==2 && $this->phaseMinutes>30 )
         return true;
      return parent::needsProcess();
   }
   
}

class DuoVariant_processGame extends processGame {

   // 2 players are enough in Pregame to start the game:
   public function needsProcess()
   {
      if ($this->phase=='Pre-game' && count($this->Members->ByID)==2 && $this->phaseMinutes>30 )
         return true;
      return parent::needsProcess();
   }
   
   function process()
   {
      global $DB;
      // Set neutral player to "Playing" bevore processing
      $DB->sql_put("UPDATE wD_Members SET status='Playing' WHERE gameID=".$this->id." AND countryID=3");

      parent::process();
      
      // custom movement code here:

      // Set "neutral player" as defeated, so we don't need to wait for his orders and votes
      $DB->sql_put("UPDATE wD_Members SET status='Defeated', missedPhases=0 WHERE gameID=".$this->id." AND countryID=3");
   }
}

class DuoVariant_adjudicatorPreGame extends adjudicatorPreGame {

   protected function isEnoughPlayers() {
      global $Game;
      return ( count($Game->Members->ByID) == 2 );
   }

   protected function userCountries() {
      global $Game, $DB;

      $userIDs=array();
      foreach($Game->Members->ByUserID as $userID=>$Member)
         $userIDs[] = $userID;

      shuffle($userIDs);

      $userCountries=array();
      $countryID=1;
      foreach($userIDs as $userID)
      {
         $userCountries[$userID] = $countryID;
         $countryID++;
      }
      
      $DB->sql_put("INSERT INTO wD_Members SET
         userID = 3, gameID = ".$Game->id.", orderStatus='None,Completed,Ready', bet = 0, timeLoggedIn = ".time());
      $Game->Members->load();

      $userCountries[3] = 3;

      return $userCountries;
   }
   

}


Oliver


Top
 Profile  
 
PostPosted: Mon Apr 12, 2010 3:06 pm 
Offline

Joined: Mon Apr 12, 2010 9:59 am
Posts: 3
Thanks for the info :-)

It seems that the standard 5-6 players based variants where fiddled with judging from the userids 3-4 :-)
Anyways, based on your work, with no appropriate comments and/or license, here is my (supposedly) working shot. I'll do some proper stuff later on, when I won't be at work!

(Yes, the code is pretty ugly, I fiddled around some stuff looking for other stuff, when I realized what I had to do...)

http://www.calaquendi.org/diplomacy/var ... ssic_6.tgz


Top
 Profile  
 
PostPosted: Thu Apr 15, 2010 9:46 pm 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
In "pregame" I tried:
Code:
   protected function userCountries() {

      global $Game, $DB;

      $ret=parent::userCountries();

      $DB->sql_put("INSERT INTO wD_Members SET
         userID = 3, gameID = ".$Game->id.", orderStatus='None,Completed,Ready', bet = 0, timeLoggedIn = ".time());
      $Game->Members->load();

      $ret[3] = 7;

      return $ret;
   }   

It's a bit more elegant, instead of copying the whole usercountries code.

Oliver


Top
 Profile  
 
PostPosted: Thu Apr 15, 2010 10:05 pm 
Offline

Joined: Mon Apr 12, 2010 9:59 am
Posts: 3
Sleepcap wrote:
It's a bit more elegant, instead of copying the whole usercountries code.


Agreed. As I told before, quick hack just to test it while I was at work, supposed to do other stuff ;-)
When I'll find enough time to do it, I'll try to investigate and find other funny stuff to do. If you're willing to, we could team up to build these variants you were talking about, I'm eager to find myself some funny stuff to do as it's been 6 months or so I paused my activites on other open source projects (embedded software openmoko related).


Top
 Profile  
 
PostPosted: Thu Apr 15, 2010 10:14 pm 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
Ainulindale wrote:
When I'll find enough time to do it, I'll try to investigate and find other funny stuff to do. If you're willing to, we could team up to build these variants you were talking about, I'm eager to find myself some funny stuff to do as it's been 6 months or so I paused my activites on other open source projects (embedded software openmoko related).

I'm currently stuck at implementing 2 "strange" rules in the Colonial-map and in the Imperium-map.
My PHP-knowledge is quite basic, so I have no clue at the moment how to program this (but many ideas).
If you want to help check out these 2 variants. Also I made a very experimental map with really strange options (transform army into fleets, computer players). I can send you the code if interested, but it's definitely not ready for prime-time.

You can find them on my variant-thread here:http://forum.webdiplomacy.net/viewtopic.php?f=25&t=375
It's the last 2 variants.

Or see them in action: http://oli.rhoen.de/webdiplomacy/

Oliver


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group